Skip to content

Commit 51367db

Browse files
committed
reruff
1 parent b762237 commit 51367db

Some content is hidden

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

64 files changed

+208
-141
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: 99 additions & 72 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,23 +19,24 @@
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",
3235
"import seaborn as sns\n",
3336
"\n",
3437
"from petab.v1.C import *\n",
38+
"from petab.v1.parameters import unscale\n",
3539
"from petab.v1.priors import Prior\n",
36-
"from petab.v1.parameters import scale, unscale\n",
37-
"\n",
3840
"\n",
3941
"sns.set_style(None)\n",
4042
"\n",
@@ -51,7 +53,10 @@
5153
" plt.tight_layout()\n",
5254
" plt.show()\n",
5355
"\n",
54-
"def plot_single(prior: Prior, scaled: bool = False, ax=None, sample: np.array = None):\n",
56+
"\n",
57+
"def plot_single(\n",
58+
" prior: Prior, scaled: bool = False, ax=None, sample: np.array = None\n",
59+
"):\n",
5560
" fig = None\n",
5661
" if ax is None:\n",
5762
" fig, ax = plt.subplots()\n",
@@ -64,113 +69,124 @@
6469
" sample = unscale(sample, prior.transformation)\n",
6570
" bounds = prior.bounds\n",
6671
" else:\n",
67-
" bounds = (prior.lb_scaled, prior.ub_scaled) if prior.bounds is not None else None\n",
72+
" bounds = (\n",
73+
" (prior.lb_scaled, prior.ub_scaled)\n",
74+
" if prior.bounds is not None\n",
75+
" else None\n",
76+
" )\n",
6877
"\n",
6978
" # plot pdf\n",
70-
" xmin = min(sample.min(), bounds[0] if prior.bounds is not None else sample.min())\n",
71-
" xmax = max(sample.max(), bounds[1] if prior.bounds is not None else sample.max())\n",
79+
" xmin = min(\n",
80+
" sample.min(), bounds[0] if prior.bounds is not None else sample.min()\n",
81+
" )\n",
82+
" xmax = max(\n",
83+
" sample.max(), bounds[1] if prior.bounds is not None else sample.max()\n",
84+
" )\n",
7285
" padding = 0.1 * (xmax - xmin)\n",
7386
" xmin -= padding\n",
7487
" xmax += padding\n",
7588
" x = np.linspace(xmin, xmax, 500)\n",
7689
" y = prior.pdf(x, x_scaled=scaled, rescale=scaled)\n",
77-
" ax.plot(x, y, color='red', label='pdf')\n",
90+
" ax.plot(x, y, color=\"red\", label=\"pdf\")\n",
7891
"\n",
79-
" sns.histplot(sample, stat='density', ax=ax, label=\"sample\")\n",
92+
" sns.histplot(sample, stat=\"density\", ax=ax, label=\"sample\")\n",
8093
"\n",
8194
" # plot bounds\n",
8295
" if prior.bounds is not None:\n",
8396
" for bound in bounds:\n",
8497
" if bound is not None and np.isfinite(bound):\n",
85-
" ax.axvline(bound, color='black', linestyle='--', label='bound')\n",
98+
" ax.axvline(bound, color=\"black\", linestyle=\"--\", label=\"bound\")\n",
8699
"\n",
87100
" if fig is not None:\n",
88101
" ax.set_title(str(prior))\n",
89102
"\n",
90103
" if scaled:\n",
91-
" ax.set_xlabel(f'Parameter value on parameter scale ({prior.transformation})')\n",
104+
" ax.set_xlabel(\n",
105+
" f\"Parameter value on parameter scale ({prior.transformation})\"\n",
106+
" )\n",
92107
" ax.set_ylabel(\"Rescaled density\")\n",
93108
" else:\n",
94-
" ax.set_xlabel('Parameter value')\n",
109+
" ax.set_xlabel(\"Parameter value\")\n",
95110
"\n",
96111
" ax.grid(False)\n",
97112
" handles, labels = ax.get_legend_handles_labels()\n",
98-
" unique_labels = dict(zip(labels, handles))\n",
113+
" unique_labels = dict(zip(labels, handles, strict=False))\n",
99114
" ax.legend(unique_labels.values(), unique_labels.keys())\n",
100115
"\n",
101116
" if ax is None:\n",
102-
" plt.show()\n"
103-
],
104-
"id": "initial_id",
105-
"outputs": [],
106-
"execution_count": null
117+
" plt.show()"
118+
]
107119
},
108120
{
109-
"metadata": {},
110121
"cell_type": "markdown",
111-
"source": "The basic distributions are the uniform, normal, Laplace, log-normal, and log-laplace distributions:\n",
112-
"id": "db36a4a93622ccb8"
122+
"id": "db36a4a93622ccb8",
123+
"metadata": {},
124+
"source": "The basic distributions are the uniform, normal, Laplace, log-normal, and log-laplace distributions:\n"
113125
},
114126
{
115-
"metadata": {},
116127
"cell_type": "code",
128+
"execution_count": null,
129+
"id": "4f09e50a3db06d9f",
130+
"metadata": {},
131+
"outputs": [],
117132
"source": [
118133
"plot_single(Prior(UNIFORM, (0, 1)))\n",
119134
"plot_single(Prior(NORMAL, (0, 1)))\n",
120135
"plot_single(Prior(LAPLACE, (0, 1)))\n",
121136
"plot_single(Prior(LOG_NORMAL, (0, 1)))\n",
122137
"plot_single(Prior(LOG_LAPLACE, (1, 0.5)))"
123-
],
124-
"id": "4f09e50a3db06d9f",
125-
"outputs": [],
126-
"execution_count": null
138+
]
127139
},
128140
{
129-
"metadata": {},
130141
"cell_type": "markdown",
131-
"source": "If a parameter scale is specified (`parameterScale=lin|log|log10`) and the chosen distribution is not a `parameterScale*`-type distribution, then the distribution parameters are taken as is, i.e., the `parameterScale` is not applied to the distribution parameters. In the context of PEtab prior distributions, `parameterScale` will only be used for the start point sampling for optimization, where the sample will be transformed accordingly. This is demonstrated below. The left plot always shows the prior distribution for unscaled parameter values, and the right plot shows the prior distribution for scaled parameter values. Note that in the objective function, the prior is always on the unscaled parameters.\n",
132-
"id": "dab4b2d1e0f312d8"
142+
"id": "dab4b2d1e0f312d8",
143+
"metadata": {},
144+
"source": "If a parameter scale is specified (`parameterScale=lin|log|log10`) and the chosen distribution is not a `parameterScale*`-type distribution, then the distribution parameters are taken as is, i.e., the `parameterScale` is not applied to the distribution parameters. In the context of PEtab prior distributions, `parameterScale` will only be used for the start point sampling for optimization, where the sample will be transformed accordingly. This is demonstrated below. The left plot always shows the prior distribution for unscaled parameter values, and the right plot shows the prior distribution for scaled parameter values. Note that in the objective function, the prior is always on the unscaled parameters.\n"
133145
},
134146
{
135-
"metadata": {},
136147
"cell_type": "code",
148+
"execution_count": null,
149+
"id": "f6192c226f179ef9",
150+
"metadata": {},
151+
"outputs": [],
137152
"source": [
138153
"plot(Prior(NORMAL, (10, 2), transformation=LIN))\n",
139154
"plot(Prior(NORMAL, (10, 2), transformation=LOG))\n",
140155
"\n",
141-
"# Note that the log-normal distribution is different from a log-transformed normal distribution:\n",
156+
"# Note that the log-normal distribution is different\n",
157+
"# from a log-transformed normal distribution:\n",
142158
"plot(Prior(LOG_NORMAL, (10, 2), transformation=LIN))"
143-
],
144-
"id": "f6192c226f179ef9",
145-
"outputs": [],
146-
"execution_count": null
159+
]
147160
},
148161
{
149-
"metadata": {},
150162
"cell_type": "markdown",
151-
"source": "On the log-transformed parameter scale, `Log*` and `parameterScale*` distributions are equivalent:",
152-
"id": "4281ed48859e6431"
163+
"id": "4281ed48859e6431",
164+
"metadata": {},
165+
"source": "On the log-transformed parameter scale, `Log*` and `parameterScale*` distributions are equivalent:"
153166
},
154167
{
155-
"metadata": {},
156168
"cell_type": "code",
169+
"execution_count": null,
170+
"id": "34c95268e8921070",
171+
"metadata": {},
172+
"outputs": [],
157173
"source": [
158174
"plot(Prior(LOG_NORMAL, (10, 2), transformation=LOG))\n",
159175
"plot(Prior(PARAMETER_SCALE_NORMAL, (10, 2)))"
160-
],
161-
"id": "34c95268e8921070",
162-
"outputs": [],
163-
"execution_count": null
176+
]
164177
},
165178
{
166-
"metadata": {},
167179
"cell_type": "markdown",
168-
"source": "Prior distributions can also be defined on the scaled parameters (i.e., transformed according to `parameterScale`) by using the types `parameterScaleUniform`, `parameterScaleNormal` or `parameterScaleLaplace`. In these cases, the distribution parameters are interpreted on the transformed parameter scale (but not the parameter bounds, see below). This implies, that for `parameterScale=lin`, there is no difference between `parameterScaleUniform` and `uniform`.",
169-
"id": "263c9fd31156a4d5"
180+
"id": "263c9fd31156a4d5",
181+
"metadata": {},
182+
"source": "Prior distributions can also be defined on the scaled parameters (i.e., transformed according to `parameterScale`) by using the types `parameterScaleUniform`, `parameterScaleNormal` or `parameterScaleLaplace`. In these cases, the distribution parameters are interpreted on the transformed parameter scale (but not the parameter bounds, see below). This implies, that for `parameterScale=lin`, there is no difference between `parameterScaleUniform` and `uniform`."
170183
},
171184
{
172-
"metadata": {},
173185
"cell_type": "code",
186+
"execution_count": null,
187+
"id": "5ca940bc24312fc6",
188+
"metadata": {},
189+
"outputs": [],
174190
"source": [
175191
"# different, because transformation!=LIN\n",
176192
"plot(Prior(UNIFORM, (0.01, 2), transformation=LOG10))\n",
@@ -179,50 +195,61 @@
179195
"# same, because transformation=LIN\n",
180196
"plot(Prior(UNIFORM, (0.01, 2), transformation=LIN))\n",
181197
"plot(Prior(PARAMETER_SCALE_UNIFORM, (0.01, 2), transformation=LIN))"
182-
],
183-
"id": "5ca940bc24312fc6",
184-
"outputs": [],
185-
"execution_count": null
198+
]
186199
},
187200
{
188-
"metadata": {},
189201
"cell_type": "markdown",
190-
"source": "The given distributions are truncated at the bounds defined in the parameter table:",
191-
"id": "b1a8b17d765db826"
202+
"id": "b1a8b17d765db826",
203+
"metadata": {},
204+
"source": "The given distributions are truncated at the bounds defined in the parameter table:"
192205
},
193206
{
194-
"metadata": {},
195207
"cell_type": "code",
208+
"execution_count": null,
209+
"id": "4ac42b1eed759bdd",
210+
"metadata": {},
211+
"outputs": [],
196212
"source": [
197213
"plot(Prior(NORMAL, (0, 1), bounds=(-2, 2)))\n",
198214
"plot(Prior(UNIFORM, (0, 1), bounds=(0.1, 0.9)))\n",
199215
"plot(Prior(UNIFORM, (1e-8, 1), bounds=(0.1, 0.9), transformation=LOG10))\n",
200216
"plot(Prior(LAPLACE, (0, 1), bounds=(-0.5, 0.5)))\n",
201-
"plot(Prior(PARAMETER_SCALE_UNIFORM, (-3, 1), bounds=(1e-2, 1), transformation=LOG10))"
202-
],
203-
"id": "4ac42b1eed759bdd",
204-
"outputs": [],
205-
"execution_count": null
217+
"plot(\n",
218+
" Prior(\n",
219+
" PARAMETER_SCALE_UNIFORM,\n",
220+
" (-3, 1),\n",
221+
" bounds=(1e-2, 1),\n",
222+
" transformation=LOG10,\n",
223+
" )\n",
224+
")"
225+
]
206226
},
207227
{
208-
"metadata": {},
209228
"cell_type": "markdown",
210-
"source": "Further distribution examples:",
211-
"id": "45ffce1341483f24"
229+
"id": "45ffce1341483f24",
230+
"metadata": {},
231+
"source": "Further distribution examples:"
212232
},
213233
{
214-
"metadata": {},
215234
"cell_type": "code",
235+
"execution_count": null,
236+
"id": "581e1ac431860419",
237+
"metadata": {},
238+
"outputs": [],
216239
"source": [
217240
"plot(Prior(NORMAL, (10, 1), bounds=(6, 11), transformation=\"log10\"))\n",
218-
"plot(Prior(PARAMETER_SCALE_NORMAL, (2, 1), bounds=(10**0, 10**3), transformation=\"log10\"))\n",
241+
"plot(\n",
242+
" Prior(\n",
243+
" PARAMETER_SCALE_NORMAL,\n",
244+
" (2, 1),\n",
245+
" bounds=(10**0, 10**3),\n",
246+
" transformation=\"log10\",\n",
247+
" )\n",
248+
")\n",
219249
"plot(Prior(LAPLACE, (10, 2), bounds=(6, 14)))\n",
220250
"plot(Prior(LOG_LAPLACE, (1, 0.5), bounds=(0.5, 8)))\n",
221251
"plot(Prior(LOG_NORMAL, (2, 1), bounds=(0.5, 8)))"
222-
],
223-
"id": "581e1ac431860419",
224-
"outputs": [],
225-
"execution_count": null
252+
]
226253
}
227254
],
228255
"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

0 commit comments

Comments
 (0)