salvus.opt.tasks
salvus.opt.tasks salvus opt tasks Collection of task objects to handle asynchronous inversions.
Functions
read_task_from_json()
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.
ddict — JSON dictionary of the task.
validate_keys()
validate_keys()def validate_keys(
required: set, obtained: set, key: str, partial_update: bool = False
) -> None: ...Utility function to validate a set of keys.
requiredset — Set of required items.obtainedset — Set of obtained items.keystr — Description of the set (just for printing nicer errors).partial_updatebool — Allow partial update that does not necessarily contain all required keys.
Classes
Task
Taskclass Task(salvus.flow.utils.serialization_helpers.SerializationMixin):
def __init__(self): ...Base class to create tasks during an inversion.
name str
name strTask name.
from_json()
from_json()def from_json(d: dict) -> typing.Self: ...Construct object from a JSON-serializable dictionary.
ddict — JSON dictionary of the task.
to_json()
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.
external_file_hashstr | 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.timerTimer | None — Execution timer.log_to_loggerbool — Log timings to the logger.commint | None — MPI communicator, if any.
update_status()
update_status()def update_status(self, status: _valid_status) -> None: ...Update task status.
status_valid_status — New status.
validate()
validate()def validate(self, success: bool = False) -> None: ...Validate status of the tasks.
successbool — Raise if task has not been completed (status="done").
TaskCustom
TaskCustomclass 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.
infodict[str, int | str | float | SerializationMixin] — Custom task specification.
name str
name strTask name.
from_json()
from_json()def from_json(d: dict) -> TaskCustom: ...Construct object from a JSON-serializable dictionary.
ddict — JSON dictionary of the task.
to_json()
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.
external_file_hashstr | 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.timerTimer | None — Execution timer.log_to_loggerbool — Log timings to the logger.commint | None — MPI communicator, if any.
update_results()
update_results()def update_results(
self, result: dict[str, int | str | float | SerializationMixin]
) -> None: ...Update the results of the tasks.
resultdict[str, int | str | float | SerializationMixin] — Task results.
update_status()
update_status()def update_status(self, status: _valid_status) -> None: ...Update task status.
status_valid_status — New status.
validate()
validate()def validate(self, success: bool = False) -> None: ...Validate status of the tasks.
successbool — Raise if task has not been completed (status="done").
TaskEventSelection
TaskEventSelectionclass 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.
eventslist[str] — List of events to choose from.required_eventslist[str] | None — List of required events.
name str
name strTask name.
from_json()
from_json()def from_json(d: dict) -> TaskEventSelection: ...Construct object from a JSON-serializable dictionary.
ddict — JSON dictionary of the task.
to_json()
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.
external_file_hashstr | 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.timerTimer | None — Execution timer.log_to_loggerbool — Log timings to the logger.commint | None — MPI communicator, if any.
update_results()
update_results()def update_results(self, selection: list[bool]) -> None: ...Update the results of the tasks.
selectionlist[bool] — Boolean list selecting / deselecting events.
update_status()
update_status()def update_status(self, status: _valid_status) -> None: ...Update task status.
status_valid_status — New status.
validate()
validate()def validate(self, success: bool = False) -> None: ...Validate status of the tasks.
successbool — Raise if task has not been completed (status="done").
TaskFinalizeIteration
TaskFinalizeIterationclass TaskFinalizeIteration(salvus.opt.tasks.Task):
def __init__(
self,
info: dict[str, int | str | float | SerializationMixin] | None = None,
): ...Custom task to finalize iteration.
infodict[str, int | str | float | SerializationMixin] | None — Custom task specification.
name str
name strTask name.
from_json()
from_json()def from_json(d: dict) -> TaskFinalizeIteration: ...Construct object from a JSON-serializable dictionary.
ddict — JSON dictionary of the task.
to_json()
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.
external_file_hashstr | 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.timerTimer | None — Execution timer.log_to_loggerbool — Log timings to the logger.commint | None — MPI communicator, if any.
update_results()
update_results()def update_results(self) -> None: ...Update the status of the tasks.
update_status()
update_status()def update_status(self, status: _valid_status) -> None: ...Update task status.
status_valid_status — New status.
validate()
validate()def validate(self, success: bool = False) -> None: ...Validate status of the tasks.
successbool — Raise if task has not been completed (status="done").
TaskGradients
TaskGradientsclass 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.
modelstr — Modeleventslist[str] — List of events.
name str
name strTask name.
from_json()
from_json()def from_json(d: dict) -> TaskGradients: ...Construct object from a JSON-serializable dictionary.
ddict — JSON dictionary of the task.
to_json()
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.
external_file_hashstr | 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.timerTimer | None — Execution timer.log_to_loggerbool — Log timings to the logger.commint | None — MPI communicator, if any.
update_results()
update_results()def update_results(
self, gradients: dict[str, typing.Any], partial_update: bool = False
) -> None: ...Update the results of the tasks.
gradientsdict[str, typing.Any] — Dictionary with event-specific gradients.partial_updatebool — Allow partial updates for a subset of data.
update_status()
update_status()def update_status(self, status: _valid_status) -> None: ...Update task status.
status_valid_status — New status.
validate()
validate()def validate(self, success: bool = False) -> None: ...Validate status of the tasks.
successbool — Raise if task has not been completed (status="done").
TaskMisfits
TaskMisfitsclass 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.
modelstr — Modeleventslist[str] — List of events.
name str
name strTask name.
from_json()
from_json()def from_json(d: dict) -> TaskMisfits: ...Construct object from a JSON-serializable dictionary.
ddict — JSON dictionary of the task.
to_json()
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.
external_file_hashstr | 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.timerTimer | None — Execution timer.log_to_loggerbool — Log timings to the logger.commint | None — MPI communicator, if any.
update_results()
update_results()def update_results(
self, misfits: dict[str, float], partial_update: bool = False
) -> None: ...Update the results of the tasks.
misfitsdict[str, float] — Dictionary with event-specific misfits.partial_updatebool — Allow partial updates for a subset of data.
update_status()
update_status()def update_status(self, status: _valid_status) -> None: ...Update task status.
status_valid_status — New status.
validate()
validate()def validate(self, success: bool = False) -> None: ...Validate status of the tasks.
successbool — Raise if task has not been completed (status="done").
TaskMisfitsAndGradients
TaskMisfitsAndGradientsclass 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.
modelstr — Modeleventslist[str] — List of events.
name str
name strTask name.
from_json()
from_json()def from_json(d: dict) -> TaskMisfitsAndGradients: ...Construct object from a JSON-serializable dictionary.
ddict — JSON dictionary of the task.
to_json()
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.
external_file_hashstr | 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.timerTimer | None — Execution timer.log_to_loggerbool — Log timings to the logger.commint | None — MPI communicator, if any.
update_results()
update_results()def update_results(
self, misfits: dict[str, float], gradients: dict[str, typing.Any]
) -> None: ...Update the results of the tasks.
misfitsdict[str, float] — Dictionary with event-specific misfits.gradientsdict[str, typing.Any] — Dictionary with event-specific gradients.
update_status()
update_status()def update_status(self, status: _valid_status) -> None: ...Update task status.
status_valid_status — New status.
validate()
validate()def validate(self, success: bool = False) -> None: ...Validate status of the tasks.
successbool — Raise if task has not been completed (status="done").
TaskMisfitsAndSummedGradient
TaskMisfitsAndSummedGradientclass 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.
modelstr — Modeleventslist[str] — List of events.
name str
name strTask name.
from_json()
from_json()def from_json(d: dict) -> TaskMisfitsAndSummedGradient: ...Construct object from a JSON-serializable dictionary.
ddict — JSON dictionary of the task.
to_json()
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.
external_file_hashstr | 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.timerTimer | None — Execution timer.log_to_loggerbool — Log timings to the logger.commint | None — MPI communicator, if any.
update_results()
update_results()def update_results(
self,
misfits: dict[str, float],
gradient: dict[str, typing.Any] | ModelType,
) -> None: ...Update the results of the tasks.
misfitsdict[str, float] — Dictionary with event-specific misfits.gradientdict[str, typing.Any] | ModelType — Summed gradient.
update_status()
update_status()def update_status(self, status: _valid_status) -> None: ...Update task status.
status_valid_status — New status.
validate()
validate()def validate(self, success: bool = False) -> None: ...Validate status of the tasks.
successbool — Raise if task has not been completed (status="done").
TaskPreconditioner
TaskPreconditionerclass TaskPreconditioner(salvus.opt.tasks.Task, typing.Generic):
def __init__(self, model: str | ModelType): ...Task to apply a preconditioner to a given model.
modelstr | ModelType — Model to apply the preconditioner to.
name str
name strTask name.
from_json()
from_json()def from_json(d: dict) -> TaskPreconditioner: ...Construct object from a JSON-serializable dictionary.
ddict — JSON dictionary of the task.
to_json()
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.
external_file_hashstr | 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.timerTimer | None — Execution timer.log_to_loggerbool — Log timings to the logger.commint | None — MPI communicator, if any.
update_results()
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.
preconditioned_modelstr | ModelType | None — Preconditioned model.infodict[str, str] | None — Auxiliary information, e.g., the job name of a running simulation.
update_status()
update_status()def update_status(self, status: _valid_status) -> None: ...Update task status.
status_valid_status — New status.
validate()
validate()def validate(self, success: bool = False) -> None: ...Validate status of the tasks.
successbool — Raise if task has not been completed (status="done").