Version:

salvus.opt.iteration

salvus.opt.iteration salvus opt iteration
The iteration class and related functionality.

Functions

require_gradient()

Type guard to ensure that the iteration has a gradient.
SIGNATURE
def require_gradient(
    iteration: Iteration[ModelType],
) -> HasGradient[ModelType]: ...
ARGUMENTS
Required
iteration
Type:Iteration[ModelType]
Description:
The iteration to check.
RETURNS
Return type: HasGradient[ModelType]
The iteration with a guaranteed gradient.

require_parent_id()

Type guard to ensure that the iteration has a parent ID.
SIGNATURE
def require_parent_id(it: Iteration[ModelType]) -> HasParentID: ...
ARGUMENTS
Required
it
Type:Iteration[ModelType]
Description:
The iteration to check.
RETURNS
Return type: HasParentID
The iteration with a guaranteed parent ID.

Classes

HasGradient

Base class for protocol classes.
Protocol classes are defined as::
class Proto(Protocol):
    def meth(self) -> int:
        ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example::
class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::
class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
SIGNATURE
class HasGradient(typing.Protocol):
    def __init__(self):
        ...

HasParentID

Base class for protocol classes.
Protocol classes are defined as::
class Proto(Protocol):
    def meth(self) -> int:
        ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example::
class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::
class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
SIGNATURE
class HasParentID(typing.Protocol):
    def __init__(self):
        ...

Iteration

Iteration class to organize all tasks and data linked to one iteration of an multi-event inversion.
SIGNATURE
class Iteration(
    salvus.flow.utils.serialization_helpers.SerializationMixin, typing.Generic
):
    def __init__(
        self,
        id: int,
        model: ModelType,
        events: list[str],
        misfit_configuration: str,
        parent_id: int | None = None,
        control_group_events: list[str] | None = None,
    ): ...
ARGUMENTS
Required
id
Type:int
Description:
Unique identifier of the iteration.
Required
model
Type:ModelType
Description:
Model of the iteration.,
Required
events
Type:list[str]
Description:
Batch of events for this iteration.
Required
misfit_configuration
Type:str
Description:
Misfit configuration.
Optional
parent_id
Type:int | None
Default value:None
Description:
ID of the parent iteration that this iteration is derived from.
Optional
control_group_events
Type:list[str] | None
Default value:None
Description:
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.

Properties

  • objective(float)-Obtain the objective value of this iteration, i.e., the sum of misfit and regularization term. Returns: The aggregated objective value.

Class Methods

Iteration.from_disk()
Construct object from a JSON-serializable dictionary.
SIGNATURE
def from_disk(d: dict, path: pathlib.Path) -> Iteration[ModelType]: ...
ARGUMENTS
Required
d
Type:dict
Description:
JSON dictionary of the iteration.
Required
path
Type:pathlib.Path
Description:
Path to the folder containing auxiliary files.
Iteration.from_json()
Construct object from a JSON-serializable dictionary.
SIGNATURE
def from_json(d: dict) -> Iteration[ModelType]: ...
ARGUMENTS
Required
d
Type:dict
Description:
JSON dictionary of the iteration.
Iteration.from_parent()
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.
SIGNATURE
def from_parent(
    id: int,
    parent: Iteration[ModelType],
    events: list[str] | None = None,
    control_group_events: list[str] | None = None,
    misfit_configuration: str | None = None,
) -> Iteration[ModelType]: ...
ARGUMENTS
Required
id
Type:int
Description:
Unique identifier of the new iteration.
Required
parent
Type:Iteration[ModelType]
Description:
Parent iteration to inherit from.
Optional
events
Type:list[str] | None
Default value:None
Description:
List of iteration-specific events.
Optional
control_group_events
Type:list[str] | None
Default value:None
Description:
Iteration-specific control group.
Optional
misfit_configuration
Type:str | None
Default value:None
Description:
Iteration-specfic misfit configuration.

Methods

Iteration.add_trial_model()
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.
SIGNATURE
def add_trial_model(
    self,
    model: ModelType,
    d: dict | None = None,
    status: ModelStatus = "unknown",
) -> None: ...
ARGUMENTS
Required
model
Type:ModelType
Description:
Trial model to be stored.
Optional
d
Type:dict | None
Default value:None
Description:
Auxiliary information for the trial model.
Optional
status
Type:ModelStatus
Default value:'unknown'
Description:
Status of the model.
Iteration.get_final_model()
Obtain the name of the final model of this iteration.
SIGNATURE
def get_final_model(self) -> str: ...
Iteration.get_gradient()
Obtain the mapped gradient of an event.
SIGNATURE
def get_gradient(self, event: str, name: str | None = None) -> ModelType: ...
ARGUMENTS
Required
event
Type:str
Description:
Event name.
Optional
name
Type:str | None
Default value:None
Description:
Optional name of the returned gradient.
Iteration.get_model_directory()
Obtain the path where all models and gradients of this iteration are stored.
SIGNATURE
def get_model_directory(self) -> pathlib.Path: ...
Iteration.get_new_trial_model_id()
Obtain the next available ID for a trial model.
SIGNATURE
def get_new_trial_model_id(self) -> int: ...
Iteration.get_trial_models()
Obtain trial models associated with this iteration.
SIGNATURE
def get_trial_models(self, status: str = "all") -> list[TrialModelEntry]: ...
ARGUMENTS
Optional
status
Type:str
Default value:'all'
Description:
Return only models with a specific status, or all models if status="all".
Iteration.issue_task()
Issue a new set of tasks for this iteration.
SIGNATURE
def issue_task(self, tasks: Task | typing.Sequence[Task]) -> None: ...
ARGUMENTS
Required
tasks
Type:Task | typing.Sequence[Task]
Description:
Task or list of tasks that need to be done next.
Iteration.process_current_tasks()
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.
SIGNATURE
def process_current_tasks(self) -> None: ...
Iteration.set_entry_point()
Modify the next entry point where this iteration will continue after all tasks have been completed.
SIGNATURE
def set_entry_point(self, next_task: str) -> None: ...
ARGUMENTS
Required
next_task
Type:str
Description:
Identifier of the next task.
Iteration.set_model_directory()
Set the path to the model inventory where all models and gradients of this iteration are stored.
SIGNATURE
def set_model_directory(self, path: pathlib.Path) -> None: ...
ARGUMENTS
Required
path
Type:pathlib.Path
Description:
Path to model inventory.
Iteration.to_disk()
Serialize the object to dictionary that can be written to JSON. Auxiliary files will be written to the specified path.
SIGNATURE
def to_disk(
    self, path: pathlib.Path, external_file_hash: str | None = None
) -> dict: ...
ARGUMENTS
Required
path
Type:pathlib.Path
Description:
Path to store auxiliary files.
Optional
external_file_hash
Type:str | None
Default value:None
Description:
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.
Iteration.to_json()
Serialize the object to dictionary that can be written to JSON.
SIGNATURE
def to_json(
    self,
    external_file_hash: str | None = None,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    comm: int | None = None,
) -> dict: ...
ARGUMENTS
Optional
external_file_hash
Type:str | None
Default value:None
Description:
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.
Optional
timer
Type:Timer | None
Default value:None
Description:
Execution timer.
Optional
log_to_logger
Type:bool
Default value:False
Description:
Log timings to the logger.
Optional
comm
Type:int | None
Default value:None
Description:
MPI communicator, if any.

TrialModelEntry

Entry describing a trial/auxiliary model.
This structure stores metadata and (potentially serialized) gradient information for auxiliary / trial models produced during an iteration.
SIGNATURE
class TrialModelEntry(typing.Generic, builtins.dict):
    def __init__(self): ...
PAGE CONTENTS