Skip to content

simulator.scan_core

A scan of the engine core, planned by sbmlsim-core.

Simulator.run of the engine core hands the scan to the planner of sbmlsim-core (sbmlsim_core.scan, the crate sbmlsim-scan): scan_request writes the request scan/1 (the scan as Scan.to_dict(), the observables as Observable.to_dict(), keep, the grid time, on_error, the block points, the settings of the requests simulation/1 and the selections of the model, as JSON types), run_core runs it on the threads of the engine in this process and sbmlsim.result.from_core.scan_result wraps its answer scanresult/1 into the ScanResult every engine gives. The planner compiles the plans, applies the values of the dimensions, folds the formulas at the changes, simulates the points in batches of the engine, evaluates the Formula and PK observables and interpolates onto the grid; a Custom observable is a function of python, which the planner asks for (observe) once the points of a batch ran. The numbers are the ones of the python path of the engine core which the planner replaced, see tests/simulator/test_scan_core_switch.py and the oracle fixtures of scripts/scan_fixtures.py.

The changes of a model (AbstractModel.changes) are the defaults of the pre-initialization of every simulation of the scan, as Simulator.compile applies them for every engine: the request carries the changes of the model of the run (changes), and the planner applies them. A scan with a dimension of models hands the planner the loaded model of every key of Dimension.models and the settings and changes of every model (model_settings, model_changes), and the planner applies them per model.

The errors of the planner are the ones of sbmlsim: a request which does not fit the model or a time or a value which cannot be converted is a ValueError, a simulation the engine does not simulate as roadrunner does an UnsupportedModelError, and the failed point of a scan of on_error="raise" the ScanError of sbmlsim.simulator.simulator with the labels and values of the point.

encoded_time

encoded_time(time)

Get the grid of a run as JSON types, a quantity as its value and unit.

scan_request

scan_request(
    model,
    scan,
    observables=None,
    *,
    time=None,
    keep=None,
    on_error="raise",
    points=None,
    settings=None,
    models=None,
)

Get the request scan/1 of a run, as JSON types, see the module.

The changes of the model of the run are changes; a scan with a dimension of models carries the settings of the requests of every model (model_settings, each with its own tolerance per state) and the changes of every model which has them (model_changes), by the keys of Dimension.models. The planner applies the changes as the defaults of the pre-initialization of the simulations of their model, see changes_of_models.

Parameters:

Name Type Description Default
model CoreSBMLModel

the model of the run, the first model of a dimension of models, which gives the settings of the requests of the engine and the selections.

required
scan Scan | Simulation

the scan, a simulation is a scan without dimensions.

required
observables Sequence[Observable] | None

the observables of the run.

None
time ArrayLike | Quantity | None

the grid of times of the run, see Simulator.run.

None
keep Sequence[str] | None

the observables (or selections) of the result.

None
on_error str

"raise" or "flag".

'raise'
points range | None

the block of the run, None for the whole scan.

None
settings Mapping[str, Any] | None

the settings of the requests of the engine, model.request_settings() by default.

None
models Mapping[str, CoreSBMLModel] | None

the model of every key of the dimension of models, None without one.

None

Returns:

Type Description
dict[str, Any]

The request.

core_threads

core_threads(n_workers, n_points)

Get the number of threads the engine core runs the points of a run on.

A number is taken as given and 1 runs the points on one thread. None is every CPU of the quota, at most one thread per point, for a run of any size: threads are no processes which have to be started, so the threshold of a pool (parallel.POOL_THRESHOLD) does not apply, and a batch of a few points of a model of the library earns them (a scan of 100 points of the HCTZ model over its draws took 14.3 s on one thread). A run inside a worker of a pool, or of a process which runs it beside a pool of its own (parallel.beside), takes the share of its process of the CPUs (parallel.worker_cores, at most one thread per point), so the shares of the processes of a busy pool add up to the CPUs. A worker which runs the long experiment of a run is no longer held to one core (sbmlsim#664).

Parameters:

Name Type Description Default
n_workers int | None

the threads of the run, None for every CPU.

required
n_points int

the points of the run.

required

Returns:

Type Description
int

The number of threads, at least one.

Raises:

Type Description
ValueError

if n_workers is less than 1.

run_core

run_core(
    model,
    scan,
    observables,
    *,
    time,
    keep,
    on_error,
    points,
    n_points,
    n_workers,
    progress,
    integrator_settings,
    models=None,
)

Run a scan of the engine core through the planner of sbmlsim-core.

The points run on the threads of core_threads in this process; a process of a pool counts itself among the ones which run threads while they run (parallel.threads). Every answered batch of points reports the event scan.chunk and advances the progress of the run, which is shown for a run on more than one thread unless progress says otherwise; a simulation is a scan of one point, which reports no progress.

Parameters:

Name Type Description Default
model CoreSBMLModel

the model of the run.

required
scan Scan

the scan; the changes of the model are the defaults of the pre-initialization of its simulations, see scan_request.

required
observables Sequence[Observable] | None

the observables of the run.

required
time ArrayLike | Quantity | None

the grid of times of the run.

required
keep Sequence[str] | None

the outputs of the result.

required
on_error str

"raise" or "flag".

required
points range | None

the block of the run, None for the whole scan.

required
n_points int

the points the run runs, the ones of the block.

required
n_workers int | None

the threads of the run, see core_threads.

required
progress bool | None

show a progress bar; None shows it for more than one thread.

required
integrator_settings Mapping[str, Any]

the record of the integrator settings of the run, the attribute integrator_settings of the result.

required
models Mapping[str, CoreSBMLModel] | None

the model of every key of a dimension of models, whose first one is model, None without one; the planner runs the points of a model on a batch executor of its own.

None

Returns:

Type Description
ScanResult

The result.

Raises:

Type Description
ValueError

for a request which does not fit the model.

UnsupportedModelError

for a simulation the engine does not simulate as roadrunner does.

ScanError

for the first point which fails, with on_error="raise".