experiment¶
The base class of the simulation experiments of a model.
The base of the experiments of a model derives from PKPDSimulationExperiment
and binds it to the model object; the experiments of the model derive from that
base:
# not executed
from sbmlsim import Q
class HctzSimulationExperiment(PKPDSimulationExperiment):
pkpd_model = MODEL
selections = ("time", "[Cve_hctz]", "Aurine_hctz")
Mr: ClassVar[MolecularWeights] = MolecularWeights(hctz=Q(297.74, "g/mole"))
The base simulates the model of the model object (models), the build of the
sex of the study (sex, the male build by default, the female build of a study
of women; simulation_sexes for a study with a group of each sex), creates a
task per simulation on the build of its sex (tasks), adds the selections to
every task (data), loads the digitized data of the study (load_dataframe) and has the classes of impaired
organ function (pkpdsim.impairment) and the labels of the pharmacokinetic
parameters (pkpdsim.pk) as defaults. A model overrides what it does
differently.
The keys of an experiment are SIds (sbmlsim checks them): sbmlsim.experiment.to_sid
gives the SId of a text, e.g. of a label of the data, and the method to_sid of the base
checks that no two texts of an experiment give the same SId. A unit which the
data use and sbmlsim does not define (an international unit is specific to a
substance) is defined under a name of the model and the substance, data_units
(sbmlsim.units.define_unit).
A run over the draws of the fitted parameters (run_simulation <package> --uncertainty)
gives every experiment the setting uncertainty, a
sbmlsim.experiment.draws.UncertaintyRun: the initialize of sbmlsim's
SimulationExperiment runs every simulation over the draws and turns the curves
of the simulations into bands (sbmlsim.experiment.draws.apply_uncertainty), so
an experiment needs no code of its own for it. A figure which an experiment draws
itself (figures_mpl) reads uncertainty and draws the bands of the draws, e.g.
with sbmlsim.result.scan.point_band(result, ..., across=self.across()); a
function of the results (add_function) is a band of the draws as well.
A dose after the first one adds to its dose state (add_doses): the rest of the
earlier doses which is not yet dissolved, absorbed or infused stays, which a
change of the dose state to the dose would discard (pkdb_models#105).
PKPDSimulationExperiment
¶
Bases: SimulationExperiment
The base of the simulation experiments of a model.
Attributes:
| Name | Type | Description |
|---|---|---|
pkpd_model |
PKPDModel
|
the model object of the model, set once in the base of its experiments. |
selections |
Sequence[str]
|
the selections of every task, see |
Mr |
Sequence[str]
|
the molecular weights of the substances, for the conversion of the
data (a |
labels |
Mapping[str, str]
|
the labels of the observables by id. |
units |
Mapping[str, str]
|
the units of the observables by id. |
renal_map |
Mapping[str, float]
|
the factor of the renal function by class. |
renal_colors |
Mapping[str, str]
|
the color of a class of the renal function. |
cirrhosis_map |
Mapping[str, float]
|
the degree of cirrhosis by class. |
cirrhosis_colors |
Mapping[str, str]
|
the color of a class of the cirrhosis. |
cardiac_map |
Mapping[str, float]
|
the factor of the cardiac output by class. |
cardiac_colors |
Mapping[str, str]
|
the color of a class of the cardiac function. |
pk_labels |
Mapping[str, str]
|
the label of a pharmacokinetic parameter. |
pk_units |
Mapping[str, str]
|
the unit of a pharmacokinetic parameter. |
data_units |
Mapping[str, str]
|
the units of the data which the experiment reads under a
name of its own, see |
sex |
Sex
|
the sex of the subjects of the study, the build of the model
object its simulations run ( |
simulation_sexes |
Mapping[str, Sex]
|
the sex of single simulations which differs from
|
Create the experiment, see SimulationExperiment.
The units of the data (data_units) are defined by initialize, so a
definition which is refused fails the initialization of this experiment,
which a run reports, and not the creation, which stops a run of sbmlsim
before any experiment ran.
Raises:
| Type | Description |
|---|---|
TypeError
|
if no base of the experiments sets |
initialize
¶
Define the units of the data and initialize the experiment.
The units of data_units are defined before the data are read, see
SimulationExperiment.initialize, which also runs the experiment over
the draws of its setting uncertainty.
Raises:
| Type | Description |
|---|---|
ValueError
|
for a definition of |
add_function
¶
Add a function of the results of a task over the time to a plot.
A curve of the line width of the curves of the selections (add_data,
2.0); in a run over the draws of the fitted parameters (uncertainty)
the band of the draws instead, with the quantiles of the run: the
function is no selection of a task, which the run makes a band of
itself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plot
|
Plot
|
the plot. |
required |
task_id
|
str
|
the task whose results the function reads. |
required |
y
|
Data
|
the function, a |
required |
label
|
str | None
|
the label of the curve or the band, |
required |
color
|
str
|
the color. |
required |
linestyle
|
str | None
|
the line style of the curve, |
'-'
|
data_unit_names
¶
Get the names of the units of the data, defining the units of data_units once.
The loaders rename the units of the data with these names; a table
which a model reads itself, e.g. the data of a figure of a scan, is
renamed with them by sbmlsim.data.rename_units. initialize calls it first; a call
without initialize defines the units on its first call.
Returns:
| Type | Description |
|---|---|
Mapping[str, str]
|
The name of a unit in the data -> the name of its definition, |
Mapping[str, str]
|
read-only. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a definition which |
to_sid
¶
Get the SId of a text as a key of the experiment, see sbmlsim.experiment.to_sid.
The keys of an experiment are unique across its datasets, simulations, tasks, figures and fit mappings, so two texts which give one SId in an experiment are an error: one entry would replace the other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the text, e.g. a label of the data. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The SId. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if another text of the experiment gave the same SId. |
sex_of
classmethod
¶
Get the sex of the subjects of a simulation: simulation_sexes, else sex.
A class method, since the sexes are declared: the class methods of an
experiment (the renal function of a group, pkpdsim.pbpk) resolve the
sex of a simulation by its key as well.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
str
|
the key of the simulation. |
required |
Returns:
| Type | Description |
|---|---|
Sex
|
The sex, whose build the simulation runs. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for a sex which is no |
variant_of
¶
Get the variant of the model a simulation runs on: the sex of its subjects.
The variants of a PKPDModel are the sexes, so pkpdsim-verify dump
stores the sex per task as builds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
str
|
the key of the simulation. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The value of the sex ( |
model_id
¶
Get the key of the build of a sex among the models of the experiment.
The build of sex is model, the model of an experiment without
builds per sex; the build of another sex is model_<sex>, e.g.
model_female in a study of men with a group of women.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sex
|
Sex
|
the sex. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The key of the model. |
models
¶
Get the builds of the model object which the experiment simulates.
The build of sex as model and the build of every other sex of
simulation_sexes as model_<sex> (model_id), without changes; a
model without builds per sex has the one model model. Only the builds
which the experiment simulates are loaded.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the model object has no build of a sex of the experiment, naming the experiment. |
tasks
¶
Get a task for every simulation, on the build of the sex of the simulation.
initialize creates the simulations before the tasks, so they are not
created a second time.
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
add_doses
¶
Get doses at times which add to their dose states.
A dose is given by its dose state, e.g. PODOSE_hctz, from which a
rate rule dissolves, absorbs or infuses it. A change of the dose state
to the dose (Change(times, {"PODOSE_hctz": Q(10, "mg")})) discards
what is left of the earlier doses; the change of this method adds the
dose ("PODOSE_hctz + 10.0", a formula in the unit of the dose state
in the model), so repeated doses keep the rest of the earlier ones. The
first dose is usually a change before the initialization
(preinit_changes), which may set the state. The models are loaded
before simulations(), where the doses are created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
float | Quantity | Sequence[float | Quantity]
|
the times of the doses, in the time unit of the simulation or quantities. |
required |
doses
|
Mapping[str, Quantity]
|
the dose state and the dose, e.g.
|
required |
model
|
str
|
the key of the model whose units the dose states have. |
'model'
|
Returns:
| Type | Description |
|---|---|
Change
|
The change of the dose states at the times. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the model is not loaded. |
default_changes
¶
Get the changes of every simulation of the experiments, none.
The parameters are part of the model and are not changed in the simulations: a parameter which is fitted must not be set by a simulation, it would override the value of the fit.
load_dataframe
¶
Load the digitized data of a figure or table of a study.
The units of the data are renamed (data_units, rename_units); the
geometric means get the unit of their row when the table is read as a
DataSet (DataSet.from_df).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig_id
|
str
|
the id of the figure or table in the study, e.g. |
required |
study
|
str | None
|
the study, the id of the experiment by default. |
None
|
na_values
|
Sequence[str] | Mapping[str, Sequence[str]] | None
|
additional strings of missing values, for every column or
by column, e.g. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if the experiment has no |
load_dataframes_by_substance
¶
Load the digitized data of a figure or table by substance.
The units of the data are renamed (data_units, rename_units). The rows without a
substance (a bile flow, a blood pressure) are in no frame, they are in
the table of load_dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig_id
|
str
|
the id of the figure or table in the study, e.g. |
required |
study
|
str | None
|
the study, the id of the experiment by default. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if the experiment has no |
figures_by_sid
staticmethod
¶
Get figures by their id, which every figure of the experiments has.
Raises:
| Type | Description |
|---|---|
ValueError
|
for a figure without an id. |