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()
get_in_memory_cache()def get_in_memory_cache() -> dict[str, DistributedBlockModel]: ...Get the in-memory cache of distributed block models.
Classes
DistributedBlockModel
DistributedBlockModelclass 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.
commint — The MPI communicator.local_modelBlockModel — The local block model on each rank.global_element_maplist[npt.NDArray] | None — A list of numpy arrays that map the local elements to the global elements.
fields list[str]
fields list[str]The fields the model is defined on.
model list
model listShortcut to the local model.
This is the part of the model that the current rank owns.
name str
name strThe name of the model.
status str
status strThe status of the model to keep track of whether the model has been modified.
from_disk()
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.
parent_folderpathlib.Path — The folder where the model files are stored. Not used here but required by the interface.ddict — The dictionary returned by to_disk().
from_json()
from_json()def from_json(d: builtins.dict) -> Any: ...Recreate the object from a dictionary serialization of its initialization parameters.
dbuiltins.dict — Dictionary containing its init parameters and a few other things.
preprocess_from_json()
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.
ddict — The dictionary to preprocess.
update_notification_count()
update_notification_count()def update_notification_count() -> None: ...Update the notification count in the decorator info.
compute_inf_norm()
compute_inf_norm()def compute_inf_norm(self) -> float: ...Infinity norm of the model.
compute_norm()
compute_norm()def compute_norm(self) -> float: ...Norm of the model.
copy()
copy()def copy(self, name: str) -> DistributedBlockModel: ...Return a copy of the model but with a new name.
namestr — The name of the new model.
dot()
dot()def dot(self, other: DistributedBlockModel) -> float: ...Dot product of the model with another model.
otherDistributedBlockModel — The other model.
expand_scalar_fields()
expand_scalar_fields()def expand_scalar_fields(self) -> None: ...Expand scalar fields.
max()
max()def max(self, other: DistributedBlockModel) -> DistributedBlockModel: ...In-place point-wise maximum.
otherDistributedBlockModel — Model to compare with.
self.min()
min()def min(self, other: DistributedBlockModel) -> DistributedBlockModel: ...In-place point-wise minimum.
otherDistributedBlockModel — Model to compare with.
self.to_disk()
to_disk()def to_disk(self, parent_folder: pathlib.Path | str) -> dict: ...The to_disk() method.
This just caches it in memory.
parent_folderpathlib.Path | str — The folder to write the model files to. Only used as the cache key here.
to_json()
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.
external_file_hashtypes — 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.timertypes — Execution timer.log_to_loggerbool — Log timings to the logger.commtypes — MPI communicator, if any.