Mondaic

salvus.opt.models.distributed_block_model

salvus.opt.models.distributed_block_model salvus opt models distributed_block_model

Distributed block model for MPI inversion workflows.

Functions

get_in_memory_cache()

def get_in_memory_cache() -> dict[str, DistributedBlockModel]: ...

Get the in-memory cache of distributed block models.

Returns dict[str, DistributedBlockModel] — The in-memory cache.

Classes

DistributedBlockModel

class DistributedBlockModel(
    salvus.flow.utils.serialization_helpers.SerializationMixin
):
    def __init__(
        self,
        comm: int,
        local_model: BlockModel,
        global_element_map: list[npt.NDArray] | None = None,
    ) -> None: ...

A block model distributed across MPI ranks.

Parameters
  • comm int — The MPI communicator.
  • local_model BlockModel — The local block model on each rank.
  • global_element_map list[npt.NDArray] | None — A list of numpy arrays that map the local elements to the global elements.
Attributes
fields list[str]

The fields the model is defined on.

model list

Shortcut to the local model.

This is the part of the model that the current rank owns.

name str

The name of the model.

status str

The status of the model to keep track of whether the model has been modified.

Methods
from_disk()
def from_disk(
    parent_folder: pathlib.Path, d: dict
) -> DistributedBlockModel: ...

The from_disk() method.

Only gets the model from the in-memory cache.

Parameters
  • parent_folder pathlib.Path — The folder where the model files are stored. Not used here but required by the interface.
  • d dict — The dictionary returned by to_disk().
Returns DistributedBlockModel
from_json()
def from_json(d: builtins.dict) -> Any: ...

Recreate the object from a dictionary serialization of its initialization parameters.

Parameters
  • d builtins.dict — Dictionary containing its init parameters and a few other things.
Returns Any
preprocess_from_json()
def preprocess_from_json(d: dict) -> dict: ...

Helper function to preprocess the dictionary before deserialization.

This is needed to get the model from and to the in-memory cache.

Parameters
  • d dict — The dictionary to preprocess.
Returns dict
update_notification_count()
def update_notification_count() -> None: ...

Update the notification count in the decorator info.

Returns None
compute_inf_norm()
def compute_inf_norm(self) -> float: ...

Infinity norm of the model.

Returns float
compute_norm()
def compute_norm(self) -> float: ...

Norm of the model.

Returns float
copy()
def copy(self, name: str) -> DistributedBlockModel: ...

Return a copy of the model but with a new name.

Parameters
  • name str — The name of the new model.
Returns DistributedBlockModel
dot()
def dot(self, other: DistributedBlockModel) -> float: ...

Dot product of the model with another model.

Parameters
  • other DistributedBlockModel — The other model.
Returns float — The dot product as a float.
expand_scalar_fields()
def expand_scalar_fields(self) -> None: ...

Expand scalar fields.

Returns None
max()
def max(self, other: DistributedBlockModel) -> DistributedBlockModel: ...

In-place point-wise maximum.

Parameters
  • other DistributedBlockModel — Model to compare with.
Returns DistributedBlockModel — A reference to the modified input model, i.e., self.
min()
def min(self, other: DistributedBlockModel) -> DistributedBlockModel: ...

In-place point-wise minimum.

Parameters
  • other DistributedBlockModel — Model to compare with.
Returns DistributedBlockModel — A reference to the modified input model, i.e., self.
to_disk()
def to_disk(self, parent_folder: pathlib.Path | str) -> dict: ...

The to_disk() method.

This just caches it in memory.

Parameters
  • parent_folder pathlib.Path | str — The folder to write the model files to. Only used as the cache key here.
Returns dict
to_json()
def to_json(
    self,
    external_file_hash: types = None,
    timer: types = None,
    log_to_logger: bool = False,
    comm: types = None,
) -> builtins.dict: ...

Serialize the object to a dictionary that can be written to JSON.

Parameters
  • external_file_hash types — Hash of any external files associated with this object. Can be passed here in which case it will be stored in a centralized location in the JSON file.
  • timer types — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm types — MPI communicator, if any.
Returns builtins.dict