model¶
The description of a PBPK/PD model, which the commands of pkpdsim work with.
A model package defines one PKPDModel in its __init__.py, next to its path
constants:
# not executed
MODEL = PKPDModel(
name="hctz",
package=__name__,
title="HCTZ PBPK/PD model",
path=HCTZ_PATH,
model_path=MODEL_PATH,
data_paths=tuple(DATA_PATHS),
factory=".models.factory:create_hctz_models",
experiments=".simulations:EXPERIMENTS",
fit_definitions=".fitting.fitting:FIT_DEFINITIONS",
)
A PKPDModel is a sbmlsim.project.Project: the factory, the experiments, the
fit definitions and the credibility declaration are references
"module:attribute", resolved when they are used, the settings of the
simulator are the sbmlsim.project.SimulatorSettings, the known exceptions of
the tests the sbmlsim.project.CheckSettings and the release metadata the
sbmlsim.release.settings.ReleaseSettings of sbmlsim. The keywords of the
model packages (path, model_path, female_model_path, data_paths,
fit_definitions, fits, figures) are mapped
onto the fields of the project when a model is created, see PKPDModel; the
release settings of a model are a PKPDReleaseSettings, the ones of sbmlsim
with the framework pkpdsim and its release hook (pkpdsim.release.hook).
A model whose studies include women has a female build next to the male one
(female_model_path, the factory builds both from one definition, see
pkpdsim.pbpk.create_archive): the builds are the variants of the project by
the value of their pkpdsim.sex.Sex, the male build first, the model of every
caller which does not ask for a sex, and an experiment chooses the build of the
sex of its subjects (pkpdsim.experiment.PKPDSimulationExperiment.sex).
FigureSettings is the sbmlsim.plot.FigureSettings of sbmlsim with the
formats of the figures and the resolution of the static images, which a model
splits into the figure_settings and the figures of its project; the module
therefore imports sbmlsim's plotting.
PKPDReleaseSettings
dataclass
¶
PKPDReleaseSettings(
*,
framework="pkpdsim",
core_libraries=("pkpdsim", "sbmlsim", "sbmlutils"),
library_owner="matthiaskoenig",
hook="pkpdsim.release.hook:HOOK",
)
Bases: ReleaseSettings
The release settings of a model, ReleaseSettings with the defaults of pkpdsim.
The fields of sbmlsim.release.settings.ReleaseSettings; the release is
built with pkpdsim unless the model package gives another framework, so a
field which the package gives keeps its value, e.g. framework="sbmlsim".
The archive of the release is PKPDModel.archive_path.
Attributes:
| Name | Type | Description |
|---|---|---|
framework |
str
|
|
core_libraries |
Sequence[str]
|
|
library_owner |
str
|
|
hook |
object
|
the release hook of pkpdsim, |
FigureSettings
dataclass
¶
Bases: FigureSettings
The figures of the simulation experiments of a model.
The settings of sbmlsim's figures (sbmlsim.plot.FigureSettings: the
resolution, the sizes of the panels, the fonts and the legends, with the
defaults of sbmlsim) and what a model adds: the formats of the figures and
the resolution of the static images. A model splits them into the settings
of its figures (sbmlsim_settings, the figure_settings of the project)
and the files of its figures (outputs, the figures of the project).
The fields of sbmlsim can be given by position, as in sbmlsim; formats
and savefig_dpi only by keyword.
Attributes:
| Name | Type | Description |
|---|---|---|
formats |
Sequence[str]
|
the formats of the figures, images drawn by the renderer of
sbmlsim-core ( |
savefig_dpi |
float | None
|
the resolution of the PNG images, |
sbmlsim_settings
¶
Get the settings of sbmlsim, without the formats and the resolution.
A plain sbmlsim.plot.FigureSettings, which sbmlsim compares with its
defaults (a run with the defaults sets nothing).
ExtraAction
dataclass
¶
An action a model adds to its run command, e.g. analyses of its own.
All fields are keyword-only.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
the value of |
help |
str
|
what the action does, shown by |
function |
str
|
reference to the function which runs the action; it is called
with the model, the parsed arguments and the directory of the results.
The arguments have the settings of the simulator of the run as
|
in_all |
bool
|
run the action with |
ExtraActionFunction
dataclass
¶
An extra action of a model as the function of an action of its project.
The Project.actions of a model are its extra actions, so the kind
action of python -m sbmlsim.run runs them as well (see
sbmlsim.project.ActionFunction): the arguments of the spec are the
options of the action, over the defaults of the options of the model
(PKPDModel.extra_arguments), and the action gets the settings of the
simulator of the model as options.simulator, the processes of the run as
options.n_workers, no draws (options.uncertainty is None) and the
output of the run as its directory of the results.
Attributes:
| Name | Type | Description |
|---|---|---|
reference |
str
|
the reference to the function of the action,
|
PKPDModel
¶
Bases: Project
A PBPK/PD model: what the commands, the verification and the tests need.
A sbmlsim.project.Project with what pkpdsim adds: the COMBINE archive,
the builds per sex, the adopted fits, the directories of the results below
the package and the actions of the run command. The
keywords of the model packages are mapped onto the fields of the project
when a model is created from keywords:
path:root, the directory of the model package, the base path of its experiments (the propertypath).model_path,female_model_path: thevariantsmaleandfemale, the male build first: the model of every experiment and every caller which does not ask for a sex. The builds have the same ids, so a fit applies one parameter set to both, seemodel_paths.data_paths:data_path, the directories of the study data (the propertydata_paths).fit_definitions:fits, the reference to the fit problems by name (sbmlsim.fit.cli.FitDefinition).fitsas a sequence of fit ids:adopted_ids.figuresas aFigureSettings:figure_settingsandfigures(FigureSettings.sbmlsim_settings,FigureSettings.outputs).
The release settings (release) are a PKPDReleaseSettings, the release
settings of sbmlsim with the framework, the core libraries and the release
hook of pkpdsim as defaults, and archive_path is their archive.
A keyword and its field are not given together. A model is a frozen
pydantic model: replace gives a changed copy, by the names of the
fields.
Everything which compiles a model of the model does it at the optimization
level of its simulator settings; a model which names no level is created
with DEFAULT_JIT_OPTIMIZATION, the level of pkpdsim, unless
JIT_OPTIMIZATION_VARIABLE names one.
Attributes:
| Name | Type | Description |
|---|---|---|
archive_path |
Path | None
|
the COMBINE archive the factory creates, linked by the
|
results_path |
Path | None
|
the directory of the results, |
reduced_selections |
bool
|
simulate only the selections the experiments need. |
save_results |
bool
|
store the results of the simulations by default. |
fit_identifiability |
bool
|
the fit command analyses the identifiability of the fitted parameters by default. |
extra_actions |
tuple[ExtraAction, ...]
|
actions the model adds to its |
extra_arguments |
str | None
|
reference to a function which adds the options of the
extra actions to the parser of the |
adopted_ids |
tuple[str, ...]
|
the ids of the adopted fits, whose records in |
credibility_settings |
CredibilitySettings
|
the credibility settings of the project,
|
pipeline |
Any
|
the pipeline of the model, its commands in order, which
|
Create a model from the keywords of a model package or the fields.
The keywords of the model packages are mapped onto the fields of the project, see the class.
Raises:
| Type | Description |
|---|---|
ValidationError
|
for invalid keywords or fields. |
model_paths
property
¶
The builds of the model by sex, the male build first.
A model is built for one sex (the reference values of the PBPK library
are those of a sex, pkpdsim.pbpk.PBPKDefinition.sex); a model with a
female build has both, a model without one the male build only. The
builds have the same ids, so the changes of an experiment and the
parameters of a fit apply to both.
simulation_dir
property
¶
The directory of the results of the simulation experiments.
uncertainty_dir
property
¶
The directory of the results of the experiments over the draws of the fits.
identifiability_dir
property
¶
The directory of the identifiability analyses of stored parameters.
default_app
¶
Get the default web app of the model: its doses, diseases and scans.
See pkpdsim.webapp: pages of small panels of the readouts its
experiments compare with data, under the knobs of its doses and dosing
protocols, of the diseases it is studied in and of its other scans,
and the variants of the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sbml
|
Path
|
the SBML of the default variant, which the factory just wrote. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Panel], App | None]
|
The panels by their id and the app. |
default_variant_panels
¶
Get the default panels of the builds of the other sexes.
See pkpdsim.webapp.default_variant_panels: the classes of a renal
impairment at the healthy GFR of the build of each sex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
panels
|
Mapping[str, Panel]
|
the panels of |
required |
variants
|
Mapping[str, Path]
|
the SBML file of every variant, the default first. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Panel]]
|
The panels of a variant by its name and the id of the panel, only |
dict[str, dict[str, Panel]]
|
the panels which differ. |
replace
¶
Get a copy of the model with other fields, validated again.
See sbmlsim.project.Project.replace. A FigureSettings as figures
replaces the settings of the figures as well, figure_settings. A
copy with other builds (variants) or another root derives the
directory of the factory and the folder of the adopted fits again,
unless they are given or were not the derived ones: the directory of
the male build and fits next to the directory of the factory.
Raises:
| Type | Description |
|---|---|
ValidationError
|
for invalid fields. |
model_path_of
¶
Get the build of a sex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sex
|
Sex | str
|
the sex. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The SBML model of the sex. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the model has no build of the sex. |
load_roadrunner
¶
Load the build of a sex in roadrunner at the level of the model.
See sbmlsim.project.Project.load_roadrunner: the loader of the tests
of a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variant
|
str | None
|
the sex of the build ( |
None
|
Returns:
| Type | Description |
|---|---|
RoadRunner
|
The roadrunner instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the model has no build of the sex. |
adopted_fits
¶
Get the adopted fits by their subset, those of adopted_ids.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
The fit id by subset; the adopted fits of the file of the project |
dict[str, str]
|
for a model without |
Raises:
| Type | Description |
|---|---|
ValueError
|
if an adopted fit has no id of a fit, or two adopted fits are fits of one subset. |
load_pipeline
¶
Get the pipeline of the model, resolved.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the model has no pipeline. |
TypeError
|
if the pipeline is no |
load_credibility
¶
Get the declaration of the contexts of use.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the model has no declaration. |
TypeError
|
if the reference is no |
run_experiments
¶
run_experiments(
experiment_classes,
output_dir,
*,
save_results=None,
show_report=False,
figure_formats=None,
simulator=None,
n_workers=None,
scan_workers=RUN_WORKERS,
uncertainty=None,
)
Run simulation experiments and create their report.
The run of the model packages: Project.run_experiments with the
settings of the model, which returns the directory of the results and
resolves a relative directory below the results of the model. A run
with a failed experiment or figure raises
sbmlsim.experiment.ExperimentRunError after its report is written.
The messages of the run are shown on the rich console.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_classes
|
type[SimulationExperiment] | Sequence[type[SimulationExperiment]]
|
the experiment class or classes to run. |
required |
output_dir
|
str | Path
|
the directory of the results; a relative directory is
below |
required |
save_results
|
bool | None
|
store the results of the simulations, |
None
|
show_report
|
bool
|
open the report in a web browser. |
False
|
figure_formats
|
Sequence[str] | None
|
the formats of the figures, those of the model by default or when empty. |
None
|
simulator
|
SimulatorSettings | None
|
the settings of the simulator, those of the model by default. |
None
|
n_workers
|
int | None
|
the processes of the pool of the experiments, every
experiment with its scans in its worker; by default a worker
per four experiments, at most one per CPU, and serially below
( |
None
|
scan_workers
|
int | None
|
the processes of the scans of an experiment,
serially by default ( |
RUN_WORKERS
|
uncertainty
|
UncertaintySettings | None
|
run the experiments over the draws of the fitted
parameters of the model ( |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The directory of the results. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if |
ExperimentRunError
|
after the report is written, if an experiment or a figure failed. |
run_simulation_experiments
¶
run_simulation_experiments(
experiment_classes,
output_dir,
*,
show_report=False,
figure_formats=None,
simulator=None,
n_workers=None,
scan_workers=RUN_WORKERS,
uncertainty=None,
)
Run simulation experiments and collect their figures.
run_experiments which copies the static figures of every experiment
into sbmlsim.project.FIGURES_DIR of the output directory, also those
of a run with failures, before it raises.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_classes
|
Sequence[type[SimulationExperiment]]
|
the experiments to run. |
required |
output_dir
|
str | Path
|
the directory of the results, see |
required |
show_report
|
bool
|
open the report in a web browser. |
False
|
figure_formats
|
Sequence[str] | None
|
the formats of the figures, those of the model by default. |
None
|
simulator
|
SimulatorSettings | None
|
the settings of the simulator, those of the model by default. |
None
|
n_workers
|
int | None
|
the processes of the experiments, see |
None
|
scan_workers
|
int | None
|
the processes of the scans, see |
RUN_WORKERS
|
uncertainty
|
UncertaintySettings | None
|
run the experiments over the draws of the fitted
parameters, see |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The directory of the collected figures. |
Raises:
| Type | Description |
|---|---|
ExperimentRunError
|
after the figures are collected, if an experiment or a figure failed. |
sex¶
The sex of a model build.
A model is built for one sex: the PBPK library takes the reference values of
the sex when it builds a model (pkpdsim.pbpk.PBPKDefinition.sex, the ICRP 89
anatomy, the hematocrit, the partition coefficients, the GFR), so a study of
women runs on a female build and a study of men on a male one. The model
object holds a build per sex (pkpdsim.model.PKPDModel.model_paths, the male
build the default) and an experiment chooses one
(pkpdsim.experiment.PKPDSimulationExperiment.sex).
The module imports nothing else of pkpdsim, so that the model object and the library (which imports no simulator) share the enum.
Sex
¶
Bases: StrEnum
The sex of a model build, the sex of its reference individual.