Mondaic

salvus.project.components.entity_component

salvus.project.components.entity_component salvus project components entity_component

The entity component.

Functions

type_to_entity_string()

def type_to_entity_string(_type: type | ABCMeta) -> str: ...

Convert a type to the corresponding entity_type string as used in Salvus’ entity component.

Parameters
  • _type type | ABCMeta — The type to find corresponding entity string for. Allowed to be subtype of defined entity types.
Returns str — Entity type as string.

Classes

EntityComponent

class EntityComponent(builtins.object):
    def __init__(
        self, project: salvus.project.project.Project, path: pathlib.Path
    ): ...

Project subclass handling all things related to various configuration components which we’ll call entities.

Parameters
  • project salvus.project.project.Project — The project.
  • path pathlib.Path — The path where the entities are stored within the project.
Methods
add()
def add(
    self,
    entity: typing.Any,
    overwrite: bool = False,
    skip_validation: bool = True,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    comm: int | None = None,
) -> None: ...

Add an entity to the project.

Parameters
  • entity typing.Any — The entity to add.
  • overwrite bool — Potentially overwrite an existing thing in project if it already exists.
  • skip_validation bool — If set to true, any validation steps are skipped. This currently only affects mesh QC.
  • timer Timer | None — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm int | None — MPI communicator, if any.
Returns None
delete()
def delete(self, entity_type: str, entity_name: str) -> None: ...

Remove an entity from the project.

Parameters
  • entity_type str — The type of entity to delete.
  • entity_name str — The name of the entity.
Returns None
get()
def get(
    self,
    entity_type: str,
    entity_name: str,
    comm: int | None = None,
    max_wait_time_if_mpi_in_seconds: float = 5.0,
) -> typing.Any: ...

Get an entity.

The returned object must be treated as read-only. For some entity types - see _cacheable_entity_types - repeated calls return the very same instance rather than a fresh one, so modifying it would change what every other holder of that entity sees. Deep copy it first if it has to be changed:

sc = p.entities.get("simulation_configuration", "my_sim")
my_own_copy = copy.deepcopy(sc)

A fresh object is always returned once the file backing the entity changes, whether through this component or from another process.

Parameters
  • entity_type str — The type of entity to get.
  • entity_name str — The name of the entity.
  • comm int | None — MPI communicator for distributed meshes and models, if any.
  • max_wait_time_if_mpi_in_seconds float — If the file for an entity is not found and a communicator is passed, wait for up to this long for the filesystem to catch up.
Returns typing.Any
get_all()
def get_all(self, entity_type: str) -> dict[str, typing.Any]: ...

Get all entities of a given type.

Parameters
  • entity_type str — The type of entities to get.
Returns dict[str, typing.Any]
get_inverse_problem_configurations()
def get_inverse_problem_configurations(
    self, inversions: typing.Sequence[str] | None = None
) -> dict[str, InverseProblemConfiguration]: ...

Get the inverse problem configuration objects for the passed inversions.

Parameters
  • inversions typing.Sequence[str] | None — Inversions to return the objects for. Omitting this parameter returns all inversion problem configurations related to the project.
Returns dict[str, InverseProblemConfiguration] — A dictionary of inverse problem configurations.
has()
def has(self, entity_type: str, entity_name: str) -> bool: ...

A check if an entity of a given type or name exists.

Parameters
  • entity_type str — The type of entity to get.
  • entity_name str — The name of the entity.
Returns bool
list()
def list(self, entity_type: str) -> list[str]: ...

List all available entities of the chosen type.

Parameters
  • entity_type str — The type of the entities to list.
Returns list[str]

Used in tutorials