credibility.battery¶
The battery of the checks of a model: its variants, not its predictions.
The verification of the predictions (sbmlsim.credibility.verification) asks
whether the numbers a context of use is decided on are the solution of the
model. The battery asks whether the model itself is sound, independent of any
data: every variant of the project (sbmlsim.project.Project.variants) is
simulated with roadrunner from its initial state, without a change and with
the cases of the battery hook of the project, and the results are checked
against what every model must fulfil (BATTERY_CHECKS):
non_negativity: no species becomes negative beyond the floor of the integrator in any simulation.steady_state: without a change every state but the accumulating ones (accumulating_states, the sinks which nothing drains) stays at its start (BatterySettings.steady_limit): the model starts at its steady state. A model which is not meant to, e.g. a decay or an oscillator, does not; the check runs only when the settings say the model starts at its steady state (BatterySettings.steady_state, off by default) and is not applicable otherwise.cross_simulator: a second engine of sbmlsim (BatterySettings.engines, AMICI and COPASI, each one which is installed) gives the results of roadrunner without a change and with every case of the hook which it repeats (BatteryCase.cross_simulator), withinLIMIT; both run throughsbmlsim.simulator.Simulatoron the same simulation, roadrunner compiled atO0. What an engine does not simulate as roadrunner (sbmlsim.engine.UnsupportedModelError, e.g. an algebraic rule in COPASI) is no failure: the statement names it as not compared, and a check which compared nothing is not applicable. AMICI compiles a variant in a worker of a pool of its own (sbmlsim.parallel.start_pool) which is stopped afterBatterySettings.compile_timeout, so a compilation which takes too long is not compared either.plausibility: the initial state has finite values and positive compartments, and no value of an adopted fit lies at a bound of its fit (BatterySettings.bound_margin).rebuild: the factory of the project builds the models again (sbmlsim.project.Project.create_modelsinto a temporary directory), equal to the package but for the dates of the model history (sbmlsim.project.Project.changed_outputs).
A domain adds its simulations and checks with a BatteryHook, which the
project registers (sbmlsim.project.CredibilitySettings.battery): what it
reads from a variant (BatteryHook.read), the SBML the battery simulates
instead of the file (BatteryHook.sbml, e.g. with parameters which integrate
the flows of the reactions), further selections, the cases of its changes, e.g.
a dose of every route (BatteryCase), and further checks on the simulations
of every variant (BatteryHook.contribute, BatteryRun), which it registers
(sbmlsim.credibility.verification.register_check), with sections of plain
data in the record of the battery (Battery.sections) which the report shows
(BatteryHook.report_html, BatteryHook.report_tables). The settings are
the ones of the hook (BatteryHook.settings), else the defaults, with the
settings of the project over them
(sbmlsim.project.CredibilitySettings.battery_settings, see
battery_settings_of), so a project without a hook sets its engines, its
horizon or its tolerances as well. A check without what it needs is not
applicable and assesses nothing. A hook also says which generic check does
not apply to which variant (BatteryHook.not_applicable, e.g. no steady
state for a model of another kind than the others): the check runs on the
other variants and its statement names the variants left out with their
reason, and when it leaves out every variant the check is not applicable and
its statement gives the reasons per variant. The tables of the hook are
written whether or not the battery ran (BatteryHook.report_tables).
BatteryStatus
¶
Bases: StrEnum
The result of a check of the battery.
BatteryResult
dataclass
¶
The result of a check of the battery over the variants of a model.
Attributes:
| Name | Type | Description |
|---|---|---|
check |
Check
|
the check. |
status |
BatteryStatus
|
whether it passed, failed or was not applicable. |
cases |
int
|
what was checked, e.g. the species of the non-negativity over the variants. |
largest |
float
|
the largest relative deviation of the check, |
at |
str
|
where the largest deviation is, e.g. |
problems |
tuple[str, ...]
|
what failed, a line each. |
statement |
str
|
what was checked in words, the reason for a check which is not applicable. |
to_dict
¶
Get the result as plain data, NaN as None.
The record names the label and the factor of the check, so a check of a hook is read without its module.
from_dict
classmethod
¶
Get the result from plain data, None as NaN.
A record of pkpdsim 0.19 has neither the label nor the factor of its
checks, see sbmlsim.credibility.verification.check_of.
Battery
dataclass
¶
The results of the battery of a model.
Attributes:
| Name | Type | Description |
|---|---|---|
results |
tuple[BatteryResult, ...]
|
the result of every check, the generic ones and the ones of the hook, in the order of the report. |
sections |
Mapping[str, Any]
|
the sections of the hook, plain data by their name, e.g.
the fates of the doses of a PBPK model; a record of pkpdsim 0.19
has its fates as the section |
settings |
str
|
the settings of the simulations in words. |
result
¶
Get the result of a check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
check
|
Check | str
|
the check or its id. |
required |
Returns:
| Type | Description |
|---|---|
BatteryResult
|
The result. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if the battery has no result of the check. |
from_dict
classmethod
¶
Get the battery from plain data.
A record of pkpdsim 0.19 has its sections as fields of their own,
fates, which are read as the sections.
BatterySettings
dataclass
¶
BatterySettings(
*,
horizon=HORIZON,
steps=STEPS,
relative_tolerance=RELATIVE_TOLERANCE,
absolute_tolerance=ABSOLUTE_TOLERANCE,
steady_limit=STEADY_LIMIT,
bound_margin=BOUND_MARGIN,
steady_state=False,
cross_simulator=True,
engines=("amici", "copasi"),
compile_timeout=COMPILE_TIMEOUT,
)
The settings of the simulations of the battery.
Attributes:
| Name | Type | Description |
|---|---|---|
horizon |
float
|
the end of every simulation in the time of the model. |
steps |
int
|
the intervals of the grid of the results. |
relative_tolerance |
float
|
the relative tolerance of every simulation. |
absolute_tolerance |
float
|
the absolute tolerance, also the floor of a value which is zero. |
steady_limit |
float
|
the largest change of a state without a change relative to its start. |
bound_margin |
float
|
the share of the range of a bound (in the scale of the fit) within which a fitted value lies at the bound. |
steady_state |
bool
|
whether the model starts at its steady state, so the
check |
cross_simulator |
bool
|
run the check |
engines |
tuple[str, ...]
|
the second engines of the check |
compile_timeout |
float
|
the longest compilation of a variant by AMICI (s); a variant which takes longer is not compared with AMICI. |
BatteryCase
dataclass
¶
A simulation of the battery with changes, e.g. a dose.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
the name of the case, unique per variant, e.g. |
changes |
Mapping[float, Mapping[str, float]]
|
the changes by their time in the time of the model, the value of every id at that time; times on the grid of the battery. |
added |
frozenset[str]
|
the ids whose change is added to their value instead of setting it, e.g. the state of a dose. |
cross_simulator |
bool
|
whether the check |
BatteryBuild
dataclass
¶
BatteryBuild(
*,
variant,
path,
sbml,
species,
states,
accumulating,
selections=(),
cases=(),
data=None,
)
What the battery reads from a variant of a model.
Attributes:
| Name | Type | Description |
|---|---|---|
variant |
str
|
the name of the variant, e.g. |
path |
Path
|
the SBML file. |
sbml |
str
|
the SBML the battery simulates, the file or the one of the hook. |
species |
tuple[str, ...]
|
the species which are states (not constant, no boundary condition, no assignment rule), selected as their amounts. |
states |
tuple[str, ...]
|
the parameters and compartments with a rate rule. |
accumulating |
frozenset[str]
|
the states which nothing drains, see
|
selections |
tuple[str, ...]
|
the further selections of the hook. |
cases |
tuple[BatteryCase, ...]
|
the cases of the hook. |
data |
object
|
what the hook read from the variant ( |
columns
property
¶
Get the columns of the results: the states, the species first, and the selections of the hook.
BatteryRun
¶
The simulations of a variant with roadrunner on the grid of the battery.
Attributes:
| Name | Type | Description |
|---|---|---|
build |
the variant. |
|
settings |
the settings of the battery. |
|
r |
RoadRunner
|
the instance of roadrunner, compiled at |
columns |
the selections of the results without the time, see
|
|
index |
the column of every selection. |
|
values |
the value of every global parameter in the initial state. |
|
zero |
the simulation without a change. |
|
cases |
the simulation of every case of the hook, by its name. |
Load a variant at O0 with the tolerances of the battery.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
build
|
BatteryBuild
|
the variant. |
required |
settings
|
BatterySettings
|
the settings of the battery. |
required |
run
¶
Simulate from the initial state with the changes of a case.
An id of BatteryCase.added is increased by its change, any other id
set to it. The row of a change time is the state before the change,
except at 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
case
|
BatteryCase
|
the case. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The results on the grid, |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a change at a time which is no time of the grid before the horizon. |
column
¶
Get the values of a selection over the grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ndarray
|
a simulation of the variant. |
required |
sid
|
str
|
the selection. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Its values. |
scales
¶
Get the largest absolute value of ids over the simulations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
Sequence[str]
|
the selections. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The largest absolute value of every id. |
BatteryCollector
dataclass
¶
The cases and problems of a check over the variants.
Attributes:
| Name | Type | Description |
|---|---|---|
cases |
int
|
what was checked. |
largest |
float
|
the largest relative deviation, |
at |
str
|
where the largest deviation is. |
problems |
list[str]
|
what failed, a line each. |
deviation
¶
Record a deviation, the largest one is kept, where only above zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
the relative deviation. |
required |
at
|
str
|
where it is. |
required |
result
¶
Get the result of the check, failed with a problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
check
|
Check
|
the check. |
required |
statement
|
str
|
what it checks in words. |
required |
Returns:
| Type | Description |
|---|---|
BatteryResult
|
The result, with the first |
BatteryContribution
dataclass
¶
What a battery hook adds to the battery.
Attributes:
| Name | Type | Description |
|---|---|---|
results |
tuple[BatteryResult, ...]
|
the results of its checks, of |
sections |
Mapping[str, Any]
|
its sections of plain data by their name, e.g. |
BatteryHook
¶
The simulations and checks a project adds to the battery, see the module.
A subclass names itself and overrides what it adds; every method adds
nothing by default. A hook registers its checks
(sbmlsim.credibility.verification.register_check) when its module is
imported. BatteryHook.not_applicable leaves a variant out of a generic check.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
the name of the hook, e.g. |
checks |
tuple[Check, ...]
|
the checks the hook adds, whose results |
order |
tuple[str, ...]
|
the ids of every check of the battery in the order of the
report, the generic ones ( |
settings
¶
Get the settings of the simulations of the battery.
Returns:
| Type | Description |
|---|---|
BatterySettings
|
The settings, the defaults by default. |
read
¶
Read what the hook needs from a variant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variant
|
str
|
the name of the variant. |
required |
path
|
Path
|
its SBML file. |
required |
Returns:
| Type | Description |
|---|---|
object
|
What |
object
|
|
sbml
¶
Get the SBML the battery simulates instead of the file of the variant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
object
|
what |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The SBML, |
selections
¶
Get the further selections of the simulations of a variant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
object
|
what |
required |
Returns:
| Type | Description |
|---|---|
Sequence[str]
|
The selections, e.g. parameters which integrate the flows. |
cases
¶
Get the simulations with changes of a variant, e.g. its doses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
object
|
what |
required |
Returns:
| Type | Description |
|---|---|
Sequence[BatteryCase]
|
The cases. |
contribute
¶
Check the simulations of the variants with the checks of the hook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
Sequence[BatteryRun]
|
the simulations of every variant. |
required |
Returns:
| Type | Description |
|---|---|
BatteryContribution
|
The results of the checks and the sections of the hook. |
not_applicable
¶
Get why a generic check does not apply to a variant, None when it does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
check
|
str
|
the id of a generic check of the battery ( |
required |
data
|
object
|
what |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The reason the variant is left out of the check, |
str | None
|
default) when the check applies to it. |
describe
¶
Get the settings of the cases of the hook in words.
Returns:
| Type | Description |
|---|---|
str
|
A sentence the settings of the battery end with, e.g. the doses; |
str
|
empty by default. |
report_html
¶
Get the HTML of the sections of the hook in the report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sections
|
Mapping[str, Any]
|
the sections of the hook in the record of the battery. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The HTML after the table of the battery, e.g. the fates of the |
str
|
doses; empty for none. |
report_tables
¶
Get the tables the report writes for the sections of the hook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sections
|
Mapping[str, Any]
|
the sections of the hook in the record of the battery. |
required |
Returns:
| Type | Description |
|---|---|
Mapping[str, DataFrame]
|
The tables by the name of their file without the suffix, e.g. |
Mapping[str, DataFrame]
|
|
Mapping[str, DataFrame]
|
project has a hook, with empty sections when the battery did not |
Mapping[str, DataFrame]
|
run, and the hook must then return its tables empty, with their |
Mapping[str, DataFrame]
|
columns, so the files of a report depend on the hook only. |
CompileTimeout
¶
Bases: Exception
A compilation did not end within its deadline, see with_deadline.
battery_settings_of
¶
Get the settings of the battery of a project.
The settings of the hook, the defaults without one, with the settings of
the project over them (sbmlsim.project.CredibilitySettings.battery_settings).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Project
|
the project. |
required |
hook
|
BatteryHook | None
|
its battery hook. |
required |
Returns:
| Type | Description |
|---|---|
BatterySettings
|
The settings. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a setting of the project which the battery does not have or which is not valid. |
math_names
¶
Get the names a formula of a model reads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ast
|
ASTNode | None
|
the formula, |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
The names of the formula ( |
accumulating_states
¶
Get the states of a parsed model which nothing drains, sorted.
A state of a rate rule or a species a reaction produces and none consumes accumulates when no rate (of a rate rule or a reaction) reads it, also through the assignment rules and the compartments of the species read: a sink, e.g. the amount in the urine, which grows from its start without a change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
the model. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
The ids of the accumulating states. |
read_build
¶
Read a variant of a model for the battery.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variant
|
str
|
the name of the variant. |
required |
path
|
Path
|
its SBML file. |
required |
hook
|
BatteryHook | None
|
the battery hook of the project, which reads the variant first and may give the SBML, further selections and cases. |
None
|
Returns:
| Type | Description |
|---|---|
BatteryBuild
|
The variant with the SBML the battery simulates. |
not_applicable_result
¶
Get the result of a check which is not applicable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
check
|
Check
|
the check. |
required |
reason
|
str
|
why it is not applicable. |
required |
Returns:
| Type | Description |
|---|---|
BatteryResult
|
The result. |
battery_settings
¶
Get the settings of the simulations of the battery in words.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
BatterySettings
|
the settings. |
required |
hook
|
BatteryHook | None
|
the battery hook, whose description follows. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The settings in words. |
with_deadline
¶
Call a function in a worker of a pool of its own, stopped after a deadline.
In a worker of a pool, which starts no pool, the function is called in the process, without a deadline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
Callable[..., Any]
|
a module level function. |
required |
args
|
Sequence[Any]
|
its arguments, picklable. |
required |
timeout
|
float
|
the deadline (s). |
required |
Returns:
| Type | Description |
|---|---|
Any
|
What the function returns; an exception of the function is raised. |
Raises:
| Type | Description |
|---|---|
CompileTimeout
|
if the function did not return within the deadline; the worker is stopped. |
run_battery
¶
Run the battery of the checks of a project on its variants.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Project
|
the project, every variant of |
required |
rebuild
|
bool
|
run the check |
True
|
cross_simulator
|
bool
|
run the check |
True
|
hook
|
BatteryHook | None
|
the battery hook, the one of the project
( |
None
|
Returns:
| Type | Description |
|---|---|
Battery
|
The results of the checks and the sections of the hook. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the hook gives a result of a check it does not add, or misses one, and for invalid settings of the project. |