salvus.opt.iteration
Classes
Iteration
Iterationclass 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.
idint — Unique identifier of the iteration.modelsalvus.opt.models.base_model.BaseModel — Model of the iteration.,eventsSequence[str] — Batch of events for this iteration.misfit_configurationstr — Misfit configuration.parent_idOptional[int] — ID of the parent iteration that this iteration is derived from.control_group_eventsOptional[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.
objective float
objective floatObtain the objective value of this iteration, i.e., the sum of misfit and regularization term.
Returns: The aggregated objective value.
from_disk()
from_disk()def from_disk(d: Dict, path: pathlib.Path) -> Iteration: ...Construct object from a JSON-serializable dictionary.
dDict — JSON dictionary of the iteration.pathpathlib.Path — Path to the folder containing auxiliary files.
from_json()
from_json()def from_json(d: Dict) -> Iteration: ...Construct object from a JSON-serializable dictionary.
dDict — JSON dictionary of the iteration.
from_parent()
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.
idint — Unique identifier of the new iteration.parentIteration — Parent iteration to inherit from.eventsOptional[Sequence[str]] — List of iteration-specific events.control_group_eventsOptional[Sequence[str]] — Iteration-specific control group.misfit_configurationOptional[str] — Iteration-specfic misfit configuration.
add_trial_model()
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.
modelsalvus.opt.models.base_model.BaseModel — Trial model to be stored.dDict — Auxiliary information for the trial model.statusOptional[str] — Status of the model.
get_final_model()
get_final_model()def get_final_model(self) -> str: ...Obtain the name of the final model of this iteration.
get_gradient()
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.
eventstr — Event name.nameOptional[str] — Optional name of the returned gradient.
get_model_directory()
get_model_directory()def get_model_directory(self) -> pathlib.Path: ...Obtain the path where all models and gradients of this iteration are stored.
get_new_trial_model_id()
get_new_trial_model_id()def get_new_trial_model_id(self) -> int: ...Obtain the next available ID for a trial model.
get_trial_models()
get_trial_models()def get_trial_models(self, status: str = "all") -> List[Dict]: ...Obtain trial models associated with this iteration.
statusstr — Return only models with a specific status, or all models ifstatus="all".
issue_task()
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.
tasksUnion[salvus.opt.tasks.Task, Sequence[salvus.opt.tasks.Task]] — Task or list of tasks that need to be done next.
process_current_tasks()
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.
set_entry_point()
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.
next_taskstr — Identifier of the next task.
set_model_directory()
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
pathpathlib.Path — Path to model inventory.
to_disk()
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.
pathpathlib.Path — Path to store auxiliary files.external_file_hashOptional[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.
to_json()
to_json()def to_json(self, external_file_hash: Optional[str] = None) -> Dict: ...Serialize the object to dictionary that can be written to JSON.
external_file_hashOptional[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.