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) -> salvus.opt.tasks.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: builtins.set,
obtained: builtins.set,
key: str,
partial_update: bool = False,
) -> None:
...Utility function to validate a set of keys.
requiredbuiltins.set — Set of required items.obtainedbuiltins.set — 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_extensions.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: 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.
update_status()
update_status()def update_status(self, status: str) -> None:
...Update task status
statusstr — 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,
Union[
int,
str,
float,
salvus.flow.utils.serialization_helpers.SerializationMixin,
],
],
):
...Custom task. All required information needs to be passed as dictionary that can be serialized to JSON.
infoDict[str, Union[int, str, float, salvus.flow.utils.serialization_helpers.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: 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.
update_results()
update_results()def update_results(
self,
result: Dict[
str,
Union[
int,
str,
float,
salvus.flow.utils.serialization_helpers.SerializationMixin,
],
],
) -> None:
...Update the results of the tasks.
resultDict[str, Union[int, str, float, salvus.flow.utils.serialization_helpers.SerializationMixin]] — Task results.
update_status()
update_status()def update_status(self, status: str) -> None:
...Update task status
statusstr — 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: Sequence[str], required_events: Sequence[str] = []
):
...Task to select a subgroup of events as control group
eventsSequence[str] — List of events to choose from.required_eventsSequence[str] — 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: 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.
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: str) -> None:
...Update task status
statusstr — 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,
Union[
int,
str,
float,
salvus.flow.utils.serialization_helpers.SerializationMixin,
],
] = {},
):
...Custom task to finalize iteration.
infoDict[str, Union[int, str, float, salvus.flow.utils.serialization_helpers.SerializationMixin]] — 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: 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.
update_results()
update_results()def update_results(self) -> None:
...Update the status of the tasks.
update_status()
update_status()def update_status(self, status: str) -> None:
...Update task status
statusstr — 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: Sequence[str]):
...Task to compute gradients for a given model and list of events.
modelstr — ModeleventsSequence[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: 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.
update_results()
update_results()def update_results(
self, gradients: Dict[str, Any], partial_update: bool = False
) -> None:
...Update the results of the tasks.
gradientsDict[str, 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: str) -> None:
...Update task status
statusstr — 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: Sequence[str]):
...Task to compute misfits for a given model and list of events.
modelstr — ModeleventsSequence[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: 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.
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: str) -> None:
...Update task status
statusstr — 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: Sequence[str]):
...Task to compute misfits and gradients for a given model and list of events.
modelstr — ModeleventsSequence[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: 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.
update_results()
update_results()def update_results(
self, misfits: Dict[str, float], gradients: Dict[str, Any]
) -> None:
...Update the results of the tasks.
misfitsDict[str, float] — Dictionary with event-specific misfits.gradientsDict[str, Any] — Dictionary with event-specific gradients.
update_status()
update_status()def update_status(self, status: str) -> None:
...Update task status
statusstr — 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):
def __init__(self, model: str, events: Sequence[str]):
...Task to compute misfits and gradients for a given model and list of events and return the summed gradient.
modelstr — ModeleventsSequence[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: 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.
update_results()
update_results()def update_results(
self, misfits: Dict[str, float], gradient: Dict[str, Any]
) -> None:
...Update the results of the tasks.
misfitsDict[str, float] — Dictionary with event-specific misfits.gradientDict[str, Any] — Summed gradient.
update_status()
update_status()def update_status(self, status: str) -> None:
...Update task status
statusstr — 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):
def __init__(
self, model: Union[str, salvus.opt.models.base_model.BaseModel]
):
...Task to apply a preconditioner to a given model.
modelUnion[str, salvus.opt.models.base_model.BaseModel] — 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: 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.
update_results()
update_results()def update_results(
self,
preconditioned_model: Optional[
str, salvus.opt.models.base_model.BaseModel
] = None,
info: Optional[Dict[str, str]] = None,
) -> None:
...Update the results of the tasks.
preconditioned_modelOptional[str, salvus.opt.models.base_model.BaseModel] — Preconditioned model.infoOptional[Dict[str, str]] — Auxiliary information, e.g., the job name of a running simulation.
update_status()
update_status()def update_status(self, status: str) -> None:
...Update task status
statusstr — 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").