Mondaic

salvus.opt.tasks

salvus.opt.tasks salvus opt tasks

Collection of task objects to handle asynchronous inversions.

Functions

read_task_from_json()

def read_task_from_json(d: dict) -> Task: ...

Utility to deserialize a task. This requires to detect the correct class name from the JSON dictionary to instantiate the task.

Parameters
  • d dict — JSON dictionary of the task.
Returns Task — Task object.

validate_keys()

def validate_keys(
    required: set, obtained: set, key: str, partial_update: bool = False
) -> None: ...

Utility function to validate a set of keys.

Parameters
  • required set — Set of required items.
  • obtained set — Set of obtained items.
  • key str — Description of the set (just for printing nicer errors).
  • partial_update bool — Allow partial update that does not necessarily contain all required keys.
Returns None

Classes

Task

class Task(salvus.flow.utils.serialization_helpers.SerializationMixin):
    def __init__(self): ...

Base class to create tasks during an inversion.

Attributes
name str

Task name.

Methods
from_json()
def from_json(d: dict) -> typing.Self: ...

Construct object from a JSON-serializable dictionary.

Parameters
  • d dict — JSON dictionary of the task.
Returns typing.Self
to_json()
def to_json(
    self,
    external_file_hash: str | None = None,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    comm: int | None = None,
) -> dict: ...

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

Parameters
  • external_file_hash 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 Timer | None — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm int | None — MPI communicator, if any.
Returns dict
update_status()
def update_status(self, status: _valid_status) -> None: ...

Update task status.

Parameters
  • status _valid_status — New status.
Returns None
validate()
def validate(self, success: bool = False) -> None: ...

Validate status of the tasks.

Parameters
  • success bool — Raise if task has not been completed (status="done").
Returns None

TaskCustom

class TaskCustom(salvus.opt.tasks.Task):
    def __init__(
        self, info: dict[str, int | str | float | SerializationMixin]
    ): ...

Custom task. All required information needs to be passed as dictionary that can be serialized to JSON.

Parameters
  • info dict[str, int | str | float | SerializationMixin] — Custom task specification.
Attributes
name str

Task name.

Methods
from_json()
def from_json(d: dict) -> TaskCustom: ...

Construct object from a JSON-serializable dictionary.

Parameters
  • d dict — JSON dictionary of the task.
Returns TaskCustom
to_json()
def to_json(
    self,
    external_file_hash: str | None = None,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    comm: int | None = None,
) -> dict: ...

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

Parameters
  • external_file_hash 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 Timer | None — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm int | None — MPI communicator, if any.
Returns dict
update_results()
def update_results(
    self, result: dict[str, int | str | float | SerializationMixin]
) -> None: ...

Update the results of the tasks.

Parameters
  • result dict[str, int | str | float | SerializationMixin] — Task results.
Returns None
update_status()
def update_status(self, status: _valid_status) -> None: ...

Update task status.

Parameters
  • status _valid_status — New status.
Returns None
validate()
def validate(self, success: bool = False) -> None: ...

Validate status of the tasks.

Parameters
  • success bool — Raise if task has not been completed (status="done").
Returns None

TaskEventSelection

class TaskEventSelection(salvus.opt.tasks.Task):
    def __init__(
        self, events: list[str], required_events: list[str] | None = None
    ): ...

Task to select a subgroup of events as control group.

Parameters
  • events list[str] — List of events to choose from.
  • required_events list[str] | None — List of required events.
Attributes
name str

Task name.

Methods
from_json()
def from_json(d: dict) -> TaskEventSelection: ...

Construct object from a JSON-serializable dictionary.

Parameters
  • d dict — JSON dictionary of the task.
Returns TaskEventSelection
to_json()
def to_json(
    self,
    external_file_hash: str | None = None,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    comm: int | None = None,
) -> dict: ...

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

Parameters
  • external_file_hash 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 Timer | None — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm int | None — MPI communicator, if any.
Returns dict
update_results()
def update_results(self, selection: list[bool]) -> None: ...

Update the results of the tasks.

Parameters
  • selection list[bool] — Boolean list selecting / deselecting events.
Returns None
update_status()
def update_status(self, status: _valid_status) -> None: ...

Update task status.

Parameters
  • status _valid_status — New status.
Returns None
validate()
def validate(self, success: bool = False) -> None: ...

Validate status of the tasks.

Parameters
  • success bool — Raise if task has not been completed (status="done").
Returns None

TaskFinalizeIteration

class TaskFinalizeIteration(salvus.opt.tasks.Task):
    def __init__(
        self,
        info: dict[str, int | str | float | SerializationMixin] | None = None,
    ): ...

Custom task to finalize iteration.

Parameters
  • info dict[str, int | str | float | SerializationMixin] | None — Custom task specification.
Attributes
name str

Task name.

Methods
from_json()
def from_json(d: dict) -> TaskFinalizeIteration: ...

Construct object from a JSON-serializable dictionary.

Parameters
  • d dict — JSON dictionary of the task.
Returns TaskFinalizeIteration
to_json()
def to_json(
    self,
    external_file_hash: str | None = None,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    comm: int | None = None,
) -> dict: ...

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

Parameters
  • external_file_hash 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 Timer | None — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm int | None — MPI communicator, if any.
Returns dict
update_results()
def update_results(self) -> None: ...

Update the status of the tasks.

Returns None
update_status()
def update_status(self, status: _valid_status) -> None: ...

Update task status.

Parameters
  • status _valid_status — New status.
Returns None
validate()
def validate(self, success: bool = False) -> None: ...

Validate status of the tasks.

Parameters
  • success bool — Raise if task has not been completed (status="done").
Returns None

TaskGradients

class TaskGradients(salvus.opt.tasks.Task):
    def __init__(self, model: str, events: list[str]): ...

Task to compute gradients for a given model and list of events.

Parameters
  • model str — Model
  • events list[str] — List of events.
Attributes
name str

Task name.

Methods
from_json()
def from_json(d: dict) -> TaskGradients: ...

Construct object from a JSON-serializable dictionary.

Parameters
  • d dict — JSON dictionary of the task.
Returns TaskGradients
to_json()
def to_json(
    self,
    external_file_hash: str | None = None,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    comm: int | None = None,
) -> dict: ...

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

Parameters
  • external_file_hash 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 Timer | None — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm int | None — MPI communicator, if any.
Returns dict
update_results()
def update_results(
    self, gradients: dict[str, typing.Any], partial_update: bool = False
) -> None: ...

Update the results of the tasks.

Parameters
  • gradients dict[str, typing.Any] — Dictionary with event-specific gradients.
  • partial_update bool — Allow partial updates for a subset of data.
Returns None
update_status()
def update_status(self, status: _valid_status) -> None: ...

Update task status.

Parameters
  • status _valid_status — New status.
Returns None
validate()
def validate(self, success: bool = False) -> None: ...

Validate status of the tasks.

Parameters
  • success bool — Raise if task has not been completed (status="done").
Returns None

TaskMisfits

class TaskMisfits(salvus.opt.tasks.Task):
    def __init__(self, model: str, events: list[str]): ...

Task to compute misfits for a given model and list of events.

Parameters
  • model str — Model
  • events list[str] — List of events.
Attributes
name str

Task name.

Methods
from_json()
def from_json(d: dict) -> TaskMisfits: ...

Construct object from a JSON-serializable dictionary.

Parameters
  • d dict — JSON dictionary of the task.
Returns TaskMisfits
to_json()
def to_json(
    self,
    external_file_hash: str | None = None,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    comm: int | None = None,
) -> dict: ...

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

Parameters
  • external_file_hash 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 Timer | None — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm int | None — MPI communicator, if any.
Returns dict
update_results()
def update_results(
    self, misfits: dict[str, float], partial_update: bool = False
) -> None: ...

Update the results of the tasks.

Parameters
  • misfits dict[str, float] — Dictionary with event-specific misfits.
  • partial_update bool — Allow partial updates for a subset of data.
Returns None
update_status()
def update_status(self, status: _valid_status) -> None: ...

Update task status.

Parameters
  • status _valid_status — New status.
Returns None
validate()
def validate(self, success: bool = False) -> None: ...

Validate status of the tasks.

Parameters
  • success bool — Raise if task has not been completed (status="done").
Returns None

TaskMisfitsAndGradients

class TaskMisfitsAndGradients(salvus.opt.tasks.Task):
    def __init__(self, model: str, events: list[str]): ...

Task to compute misfits and gradients for a given model and list of events.

Parameters
  • model str — Model
  • events list[str] — List of events.
Attributes
name str

Task name.

Methods
from_json()
def from_json(d: dict) -> TaskMisfitsAndGradients: ...

Construct object from a JSON-serializable dictionary.

Parameters
  • d dict — JSON dictionary of the task.
Returns TaskMisfitsAndGradients
to_json()
def to_json(
    self,
    external_file_hash: str | None = None,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    comm: int | None = None,
) -> dict: ...

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

Parameters
  • external_file_hash 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 Timer | None — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm int | None — MPI communicator, if any.
Returns dict
update_results()
def update_results(
    self, misfits: dict[str, float], gradients: dict[str, typing.Any]
) -> None: ...

Update the results of the tasks.

Parameters
  • misfits dict[str, float] — Dictionary with event-specific misfits.
  • gradients dict[str, typing.Any] — Dictionary with event-specific gradients.
Returns None
update_status()
def update_status(self, status: _valid_status) -> None: ...

Update task status.

Parameters
  • status _valid_status — New status.
Returns None
validate()
def validate(self, success: bool = False) -> None: ...

Validate status of the tasks.

Parameters
  • success bool — Raise if task has not been completed (status="done").
Returns None

TaskMisfitsAndSummedGradient

class TaskMisfitsAndSummedGradient(salvus.opt.tasks.Task, typing.Generic):
    def __init__(self, model: str, events: list[str]): ...

Task to compute misfits and gradients for a given model and list of events and return the summed gradient.

Parameters
  • model str — Model
  • events list[str] — List of events.
Attributes
name str

Task name.

Methods
from_json()
def from_json(d: dict) -> TaskMisfitsAndSummedGradient: ...

Construct object from a JSON-serializable dictionary.

Parameters
  • d dict — JSON dictionary of the task.
Returns TaskMisfitsAndSummedGradient
to_json()
def to_json(
    self,
    external_file_hash: str | None = None,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    comm: int | None = None,
) -> dict: ...

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

Parameters
  • external_file_hash 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 Timer | None — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm int | None — MPI communicator, if any.
Returns dict
update_results()
def update_results(
    self,
    misfits: dict[str, float],
    gradient: dict[str, typing.Any] | ModelType,
) -> None: ...

Update the results of the tasks.

Parameters
  • misfits dict[str, float] — Dictionary with event-specific misfits.
  • gradient dict[str, typing.Any] | ModelType — Summed gradient.
Returns None
update_status()
def update_status(self, status: _valid_status) -> None: ...

Update task status.

Parameters
  • status _valid_status — New status.
Returns None
validate()
def validate(self, success: bool = False) -> None: ...

Validate status of the tasks.

Parameters
  • success bool — Raise if task has not been completed (status="done").
Returns None

TaskPreconditioner

class TaskPreconditioner(salvus.opt.tasks.Task, typing.Generic):
    def __init__(self, model: str | ModelType): ...

Task to apply a preconditioner to a given model.

Parameters
  • model str | ModelType — Model to apply the preconditioner to.
Attributes
name str

Task name.

Methods
from_json()
def from_json(d: dict) -> TaskPreconditioner: ...

Construct object from a JSON-serializable dictionary.

Parameters
  • d dict — JSON dictionary of the task.
Returns TaskPreconditioner
to_json()
def to_json(
    self,
    external_file_hash: str | None = None,
    timer: Timer | None = None,
    log_to_logger: bool = False,
    comm: int | None = None,
) -> dict: ...

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

Parameters
  • external_file_hash 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 Timer | None — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm int | None — MPI communicator, if any.
Returns dict
update_results()
def update_results(
    self,
    preconditioned_model: str | ModelType | None = None,
    info: dict[str, str] | None = None,
) -> None: ...

Update the results of the tasks.

Parameters
  • preconditioned_model str | ModelType | None — Preconditioned model.
  • info dict[str, str] | None — Auxiliary information, e.g., the job name of a running simulation.
Returns None
update_status()
def update_status(self, status: _valid_status) -> None: ...

Update task status.

Parameters
  • status _valid_status — New status.
Returns None
validate()
def validate(self, success: bool = False) -> None: ...

Validate status of the tasks.

Parameters
  • success bool — Raise if task has not been completed (status="done").
Returns None