Skip to content

testing

The tests of a model as functions: the registry, the experiments, the fits.

A repository of models calls them from its own tests, so that a model which is exported into a repository of its own keeps them (check_model checks that the model object belongs to its package):

# not executed
@pytest.mark.parametrize("model", MODELS)
def test_experiments_registered(model: PKPDModel) -> None:
    testing.check_registry(model)

The known exceptions of the tests (experiments which are not registered on purpose, modules which do not import, the reason to run the experiments one at a time) are the checks of the model object, each with its reason.

The functions raise AssertionError with a message which names every problem, also for experiments which fail to initialize or to run.

experiment_modules

experiment_modules(model)

Import the modules below experiments of a model.

The modules in model.checks.not_importable are skipped.

Parameters:

Name Type Description Default
model PKPDModel

the model.

required

Returns:

Type Description
list[ModuleType]

The imported modules and the traceback of every module which does not

dict[str, str]

import, by its name relative to the package of the model.

defined_experiments

defined_experiments(modules)

Get the experiments defined in modules, without the base experiments.

A base experiment is a class from which another of the found classes derives.

registered_experiments

registered_experiments(model)

Get the experiments of the group all of the registry of a model.

check_registry

check_registry(model)

Check that every experiment a model defines is in its registry.

Every module below experiments imports, every experiment is registered in all once, and the known exceptions of model.checks are still exceptions (a listed class is defined and not registered, a listed module exists).

Parameters:

Name Type Description Default
model PKPDModel

the model.

required

Raises:

Type Description
AssertionError

naming every problem.

check_model

check_model(model)

Check that a model object belongs to its package and its references hold.

A slip in package or path of a model resolves the references of another model, or names the paths wrongly, without an error otherwise. The name is the last component of the package (or the component ends with _<name>), model_path, the factory directory and archive_path lie below path, and the data paths exist.

Raises:

Type Description
AssertionError

naming every problem.

initialize_experiments

initialize_experiments(model)

Initialize the registered experiments with their data, figures, mappings.

Every experiment is initialized, also after one which cannot be.

Returns:

Type Description
dict[str, SimulationExperiment]

The experiments by name.

Raises:

Type Description
AssertionError

naming every experiment which cannot be initialized with its error; the tracebacks are in the log of sbmlsim.

run_all_experiments

run_all_experiments(model, output_dir)

Run the registered experiments, as run_<model> does.

Every experiment runs, also after one which failed.

Parameters:

Name Type Description Default
model PKPDModel

the model.

required
output_dir Path

the directory of the results. With model.checks.one_at_a_time every experiment runs on its own, into a directory named after it: the memory of a run of all experiments of a large model exceeds that of a runner of a continuous integration.

required

Raises:

Type Description
AssertionError

naming every failed experiment and figure, and every run which wrote no report.

start_fits

start_fits(model, output_dir, max_nfev=2)

Start a fit of every fit definition: one start with a few evaluations.

Parameters:

Name Type Description Default
model PKPDModel

the model.

required
output_dir Path

the directory of the results of the fits.

required
max_nfev int

evaluations of the cost per start.

2

Returns:

Type Description
dict[str, dict[str, FitRun]]

The runs of every fit definition.

Raises:

Type Description
AssertionError

if a fit definition did not run.