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, the checks of the battery which fail) 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
¶
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
¶
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
¶
Get the experiments of the group all of the registry of a model.
check_registry
¶
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 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>),
the builds (model_path, female_model_path), the factory directory and
archive_path lie below path,
the data paths exist, and every parameter of an adopted fit has its value
and a distribution in the model (pkpdsim.uncertainty.check_fit_parameters).
Raises:
| Type | Description |
|---|---|
AssertionError
|
naming every problem. |
initialize_experiments
¶
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 the registered experiments, as run_simulation 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
|
required |
Raises:
| Type | Description |
|---|---|
AssertionError
|
naming every failed experiment and figure, and every run which wrote no report. |
check_battery
¶
Run the battery of the checks of the builds of a model.
A failed check is a problem unless the model knows it
(CheckSettings.battery); a known failure whose check passes or is not
applicable no longer applies and is a problem as well.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PKPDModel
|
the model. |
required |
rebuild
|
bool
|
rebuild the model with its factory. |
True
|
cross_simulator
|
bool
|
compare the builds with AMICI when it is installed,
see |
True
|
Returns:
| Type | Description |
|---|---|
Battery
|
The battery. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
naming every problem. |
start_fits
¶
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. |