Skip to content

Commit a621dd6

Browse files
committed
Merge branch 'develop' into object_model
2 parents 11917a0 + 98b0115 commit a621dd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+192
-135
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.4.0
5+
rev: v5.0.0
66
hooks:
77
- id: check-added-large-files
88
- id: check-merge-conflict
@@ -12,7 +12,7 @@ repos:
1212
- id: trailing-whitespace
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
1414
# Ruff version.
15-
rev: v0.1.11
15+
rev: v0.9.10
1616
hooks:
1717
# Run the linter.
1818
- id: ruff

doc/example/distributions.ipynb

Lines changed: 83 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"cells": [
33
{
4-
"metadata": {},
54
"cell_type": "markdown",
5+
"id": "372289411a2aa7b3",
6+
"metadata": {},
67
"source": [
78
"# Prior distributions in PEtab\n",
89
"\n",
@@ -18,14 +19,16 @@
1819
"* *Initialization priors* can be used as a hint for the optimization algorithm. They will not enter the objective function. They are specified in the `initializationPriorType` and `initializationPriorParameters` columns of the parameter table.\n",
1920
"\n",
2021
"\n"
21-
],
22-
"id": "372289411a2aa7b3"
22+
]
2323
},
2424
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"id": "initial_id",
2528
"metadata": {
2629
"collapsed": true
2730
},
28-
"cell_type": "code",
31+
"outputs": [],
2932
"source": [
3033
"import matplotlib.pyplot as plt\n",
3134
"import numpy as np\n",
@@ -45,143 +48,156 @@
4548
" sample = prior.sample(10000)\n",
4649
"\n",
4750
" # pdf\n",
48-
" xmin = min(sample.min(), prior.lb_scaled if prior.bounds is not None else sample.min())\n",
49-
" xmax = max(sample.max(), prior.ub_scaled if prior.bounds is not None else sample.max())\n",
51+
" xmin = min(\n",
52+
" sample.min(),\n",
53+
" prior.lb_scaled if prior.bounds is not None else sample.min(),\n",
54+
" )\n",
55+
" xmax = max(\n",
56+
" sample.max(),\n",
57+
" prior.ub_scaled if prior.bounds is not None else sample.max(),\n",
58+
" )\n",
5059
" x = np.linspace(xmin, xmax, 500)\n",
5160
" y = prior.pdf(x)\n",
52-
" ax.plot(x, y, color='red', label='pdf')\n",
61+
" ax.plot(x, y, color=\"red\", label=\"pdf\")\n",
5362
"\n",
54-
" sns.histplot(sample, stat='density', ax=ax, label=\"sample\")\n",
63+
" sns.histplot(sample, stat=\"density\", ax=ax, label=\"sample\")\n",
5564
"\n",
5665
" # bounds\n",
5766
" if prior.bounds is not None:\n",
5867
" for bound in (prior.lb_scaled, prior.ub_scaled):\n",
5968
" if bound is not None and np.isfinite(bound):\n",
60-
" ax.axvline(bound, color='black', linestyle='--', label='bound')\n",
69+
" ax.axvline(bound, color=\"black\", linestyle=\"--\", label=\"bound\")\n",
6170
"\n",
6271
" ax.set_title(str(prior))\n",
63-
" ax.set_xlabel('Parameter value on the parameter scale')\n",
72+
" ax.set_xlabel(\"Parameter value on the parameter scale\")\n",
6473
" ax.grid(False)\n",
6574
" handles, labels = ax.get_legend_handles_labels()\n",
66-
" unique_labels = dict(zip(labels, handles))\n",
75+
" unique_labels = dict(zip(labels, handles, strict=False))\n",
6776
" ax.legend(unique_labels.values(), unique_labels.keys())\n",
6877
" plt.show()"
69-
],
70-
"id": "initial_id",
71-
"outputs": [],
72-
"execution_count": null
78+
]
7379
},
7480
{
75-
"metadata": {},
7681
"cell_type": "markdown",
77-
"source": "The basic distributions are the uniform, normal, Laplace, log-normal, and log-laplace distributions:\n",
78-
"id": "db36a4a93622ccb8"
82+
"id": "db36a4a93622ccb8",
83+
"metadata": {},
84+
"source": "The basic distributions are the uniform, normal, Laplace, log-normal, and log-laplace distributions:\n"
7985
},
8086
{
81-
"metadata": {},
8287
"cell_type": "code",
88+
"execution_count": null,
89+
"id": "4f09e50a3db06d9f",
90+
"metadata": {},
91+
"outputs": [],
8392
"source": [
8493
"plot(Prior(UNIFORM, (0, 1)))\n",
8594
"plot(Prior(NORMAL, (0, 1)))\n",
8695
"plot(Prior(LAPLACE, (0, 1)))\n",
8796
"plot(Prior(LOG_NORMAL, (0, 1)))\n",
8897
"plot(Prior(LOG_LAPLACE, (1, 0.5)))"
89-
],
90-
"id": "4f09e50a3db06d9f",
91-
"outputs": [],
92-
"execution_count": null
98+
]
9399
},
94100
{
95-
"metadata": {},
96101
"cell_type": "markdown",
97-
"source": "If a parameter scale is specified (`parameterScale=lin|log|log10` not a `parameterScale*`-type distribution), the sample is transformed accordingly (but not the distribution parameters):\n",
98-
"id": "dab4b2d1e0f312d8"
102+
"id": "dab4b2d1e0f312d8",
103+
"metadata": {},
104+
"source": "If a parameter scale is specified (`parameterScale=lin|log|log10` not a `parameterScale*`-type distribution), the sample is transformed accordingly (but not the distribution parameters):\n"
99105
},
100106
{
101-
"metadata": {},
102107
"cell_type": "code",
108+
"execution_count": null,
109+
"id": "f6192c226f179ef9",
110+
"metadata": {},
111+
"outputs": [],
103112
"source": [
104113
"plot(Prior(NORMAL, (10, 2), transformation=LIN))\n",
105114
"plot(Prior(NORMAL, (10, 2), transformation=LOG))\n",
106115
"\n",
107-
"# Note that the log-normal distribution is different from a log-transformed normal distribution:\n",
116+
"# Note that the log-normal distribution is different\n",
117+
"# from a log-transformed normal distribution:\n",
108118
"plot(Prior(LOG_NORMAL, (10, 2), transformation=LIN))"
109-
],
110-
"id": "f6192c226f179ef9",
111-
"outputs": [],
112-
"execution_count": null
119+
]
113120
},
114121
{
115-
"metadata": {},
116122
"cell_type": "markdown",
117-
"source": "On the log-transformed parameter scale, `Log*` and `parameterScale*` distributions are equivalent:",
118-
"id": "4281ed48859e6431"
123+
"id": "4281ed48859e6431",
124+
"metadata": {},
125+
"source": "On the log-transformed parameter scale, `Log*` and `parameterScale*` distributions are equivalent:"
119126
},
120127
{
121-
"metadata": {},
122128
"cell_type": "code",
129+
"execution_count": null,
130+
"id": "34c95268e8921070",
131+
"metadata": {},
132+
"outputs": [],
123133
"source": [
124134
"plot(Prior(LOG_NORMAL, (10, 2), transformation=LOG))\n",
125135
"plot(Prior(PARAMETER_SCALE_NORMAL, (10, 2)))"
126-
],
127-
"id": "34c95268e8921070",
128-
"outputs": [],
129-
"execution_count": null
136+
]
130137
},
131138
{
132-
"metadata": {},
133139
"cell_type": "markdown",
134-
"source": "Prior distributions can also be defined on the parameter scale by using the types `parameterScaleUniform`, `parameterScaleNormal` or `parameterScaleLaplace`. In these cases, 1) the distribution parameter are interpreted on the transformed parameter scale, and 2) a sample from the given distribution is used directly, without applying any transformation according to `parameterScale` (this implies, that for `parameterScale=lin`, there is no difference between `parameterScaleUniform` and `uniform`):",
135-
"id": "263c9fd31156a4d5"
140+
"id": "263c9fd31156a4d5",
141+
"metadata": {},
142+
"source": "Prior distributions can also be defined on the parameter scale by using the types `parameterScaleUniform`, `parameterScaleNormal` or `parameterScaleLaplace`. In these cases, 1) the distribution parameter are interpreted on the transformed parameter scale, and 2) a sample from the given distribution is used directly, without applying any transformation according to `parameterScale` (this implies, that for `parameterScale=lin`, there is no difference between `parameterScaleUniform` and `uniform`):"
136143
},
137144
{
138-
"metadata": {},
139145
"cell_type": "code",
146+
"execution_count": null,
147+
"id": "5ca940bc24312fc6",
148+
"metadata": {},
149+
"outputs": [],
140150
"source": [
141151
"plot(Prior(UNIFORM, (0.01, 2), transformation=LOG10))\n",
142152
"plot(Prior(PARAMETER_SCALE_UNIFORM, (0.01, 2), transformation=LOG10))\n",
143153
"\n",
144154
"plot(Prior(UNIFORM, (0.01, 2), transformation=LIN))\n",
145-
"plot(Prior(PARAMETER_SCALE_UNIFORM, (0.01, 2), transformation=LIN))\n"
146-
],
147-
"id": "5ca940bc24312fc6",
148-
"outputs": [],
149-
"execution_count": null
155+
"plot(Prior(PARAMETER_SCALE_UNIFORM, (0.01, 2), transformation=LIN))"
156+
]
150157
},
151158
{
152-
"metadata": {},
153159
"cell_type": "markdown",
154-
"source": "To prevent the sampled parameters from exceeding the bounds, the sampled parameters are clipped to the bounds. The bounds are defined in the parameter table. Note that the current implementation does not support sampling from a truncated distribution. Instead, the samples are clipped to the bounds. This may introduce unwanted bias, and thus, should only be used with caution (i.e., the bounds should be chosen wide enough):",
155-
"id": "b1a8b17d765db826"
160+
"id": "b1a8b17d765db826",
161+
"metadata": {},
162+
"source": "To prevent the sampled parameters from exceeding the bounds, the sampled parameters are clipped to the bounds. The bounds are defined in the parameter table. Note that the current implementation does not support sampling from a truncated distribution. Instead, the samples are clipped to the bounds. This may introduce unwanted bias, and thus, should only be used with caution (i.e., the bounds should be chosen wide enough):"
156163
},
157164
{
158-
"metadata": {},
159165
"cell_type": "code",
160-
"source": [
161-
"plot(Prior(NORMAL, (0, 1), bounds=(-4, 4))) # negligible clipping-bias at 4 sigma\n",
162-
"plot(Prior(UNIFORM, (0, 1), bounds=(0.1, 0.9))) # significant clipping-bias"
163-
],
166+
"execution_count": null,
164167
"id": "4ac42b1eed759bdd",
168+
"metadata": {},
165169
"outputs": [],
166-
"execution_count": null
170+
"source": [
171+
"plot(\n",
172+
" Prior(NORMAL, (0, 1), bounds=(-4, 4))\n",
173+
") # negligible clipping-bias at 4 sigma\n",
174+
"plot(Prior(UNIFORM, (0, 1), bounds=(0.1, 0.9))) # significant clipping-bias"
175+
]
167176
},
168177
{
169-
"metadata": {},
170178
"cell_type": "markdown",
171-
"source": "Further distribution examples:",
172-
"id": "45ffce1341483f24"
179+
"id": "45ffce1341483f24",
180+
"metadata": {},
181+
"source": "Further distribution examples:"
173182
},
174183
{
175-
"metadata": {},
176184
"cell_type": "code",
185+
"execution_count": null,
186+
"id": "581e1ac431860419",
187+
"metadata": {},
188+
"outputs": [],
177189
"source": [
178190
"plot(Prior(NORMAL, (10, 1), bounds=(6, 14), transformation=\"log10\"))\n",
179-
"plot(Prior(PARAMETER_SCALE_NORMAL, (10, 1), bounds=(10**6, 10**14), transformation=\"log10\"))\n",
191+
"plot(\n",
192+
" Prior(\n",
193+
" PARAMETER_SCALE_NORMAL,\n",
194+
" (10, 1),\n",
195+
" bounds=(10**6, 10**14),\n",
196+
" transformation=\"log10\",\n",
197+
" )\n",
198+
")\n",
180199
"plot(Prior(LAPLACE, (10, 2), bounds=(6, 14)))"
181-
],
182-
"id": "581e1ac431860419",
183-
"outputs": [],
184-
"execution_count": null
200+
]
185201
}
186202
],
187203
"metadata": {

petab/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
PEtab should use for operations that can be performed in parallel.
99
By default, all operations are performed sequentially.
1010
"""
11+
1112
import importlib
1213
import sys
1314
from functools import partial

petab/petablint.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def main():
161161
validate(args.yaml_file_name)
162162
except SchemaValidationError as e:
163163
logger.error(
164-
"Provided YAML file does not adhere to PEtab " f"schema: {e}"
164+
f"Provided YAML file does not adhere to PEtab schema: {e}"
165165
)
166166
sys.exit(1)
167167

@@ -205,9 +205,7 @@ def main():
205205
if args.parameter_file_name:
206206
logger.debug(f"\tParameter table: {args.parameter_file_name}")
207207
if args.visualization_file_name:
208-
logger.debug(
209-
"\tVisualization table: " f"{args.visualization_file_name}"
210-
)
208+
logger.debug(f"\tVisualization table: {args.visualization_file_name}")
211209

212210
try:
213211
problem = petab.Problem.from_files(

petab/v1/C.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
This file contains constant definitions.
44
"""
5+
56
import math as _math
67
import sys
78

petab/v1/composite_problem.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""PEtab problems consisting of multiple models"""
2+
23
import os
34

45
import pandas as pd

petab/v1/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""PEtab core functions (or functions that don't fit anywhere else)"""
2+
23
import logging
34
import os
45
import re

petab/v1/distributions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Probability distributions used by PEtab."""
2+
23
from __future__ import annotations
34

45
import abc

petab/v1/format_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
"""PEtab file format version"""
2+
23
__format_version__ = 1

petab/v1/lint.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ def check_parameter_bounds(parameter_df: pd.DataFrame) -> None:
556556
] in [LOG, LOG10]:
557557
raise AssertionError(
558558
f"Bounds for {row[PARAMETER_SCALE]} scaled parameter "
559-
f"{ row.name} must be positive."
559+
f"{row.name} must be positive."
560560
)
561561
if (
562562
row.get(PARAMETER_SCALE, LIN) in [LOG, LOG10]
@@ -586,8 +586,7 @@ def assert_parameter_prior_type_is_valid(parameter_df: pd.DataFrame) -> None:
586586
for _, row in parameter_df.iterrows():
587587
if row[col] not in PRIOR_TYPES and not core.is_empty(row[col]):
588588
raise AssertionError(
589-
f"{col} must be one of {PRIOR_TYPES} but is "
590-
f"'{row[col]}'."
589+
f"{col} must be one of {PRIOR_TYPES} but is '{row[col]}'."
591590
)
592591

593592

@@ -945,7 +944,7 @@ def lint_problem(problem: "petab.Problem") -> bool:
945944
for obs_id in problem.observable_df.index:
946945
if problem.model.has_entity_with_id(obs_id):
947946
logger.error(
948-
f"Observable ID {obs_id} shadows model " "entity."
947+
f"Observable ID {obs_id} shadows model entity."
949948
)
950949
errors_occurred = True
951950
else:
@@ -1002,8 +1001,7 @@ def lint_problem(problem: "petab.Problem") -> bool:
10021001
or problem.observable_df is None
10031002
):
10041003
logger.warning(
1005-
"Not all files of the PEtab problem definition could "
1006-
"be checked."
1004+
"Not all files of the PEtab problem definition could be checked."
10071005
)
10081006
else:
10091007
logger.info("PEtab format check completed successfully.")
@@ -1213,7 +1211,7 @@ def check_ids(ids: Iterable[str], kind: str = "") -> None:
12131211
offset = 2
12141212
error_output = "\n".join(
12151213
[
1216-
f"Line {index+offset}: "
1214+
f"Line {index + offset}: "
12171215
+ ("Missing ID" if pd.isna(_id) else _id)
12181216
for index, _id in invalids
12191217
]

0 commit comments

Comments
 (0)