Skip to content

petab_v2.testsuite

The cases of the PEtab v2 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:

group case compared
sbml PetabCase log-likelihood, chi2, simulations, log prior, log posterior
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 suite has no releases, so it is pinned by a commit. PetabSuite is the directory of the groups with the download and the cache of the commit.

CaseStatus

Bases: StrEnum

The outcome of a case.

CaseResult dataclass

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

The outcome of a case.

Attributes:

Name Type Description
group str

the group of the case, sbml or math.

cid str

the number of the case, e.g. 0001.

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, None when nothing was compared.

passed property

passed

Check whether the case passes.

key property

key

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

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.

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 v2 test suite.

Attributes:

Name Type Description
path Path

the directory which holds the directories of the groups, i.e. petabtests/cases/v2.0.0 of the suite.

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 groups 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 it if it is not cached.

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.

Raises:

Type Description
OSError

if the commit cannot be downloaded.

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, i.e. the name of its directory.

SBML

Returns:

Type Description
list[str]

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

list[str]

suite does not have.

cases

cases(group=SBML)

Iterate the cases of a group of models.

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 group sbml and of the math cases, in this

list[CaseResult]

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.