Mondaic

salvus.opt.models.block_model

salvus.opt.models.block_model salvus opt models block_model

A model using Salvus’ native mesh format.

Classes

BlockModel

class BlockModel(salvus.opt.models.base_model.BaseModel):
    def __init__(
        self,
        name: str,
        model: str | pathlib.Path | Mesh | list[DataBlock],
        fields: list[str],
        compute_auxiliary_data: bool = True,
    ): ...

Salvus mesh inversion model.

Parameters
  • name str — Name of the model.
  • model str | pathlib.Path | Mesh | list[DataBlock] — The model either as a list of DataBlock objects, a Mesh object, or a path to a serialized BlockModel object.
  • fields list[str] — Names of the elemental fields to use.
  • compute_auxiliary_data bool — Whether to compute auxiliary data for the blocks.
Attributes
model list[DataBlock]

The actual dataset representing the model.

name str

Model name.

status ModelStatus

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

vector npt.NDArray[np.float64]

The block model as a vector.

The vector is ordered by block, then by field within each block. Does not include fields that are not part of a given block’s material.

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

Load a model from disk. This will use the dictionary and path provided.

Parameters
  • parent_folder pathlib.Path — Path to store the model.
  • d dict — Dictionary containing meta information of the model.
Returns BlockModel
from_json()
def from_json(d: dict) -> Self: ...

Create a model from a dictionary.

Parameters
  • d dict — Dictionary containing meta information of the model.
Returns Self
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: ...

Compute the infinity norm of the model.

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

Return the model norm.

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

Copy the model.

Will load the model from disk if necessary, and leave it in memory.

Parameters
  • name str — Name of the new model.
Returns BlockModel — A copy of the model with the new name. Always fully in memory.
dot()
def dot(self, other: BlockModel) -> float: ...

Compute the dot product between this model and another model.

Parameters
  • other BlockModel — The other model to compute the dot product with.
Returns float — The scalar dot product as a float.
expand_scalar_fields()
def expand_scalar_fields(self) -> None: ...

Expand any scalar fields in the model to full arrays.

This modifies the model in place.

Returns None
get_block()
def get_block(self, block_id: int) -> DataBlock | None: ...

Get a block by its ID.

Parameters
  • block_id int — The ID of the block to retrieve.
Returns DataBlock | None — The DataBlock with the specified ID, or None if not found.
get_data_from_block()
def get_data_from_block(
    self, block: MeshBlock, global_material_fields: set[str]
) -> dict[str, npt.NDArray | types.scalar_]: ...

Extract the data from a single mesh block.

If the block has a material defined, the extracted data will only contain the fields that are required for this material. Any missing data will be a scalar zero.

Parameters
  • block MeshBlock — The mesh block to extract the data from.
  • global_material_fields set[str] — Set of all material fields defined in the mesh.
Returns dict[str, npt.NDArray | types.scalar_] — Dictionary mapping field names to their data arrays.
max()
def max(self, other: BlockModel) -> BlockModel: ...

In-place point-wise maximum.

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

In-place point-wise minimum.

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

Serialize the model to JSON (and an associated pair of an npy file and a toml file containt some basic information on the blocks).

Parameters
  • parent_folder pathlib.Path | str — Parent folder where the JSON + npy files should be stored.
Returns dict — A dictionary containing meta information of the serialized model.
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