Skip to content

salvus.opt.models.unstructured_model

salvus.opt.models.unstructured_model salvus opt models unstructured_model

An unstructured mesh model.

Classes

UnstructuredModel

class UnstructuredModel(salvus.opt.models.base_model.BaseModel):
    def __init__(
        self,
        name: str,
        model: str | pathlib.Path | UnstructuredMesh,
        fields: list[str],
    ): ...

Unstructured mesh inversion model.

Parameters
  • name str — Name of the model.
  • model str | pathlib.Path | UnstructuredMesh — The unstructured mesh.
  • fields list[str] — Names of the elemental fields to use.
Attributes
model UnstructuredMesh

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 unstructured mesh model as a vector.

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

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 Self
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
copy()
def copy(self, name: str) -> Self: ...

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 Self — A copy of the model with the new name. Always fully in memory.
dot()
def dot(self, other: Self) -> float: ...

Dot product of the model with another model.

Parameters
  • other Self — The other model.
Returns float — The dot product as a float.
get_metric()
def get_metric(self) -> dict[str, npt.NDArray]: ...

Get the metric for the model.

Returns dict[str, npt.NDArray] — A dictionary with the per-block weights of the metric.
max()
def max(self, other: Self) -> Self: ...

In-place point-wise maximum.

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

In-place point-wise minimum.

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

Return the model norm.

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

Infinity norm of the model.

Returns float
set_vector()
def set_vector(self, vector: npt.NDArray[np.float64]) -> None: ...

Set the model from a vector.

Parameters
  • vector npt.NDArray[np.float64] — The vector to set the model from.
Returns None
to_dict()
def to_dict(self) -> dict[str, dict[str, npt.NDArray]]: ...

Convert the model to a dictionary representation.

Returns dict[str, dict[str, npt.NDArray]] — A dictionary representation of the model.
to_disk()
def to_disk(self, parent_folder: pathlib.Path | str) -> dict: ...

Serialize the model to JSON (and an associated npy file).

Parameters
  • parent_folder pathlib.Path | str — Parent folder where the JSON + h5 files should be stored.
Returns dict — A dictionary containing meta information of the serialized model.
to_json()
def to_json(
    self,
    external_file_hash: Optional[str] = None,
    timer: Optional[salvus._core.timer.timer.Timer] = None,
    log_to_logger: bool = False,
    comm: Optional[int] = None,
) -> Dict: ...

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

Parameters
  • external_file_hash Optional[str] = None — 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 Optional[salvus._core.timer.timer.Timer] = None — Execution timer.
  • log_to_logger bool = False — Log timings to the logger.
  • comm Optional[int] = None — MPI communicator, if any.
Returns Dict
validate_consistency()
def validate_consistency(
    self, other: Self, description: str = "other model"
) -> None: ...

Check that another model has the same parameters and array shapes.

Parameters
  • other Self — The model to compare to, e.g., a weight or a reference model.
  • description str = 'other model' — Name of other in error messages.
Returns None

Used in tutorials