Mondaic
This API reference is not for the latest stable Salvus version.

salvus.opt.iteration

Classes

Iteration

class Iteration(salvus.flow.utils.serialization_helpers.SerializationMixin):
    def __init__(
        self,
        id: int,
        model: salvus.opt.models.base_model.BaseModel,
        events: Sequence[str],
        misfit_configuration: str,
        parent_id: Optional[int] = None,
        control_group_events: Optional[Sequence[str]] = None,
    ): ...

Iteration class to organize all tasks and data linked to one iteration of an multi-event inversion.

Parameters
  • id int — Unique identifier of the iteration.
  • model salvus.opt.models.base_model.BaseModel — Model of the iteration.,
  • events Sequence[str] — Batch of events for this iteration.
  • misfit_configuration str — Misfit configuration.
  • parent_id Optional[int] — ID of the parent iteration that this iteration is derived from.
  • control_group_events Optional[Sequence[str]] — Optional subset of events to be used for checking the trial model. Must be a subset of the events of the iteration. If not given, all events will be used.
Attributes
objective float

Obtain the objective value of this iteration, i.e., the sum of misfit and regularization term.

Returns: The aggregated objective value.

Methods
from_disk()
def from_disk(d: Dict, path: pathlib.Path) -> Iteration: ...

Construct object from a JSON-serializable dictionary.

Parameters
  • d Dict — JSON dictionary of the iteration.
  • path pathlib.Path — Path to the folder containing auxiliary files.
Returns Iteration
from_json()
def from_json(d: Dict) -> Iteration: ...

Construct object from a JSON-serializable dictionary.

Parameters
  • d Dict — JSON dictionary of the iteration.
Returns Iteration
from_parent()
def from_parent(
    id: int,
    parent: Iteration,
    events: Optional[Sequence[str]] = None,
    control_group_events: Optional[Sequence[str]] = None,
    misfit_configuration: Optional[str] = None,
) -> Iteration: ...

Derive a new iteration from a parent iteration. The model of the new iteration will be set to the final model of the parent iteration. If events and/or misfit_configuration are not specified, they will be inherited from the parent iteration.

Parameters
  • id int — Unique identifier of the new iteration.
  • parent Iteration — Parent iteration to inherit from.
  • events Optional[Sequence[str]] — List of iteration-specific events.
  • control_group_events Optional[Sequence[str]] — Iteration-specific control group.
  • misfit_configuration Optional[str] — Iteration-specfic misfit configuration.
Returns Iteration
add_trial_model()
def add_trial_model(
    self,
    model: salvus.opt.models.base_model.BaseModel,
    d: Dict = {},
    status: Optional[str] = "unknown",
) -> None: ...

Add a trial model to the iteration. This could be a proposed model update or any kind of auxiliary model that needs to be stored.

Parameters
  • model salvus.opt.models.base_model.BaseModel — Trial model to be stored.
  • d Dict — Auxiliary information for the trial model.
  • status Optional[str] — Status of the model.
Returns None
get_final_model()
def get_final_model(self) -> str: ...

Obtain the name of the final model of this iteration.

Returns str — Name of the final model.
get_gradient()
def get_gradient(
    self, event: str, name: Optional[str] = None
) -> salvus.opt.models.base_model.BaseModel: ...

Obtain the mapped gradient of an event.

Parameters
  • event str — Event name.
  • name Optional[str] — Optional name of the returned gradient.
Returns salvus.opt.models.base_model.BaseModel
get_model_directory()
def get_model_directory(self) -> pathlib.Path: ...

Obtain the path where all models and gradients of this iteration are stored.

Returns pathlib.Path
get_new_trial_model_id()
def get_new_trial_model_id(self) -> int: ...

Obtain the next available ID for a trial model.

Returns int — Trial model ID.
get_trial_models()
def get_trial_models(self, status: str = "all") -> List[Dict]: ...

Obtain trial models associated with this iteration.

Parameters
  • status str — Return only models with a specific status, or all models if status="all".
Returns List[Dict]
issue_task()
def issue_task(
    self, tasks: Union[salvus.opt.tasks.Task, Sequence[salvus.opt.tasks.Task]]
) -> None: ...

Issue a new set of tasks for this iteration.

Parameters
  • tasks Union[salvus.opt.tasks.Task, Sequence[salvus.opt.tasks.Task]] — Task or list of tasks that need to be done next.
Returns None
process_current_tasks()
def process_current_tasks(self) -> None: ...

Process the outputs of all current tasks. The function assumes that all current tasks have been completed and the outputs of the tasks have been updated. This function will link the task outputs to the other data stored in the iteration object.

Returns None
set_entry_point()
def set_entry_point(self, next_task: str) -> None: ...

Modify the next entry point where this iteration will continue after all tasks have been completed.

Parameters
  • next_task str — Identifier of the next task.
Returns None
set_model_directory()
def set_model_directory(self, path: pathlib.Path) -> None: ...

Set the path to the model inventory where all models and gradients of this iteration are stored

Parameters
  • path pathlib.Path — Path to model inventory.
Returns None
to_disk()
def to_disk(
    self, path: pathlib.Path, external_file_hash: Optional[str] = None
) -> Dict: ...

Serialize the object to dictionary that can be written to JSON. Auxiliary files will be written to the specified path.

Parameters
  • path pathlib.Path — Path to store auxiliary files.
  • external_file_hash Optional[str] — 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.
Returns Dict
to_json()
def to_json(self, external_file_hash: Optional[str] = None) -> Dict: ...

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

Parameters
  • external_file_hash Optional[str] — 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.
Returns Dict