sciml.testsuite¶
The cases of the PEtab SciML test suite on disk.
The test suite has
three groups of cases, every case is a directory named by its number with a
solutions.yaml:
| group | case | compared |
|---|---|---|
ml_model_import |
ModelImportCase |
the outputs of the forward pass |
initialization |
InitializationCase |
the nominal values of the arrays |
sciml_problem_import |
ProblemImportCase |
likelihood, simulations, gradient |
The suite has no releases, so it is pinned by a commit. SciMLSuite is the
directory of the groups with the download and the cache of the commit.
The arrays of the suite are in the PyTorch layout, which is the layout of
sbmlsim: the axis orders input_order_py and output_order_py of a case
name the axes of the arrays as they are stored, nothing is permuted.
CaseStatus
¶
Bases: StrEnum
The outcome of a case.
CaseResult
dataclass
¶
The outcome of a case.
Attributes:
| Name | Type | Description |
|---|---|---|
group |
str
|
the group of the case. |
cid |
str
|
the number of the case, e.g. |
status |
CaseStatus
|
the outcome. |
message |
str
|
what failed, empty for a case which passes. |
max_difference |
float | None
|
the largest absolute difference to the reference
values, |
ModelImportCase
dataclass
¶
ModelImportCase(
cid,
path,
net_file,
inputs,
parameters,
outputs,
input_order=list(),
output_order=list(),
dropout=None,
)
A case of the group ml_model_import.
A case is a network with combinations of inputs, arrays and the outputs
the network has for them. The combination i is the input i, the
arrays i and the output i.
Attributes:
| Name | Type | Description |
|---|---|---|
cid |
str
|
the number of the case, e.g. |
path |
Path
|
the directory of the case. |
net_file |
Path
|
the NN YAML. |
inputs |
list[list[Path]]
|
the input files of every combination, one per input of the network. |
parameters |
list[Path]
|
the array file of every combination, empty for a network without arrays. |
outputs |
list[Path]
|
the output file of every combination. |
input_order |
list[str]
|
the axes of the inputs, e.g. |
output_order |
list[str]
|
the axes of the outputs. |
dropout |
int | None
|
the number of forward passes in training mode the reference
values are the mean of, |
from_directory
classmethod
¶
Read a case from its directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
the directory of the case, named by its number. |
required |
Returns:
| Type | Description |
|---|---|
ModelImportCase
|
The case. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the directory has no |
network
¶
Get the network with the arrays of a combination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
int
|
the index of the combination. |
required |
Returns:
| Type | Description |
|---|---|
Network
|
The network. |
run
¶
Evaluate the network for every combination and compare the outputs.
Returns:
| Type | Description |
|---|---|
CaseResult
|
The outcome of the case. It does not raise: a layer without an |
CaseResult
|
implementation is |
InitializationCase
dataclass
¶
A case of the group initialization.
A case is a PEtab SciML problem whose parameter table sets the nominal values of a part of a network, and the arrays the network has after the import.
Attributes:
| Name | Type | Description |
|---|---|---|
cid |
str
|
the number of the case, e.g. |
path |
Path
|
the directory of the case. |
problem_path |
Path
|
the YAML of the problem. |
tolerance |
float
|
the absolute tolerance of the arrays. |
parameter_files |
dict[str, Path]
|
id of the network -> the file with its reference values. |
from_directory
classmethod
¶
Read a case from its directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
the directory of the case, named by its number. |
required |
Returns:
| Type | Description |
|---|---|
InitializationCase
|
The case. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the directory has no |
nominal
¶
Import the networks of the problem with their nominal values.
The problem is read with the classes of petab which need no
torch: the configuration, the parameter table and the mapping
table. The rows of the parameter table which the mapping table
resolves to the parameters of a network are the entries of
nominal_parameters; the nominalValue array keeps the values of
the array file.
Returns:
| Type | Description |
|---|---|
dict[str, NetworkParameters]
|
id of the network -> the arrays of the network. |
Raises:
| Type | Description |
|---|---|
NetworkImportError
|
if the problem is not a PEtab SciML problem,
a network is not in the format |
expected
¶
Read the reference values of the arrays.
Returns:
| Type | Description |
|---|---|
dict[str, NetworkParameters]
|
id of the network -> the arrays of the network. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a reference file has no arrays of its network. |
run
¶
Import the networks and compare their nominal values.
Returns:
| Type | Description |
|---|---|
CaseResult
|
The outcome of the case. It does not raise: a layer without an |
CaseResult
|
implementation is |
ProblemImportCase
dataclass
¶
ProblemImportCase(
cid,
path,
problem_path,
llh,
log_posterior,
simulation_files,
gradient_files,
tol_llh,
tol_simulations,
tol_grad,
)
A case of the group sciml_problem_import.
A case is a PEtab SciML problem with the log-likelihood, the simulations
at the measurements and the gradient of the log-likelihood at the nominal
values of its parameters. The reference values of the gradient are the
central differences of five points of a simulation with the tolerances
1e-12.
Attributes:
| Name | Type | Description |
|---|---|---|
cid |
str
|
the number of the case, e.g. |
path |
Path
|
the directory of the case. |
problem_path |
Path
|
the YAML of the problem. |
llh |
float | None
|
the log-likelihood at the nominal values, |
log_posterior |
float | None
|
the log-posterior at the nominal values, |
simulation_files |
list[Path]
|
the simulations at the measurement points. |
gradient_files |
dict[str, Path]
|
|
tol_llh |
float
|
tolerance of the log-likelihood or the log-posterior. |
tol_simulations |
float
|
tolerance of the simulations. |
tol_grad |
float
|
tolerance of the gradient. |
from_directory
classmethod
¶
Read a case from its directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
the directory of the case, named by its number. |
required |
Returns:
| Type | Description |
|---|---|
ProblemImportCase
|
The case. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the directory has no |
settings
¶
Get the settings the problem of the case is initialized with.
Returns:
| Type | Description |
|---|---|
FitSettings
|
Settings with the linear scale, a fixed grid and the tolerances |
FitSettings
|
|
FitSettings
|
differ by more than a difference of the gradient resolves. |
expected_simulations
¶
Read the reference values of the simulations.
Returns:
| Type | Description |
|---|---|
DataFrame
|
The rows of the simulation files with the columns |
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if the case has no simulation file, or if a file lacks a column. |
expected_gradient
¶
Read the reference values of the gradient.
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
id of the parameter -> derivative of the log-likelihood. The id of |
dict[str, float]
|
an element of a network is its id in |
dict[str, float]
|
|
dict[str, float]
|
stores as an empty array is frozen and has no derivative. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the case has no gradient of the mechanistic parameters, or if a file cannot be read. |
run
¶
Read the problem and compare its values with the reference values.
The log-likelihood, the simulations at the measurements and the gradient of the log-likelihood are compared, each with its tolerance. The models the problem is simulated with are written into a temporary directory.
Returns:
| Type | Description |
|---|---|
CaseResult
|
The outcome of the case. It does not raise: a problem with a gap |
CaseResult
|
or a layer without an implementation is |
CaseResult
|
other error is |
round_trip
¶
Write the problem of the case as PEtab SciML and read it back.
The problem is read twice from the case and once from its export:
the first model roadrunner loads in a process differs by about
1e-9 from every later one, so the export is compared with the
second read, bit for bit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
Path
|
the directory the export and the derived models are written to. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
What differs between the problem of the case and the problem |
list[str]
|
which is read back, one line each: the parameters (id, start |
list[str]
|
value, bounds, unit, scale, target), the hybridizations, the |
list[str]
|
data, the kinds and the weights of the fit mappings, the |
list[str]
|
predictions and the log-likelihood. What |
list[str]
|
with the export is listed too, or that it was not validated |
list[str]
|
because torch is missing. A case without parameters, fit |
list[str]
|
mappings or hybridizations is a difference, it compares nothing. |
list[str]
|
Empty when the round trip is exact. |
SciMLSuite
dataclass
¶
The cases of a commit of the PEtab SciML test suite.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
the directory which holds the directories of the groups, i.e.
|
commit |
str
|
the commit of the suite. |
cache_path
staticmethod
¶
Get the directory a commit of the suite is unpacked into.
SBMLSIM_SCIML_SUITE_PATH overrides it. Otherwise it is
sbmlsim/petab-sciml-testsuite/<commit> in the user cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
commit
|
str
|
the commit of the suite. |
SCIML_SUITE_COMMIT
|
Returns:
| Type | Description |
|---|---|
Path
|
The directory the groups of the commit live in. |
cached
classmethod
¶
Get a commit of the suite if it is already on this machine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
commit
|
str
|
the commit of the suite. |
SCIML_SUITE_COMMIT
|
Returns:
| Type | Description |
|---|---|
SciMLSuite | None
|
The suite, or |
load
classmethod
¶
Get a commit of the suite, downloading it if it is not cached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
commit
|
str
|
the commit of the suite. |
SCIML_SUITE_COMMIT
|
Returns:
| Type | Description |
|---|---|
SciMLSuite
|
The suite with its cases unpacked in the cache. |
Raises:
| Type | Description |
|---|---|
OSError
|
if the commit cannot be downloaded. |
case_ids
¶
Get the numbers of the cases of a group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str
|
the group, i.e. the name of its directory. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The names of the case directories, sorted, empty for a group the |
list[str]
|
suite does not have. |
run
¶
Run the cases of the suite.
Returns:
| Type | Description |
|---|---|
list[CaseResult]
|
The results of the groups |
list[CaseResult]
|
|
read_solutions
¶
Read the solutions.yaml of a case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
the directory of the case. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The content of the file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the directory has no |
required
¶
Get a value of the solutions.yaml of a case which must be there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solutions
|
dict[str, Any]
|
the content of the file. |
required |
key
|
str
|
the key of the value. |
required |
path
|
Path
|
the directory of the case, for the message. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the file has no value for the key. |
read_array
¶
Read the single array of an input or output file of a case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
the HDF5 file. |
required |
group
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The array in the PyTorch layout, in double precision. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the file does not hold exactly one array in the group or is not in the PyTorch layout. |
compare_arrays
¶
Compare an array with its reference values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observed
|
ndarray
|
the values of |
required |
expected
|
ndarray
|
the reference values. |
required |
tolerance
|
float
|
the absolute tolerance. |
required |
Returns:
| Type | Description |
|---|---|
CaseStatus
|
The outcome, the message and the largest absolute difference, |
str
|
when the shapes differ or a value is not finite. |
parameter_key
¶
Get the key of an entry from a modelEntityId of the mapping table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_entity_id
|
str
|
the entity, e.g. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The key of |
str | None
|
|
str | None
|
|
str | None
|
an entity which is not the parameters of a network. |
nothing_to_compare
¶
Name what a problem lacks for a round trip to compare anything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
OptimizationProblem
|
the problem read from a case. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
One line for each of the parameters, fit mappings and hybridizations |
list[str]
|
which the problem does not have. |