simulator.worker¶
The worker of a scan: the points of a chunk on one plan and one model.
run_chunk is the same function serially and in a worker process: for every
point of a chunk it applies the values of the point to the plan of the chunk,
Plan.with_values, and runs the plan with execute; the native solutions of
the points which ran are stacked into arrays padded with NaN, the observables
of the run are evaluated on them, see sbmlsim.simulator.observables, and the
kept timecourses are interpolated onto the grid of times of the chunk, if it
has one. A run without observables needs no native solution: the kept
selections of every point are interpolated right after its simulation, so the
memory of a chunk is bounded by its grid. A point fails exactly when its own
simulation or observables fail, not because of the other points of its chunk.
Nothing in here uses pint or xarray, and a chunk and its result are numbers,
strings, a plan and the graph of the observables, so they pickle.
In a worker process the model of a chunk is loaded once from its ModelSpec
and kept, see sbmlsim.parallel.worker_cache, with the integrator of the
model of the parent and every one of its settings, those of the simulator and
those set on the model, so a worker integrates as the parent does and the
result does not depend on the number of workers.
A point which fails is reported once, by its error: roadrunner logs the error
of CVODE as well, so its log level is lowered while a chunk runs. SUNDIALS
writes its own messages, a dozen lines or more per failing point, which a
worker process silences for the models it loads, see quiet_sundials; a
serial run keeps them, as the model of the user is not changed.
ScanPointError
¶
Bases: RuntimeError
A point of a scan failed and the run raises, see Chunk.on_error.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
the flat index of the point in the scan. |
|
message |
the error of the point. |
Create the error of a point, the arguments pickle.
ModelSpec
dataclass
¶
What a worker needs to load a model as the parent loaded it.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
identifies the model, its integrator and the settings of the integrator, the key of the model in the cache of a worker. |
source |
str
|
the SBML of the model as the parent loaded it, see
|
parameters |
tuple[tuple[str, float], ...]
|
the parameters added to the model, see |
integrator |
str
|
the name of the integrator, e.g. |
settings |
tuple[tuple[str, Any], ...]
|
every setting of the integrator by its name, the absolute
tolerance as the |
of
classmethod
¶
Get the spec of a loaded model and of the state of its integrator.
The integrator and its settings are read from the model after the
simulator set its own, see integrator_state, so a setting of the
model which the simulator does not set, e.g. one of
RoadrunnerSBMLModel(settings=...) or of set_integrator_settings,
holds in a worker as well.
Chunk
dataclass
¶
Points of a scan which share a plan and a model.
Attributes:
| Name | Type | Description |
|---|---|---|
indices |
ndarray
|
the flat indices of the points in the scan, in C order. |
plan |
Plan
|
the plan of the points. |
model |
int
|
the index of the model of the points among the models of the run. |
graph |
ObservableGraph
|
the observables of the run, which give the selections. |
values |
dict[str, ndarray]
|
target -> value of every point, which replaces the target wherever the plan sets it and is a change before the initialization otherwise. |
timed |
dict[float, dict[str, ndarray]]
|
time -> target -> value of every point, a change at that time. |
time |
ndarray | None
|
the grid of times to interpolate the kept timecourses onto,
|
on_error |
OnError
|
what to do about a point which fails. |
ChunkResult
dataclass
¶
The answer of a chunk.
Attributes:
| Name | Type | Description |
|---|---|---|
indices |
ndarray
|
the flat indices of the points, those of the chunk. |
values |
ndarray
|
the kept timecourses, |
scalars |
ndarray
|
the kept values per simulation, |
status |
ndarray
|
|
errors |
tuple[tuple[int, str], ...]
|
the flat index and the error of the first |
integrator_state
¶
Get the name of the integrator of a model and every one of its settings.
The absolute tolerance is the AbsoluteTolerance of the model, from which
RoadrunnerSBMLModel.set_integrator_settings computes the tolerance of
every state, and not the vector of the integrator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
RoadrunnerSBMLModel
|
the loaded model. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, tuple[tuple[str, Any], ...]]
|
The name of the integrator and its settings, sorted by name. |
point_plan
¶
Get the plan of the k-th point of values.
The values of the dimensions without a time are applied first, then the changes of the dimensions with one in time order, so a target in both has the value of the change at its time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan
|
Plan
|
the plan of the points. |
required |
values
|
Mapping[str, ndarray]
|
target -> value of every point. |
required |
timed
|
Mapping[float, Mapping[str, ndarray]]
|
time -> target -> value of every point. |
required |
k
|
int
|
the point. |
required |
Returns:
| Type | Description |
|---|---|
Plan
|
The plan with the values of the point. |
run_chunk
¶
Run the points of a chunk on a loaded model, see the module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk
|
Chunk
|
the points. |
required |
model
|
RoadrunnerSBMLModel
|
the loaded model of the chunk. |
required |
Returns:
| Type | Description |
|---|---|
ChunkResult
|
The values of every point. |
Raises:
| Type | Description |
|---|---|
ScanPointError
|
for the first point which fails, with
|
observe
¶
Evaluate the observables on the native solutions of points.
The graph is evaluated on all solutions at once. If an observable fails
the points are evaluated one at a time, each alone on its native solution
without padding, so a point fails exactly when its own evaluation fails,
whatever the other points are; the outputs of the points which succeed are
stacked again, padded with NaN to the longest of them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ObservableGraph
|
the observables. |
required |
selections
|
Sequence[str]
|
the columns of the solutions, the time first. |
required |
solutions
|
Sequence[ndarray]
|
the native solutions of the points. |
required |
plans
|
Sequence[Plan]
|
their plans. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The time points |
dict[str, ndarray]
|
outputs (a timecourse |
list[tuple[int, str, BaseException]]
|
|
tuple[ndarray, dict[str, ndarray], list[tuple[int, str, BaseException]]]
|
points whose observable failed (the position in |
tuple[ndarray, dict[str, ndarray], list[tuple[int, str, BaseException]]]
|
their message and error. |
run_chunk_in_worker
¶
Run a chunk in a worker process, on the model the worker keeps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
ModelSpec
|
the model of the chunk and the settings of its integrator. |
required |
chunk
|
Chunk
|
the points. |
required |
Returns:
| Type | Description |
|---|---|
ChunkResult
|
The values of every point, see |
quiet_roadrunner
¶
Lower the log level of roadrunner to critical messages, then restore it.
roadrunner logs the error of CVODE of a point which fails, which the run reports as the error of the point.
quiet_sundials
¶
Silence the messages of SUNDIALS of the models a worker process loads.
SUNDIALS reads the files of its messages from the environment when roadrunner creates the integrator of a model, so this applies to the models loaded after it and is no setting of a loaded model. Only a worker process of a pool is changed, never the process of the user, and a file the environment names already stays.
The change is permanent for the worker: a kept worker of
sbmlsim.parallel.pool never prints a message of SUNDIALS again, for
every model it loads later, e.g. the cases of testsuite.map_cases, also
for a scan which raises and for a point which succeeds. A failure is
reported through its exception or the variable status.