Skip to content

petab_v2.testsuite

The cases of the PEtab test suite on disk.

The test suite has a group of cases per model format and the cases of the math of PEtab, below petabtests/cases/v2.0.0, and the cases of PEtab v1 below petabtests/cases/v1.0.0. sbmlsim reads PEtab v2 only, a case of PEtab v1 is converted to PEtab v2 with its simulations once, see sbmlsim.fit.petab_v2.conversion, and run as a case of PEtab v2:

group case compared
sbml PetabCase log-likelihood, chi2, simulations, log prior, log posterior
v1/sbml PetabCase the same, of the case of PEtab v1 converted to PEtab v2
math MathCase the value of an expression of math_tests.yaml

A case of a model is a directory named by its number with the problem _<id>.yaml, the solution _<id>_solution.yaml and the simulations it names. It is read with PetabReader, simulated at the nominal values of its parameter table (PetabReader.nominal_parameters) and compared with the tolerances of its solution. A math case compiles its expression with sbmlsim.simulator.formula.compile_formula, which is what the formulas of conditions, observables and noise are evaluated with. The cases of PySB models (pysb) are not run, sbmlsim simulates SBML.

The suite has no releases, so it is pinned by a commit. PetabSuite is the directory of the cases of both versions with the download, the conversion and the cache of the commit.

CaseStatus

Bases: StrEnum

The outcome of a case.

CaseResult dataclass

CaseResult(
    group, cid, status, message="", max_difference=None
)

Bases: CaseOutcome[CaseStatus]

The outcome of a case, of the group sbml or math.

PetabCase dataclass

PetabCase(path, cid, group, problem_file, solution)

A case of a model of the PEtab v2 test suite.

Attributes:

Name Type Description
path Path

the directory of the case.

cid str

the number of the case, the name of its directory.

group str

the group of the case, the format of its model.

problem_file Path

the YAML file of the problem.

solution dict[str, Any]

the content of the solution.

key property

key

Get the key of the case in the baseline, e.g. sbml/0001.

from_directory classmethod

from_directory(path, group=SBML)

Read a case from its directory.

Parameters:

Name Type Description Default
path Path

the directory of the case.

required
group str

the group of the case.

SBML

Returns:

Type Description
PetabCase

The case.

Raises:

Type Description
ValueError

if the directory has no problem or no solution, or is a case of PEtab v1 which could not be converted.

run

run()

Run the case.

Returns:

Type Description
CaseResult

The outcome, error when the case cannot be read or simulated.

MathCase dataclass

MathCase(index, expression, expected)

A case of the math of PEtab.

Attributes:

Name Type Description
index int

the position of the case in math_tests.yaml.

expression str

the math expression.

expected float | str

its value, a number or a symbolic expression.

cid property

cid

Get the number of the case, its position with three digits.

run

run()

Compile the expression and compare its value.

A symbolic expression is evaluated with both at values of its symbols.

Returns:

Type Description
CaseResult

The outcome, error when the expression is not compiled.

PetabSuite dataclass

PetabSuite(path, commit)

The cases of a commit of the PEtab test suite.

Attributes:

Name Type Description
path Path

the directory of the cases of the suite, i.e. petabtests/cases with the versions v1.0.0 and v2.0.0, and the cases of PEtab v1 converted to PEtab v2, see convert.

commit str

the commit of the suite.

cache_path staticmethod

cache_path(commit=PETAB_SUITE_COMMIT)

Get the directory a commit of the suite is unpacked into.

SBMLSIM_PETAB_SUITE_PATH overrides it. Otherwise it is sbmlsim/petab-test-suite/<commit> in the user cache.

Parameters:

Name Type Description Default
commit str

the commit of the suite.

PETAB_SUITE_COMMIT

Returns:

Type Description
Path

The directory the cases of the commit live in.

cached classmethod

cached(commit=PETAB_SUITE_COMMIT)

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.

PETAB_SUITE_COMMIT

Returns:

Type Description
PetabSuite | None

The suite, or None if it was not downloaded yet.

load classmethod

load(commit=PETAB_SUITE_COMMIT)

Get a commit of the suite, downloading and converting it once.

Parameters:

Name Type Description Default
commit str

the commit of the suite.

PETAB_SUITE_COMMIT

Returns:

Type Description
PetabSuite

The suite with its cases unpacked in the cache and the cases of

PetabSuite

PEtab v1 converted to PEtab v2.

Raises:

Type Description
OSError

if the commit cannot be downloaded.

convert

convert()

Convert the cases of PEtab v1 which are not converted yet.

A case is converted with its simulations into the directory of the group v1/sbml, its solution names the converted simulations. A case which cannot be converted gets the file CONVERSION_ERROR with the reason instead of its problem, which PetabCase.run reports.

case_ids

case_ids(group=SBML)

Get the numbers of the cases of a group of models.

Parameters:

Name Type Description Default
group str

the group, see GROUP_DIRECTORIES.

SBML

Returns:

Type Description
list[str]

The names of the case directories, sorted, empty for a group the

list[str]

suite does not have.

case

case(cid, group=SBML)

Get a case of a group of models by its number.

cases

cases(group=SBML)

Iterate the cases of a group of models.

run_case

run_case(cid, group=SBML)

Run a case of a group of models, error for one which cannot be read.

math_cases

math_cases()

Get the math cases, empty for a suite without them.

run

run()

Run the cases of the suite.

Returns:

Type Description
list[CaseResult]

The results of the groups sbml and v1/sbml and of the math

list[CaseResult]

cases, in this order.

math_cases

math_cases(path)

Read the math cases of a math_tests.yaml.

Parameters:

Name Type Description Default
path Path

the file.

required

Returns:

Type Description
list[MathCase]

The cases in the order of the file.

Raises:

Type Description
ValueError

if a case has no expression or no expected value.