Skip to content

Commit 57f5ed5

Browse files
authored
pre-commit autoupdate (#2635)
* pre-commit autoupdate * pre-commit autoupdate `pre-commit autoupdate` and fix/ignore pyupgrade issues.
1 parent 92a530b commit 57f5ed5

File tree

18 files changed

+139
-164
lines changed

18 files changed

+139
-164
lines changed

.pre-commit-config.yaml

+3-3
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.6.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.6.7
15+
rev: v0.8.6
1616
hooks:
1717
# Run the linter.
1818
- id: ruff
@@ -28,7 +28,7 @@ repos:
2828
- python/sdist/pyproject.toml
2929

3030
- repo: https://github.com/asottile/pyupgrade
31-
rev: v3.17.0
31+
rev: v3.19.1
3232
hooks:
3333
- id: pyupgrade
3434
args: ["--py310-plus"]

python/examples/example_constant_species/ExampleEquilibrationLogic.ipynb

+14-16
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@
124124
"for reaction in sbml_model.getListOfReactions():\n",
125125
" reactants = \" + \".join(\n",
126126
" [\n",
127-
" \"%s %s\"\n",
128-
" % (\n",
127+
" \"{} {}\".format(\n",
129128
" int(r.getStoichiometry()) if r.getStoichiometry() > 1 else \"\",\n",
130129
" r.getSpecies(),\n",
131130
" )\n",
@@ -134,8 +133,7 @@
134133
" )\n",
135134
" products = \" + \".join(\n",
136135
" [\n",
137-
" \"%s %s\"\n",
138-
" % (\n",
136+
" \"{} {}\".format(\n",
139137
" int(r.getStoichiometry()) if r.getStoichiometry() > 1 else \"\",\n",
140138
" r.getSpecies(),\n",
141139
" )\n",
@@ -144,7 +142,7 @@
144142
" )\n",
145143
" reversible = \"<\" if reaction.getReversible() else \"\"\n",
146144
" print(\n",
147-
" \"%3s: %10s %1s->%10s\\t\\t[%s]\"\n",
145+
" \"%3s: %10s %1s->%10s\\t\\t[%s]\" # noqa: UP031\n",
148146
" % (\n",
149147
" reaction.getId(),\n",
150148
" reactants,\n",
@@ -370,7 +368,7 @@
370368
"\n",
371369
"# np.set_printoptions(threshold=8, edgeitems=2)\n",
372370
"for key, value in rdata.items():\n",
373-
" print(\"%12s: \" % key, value)"
371+
" print(f\"{key:12s}: \", value)"
374372
]
375373
},
376374
{
@@ -664,15 +662,15 @@
664662
"Since the Eigenvalues of the Jacobian are negative and since the Jacobian at steady state is a fixed matrix, this system has a simple algebraic solution:\n",
665663
"\n",
666664
" $$p(t) = e^{t J(x^*, \\theta)^T} p_{\\text{end}}.$$\n",
667-
" \n",
665+
"\n",
668666
"As a consequence, the quadratures in adjoint computation also reduce to a matrix-vector product:\n",
669667
"\n",
670668
" $$Q(x, \\theta) = Q(x^*, \\theta) = p_{\\text{integral}} * \\frac{\\partial f}{\\partial \\theta}$$\n",
671669
"\n",
672670
"with\n",
673671
"\n",
674-
" $$p_{\\text{integral}} = \\int_0^\\infty p(s) ds = (J(x^*, \\theta)^T)^{-1} p_{\\text{end}}.$$ \n",
675-
" \n",
672+
" $$p_{\\text{integral}} = \\int_0^\\infty p(s) ds = (J(x^*, \\theta)^T)^{-1} p_{\\text{end}}.$$\n",
673+
"\n",
676674
"However, this solution is given in terms of a linear system of equations defined by the transposed Jacobian of the right hand side. Hence, if the (transposed) Jacobian is singular, it is not applicable.\n",
677675
"In this case, standard integration must be carried out."
678676
]
@@ -922,7 +920,7 @@
922920
"\n",
923921
"for key, value in rdata.items():\n",
924922
" if key[0:6] == \"preeq_\":\n",
925-
" print(\"%20s: \" % key, value)"
923+
" print(f\"{key:20s}:\", value)"
926924
]
927925
},
928926
{
@@ -960,7 +958,7 @@
960958
"\n",
961959
"for key, value in rdata.items():\n",
962960
" if key[0:6] == \"preeq_\":\n",
963-
" print(\"%20s: \" % key, value)"
961+
" print(f\"{key:20s}:\", value)"
964962
]
965963
},
966964
{
@@ -993,7 +991,7 @@
993991
"\n",
994992
"for key, value in rdata_reduced.items():\n",
995993
" if key[0:6] == \"preeq_\":\n",
996-
" print(\"%20s: \" % key, value)"
994+
" print(f\"{key:20s}:\", value)"
997995
]
998996
},
999997
{
@@ -1044,7 +1042,7 @@
10441042
"\n",
10451043
"for key, value in rdata_reduced.items():\n",
10461044
" if key[0:6] == \"preeq_\":\n",
1047-
" print(\"%20s: \" % key, value)\n",
1045+
" print(f\"{key:20s}:\", value)\n",
10481046
"print(\"Gradient:\", rdata_reduced[\"sllh\"])"
10491047
]
10501048
},
@@ -1079,7 +1077,7 @@
10791077
"\n",
10801078
"for key, value in rdata_reduced.items():\n",
10811079
" if key[0:6] == \"preeq_\":\n",
1082-
" print(\"%20s: \" % key, value)\n",
1080+
" print(f\"{key:20s}:\", value)\n",
10831081
"print(\"Gradient:\", rdata_reduced[\"sllh\"])"
10841082
]
10851083
},
@@ -1117,7 +1115,7 @@
11171115
"\n",
11181116
"for key, value in rdata_reduced.items():\n",
11191117
" if key[0:6] == \"preeq_\":\n",
1120-
" print(\"%20s: \" % key, value)\n",
1118+
" print(f\"{key:20s}:\", value)\n",
11211119
"print(\"Gradient:\", rdata_reduced[\"sllh\"])"
11221120
]
11231121
},
@@ -1160,7 +1158,7 @@
11601158
"\n",
11611159
"for key, value in rdata.items():\n",
11621160
" if key[0:6] == \"preeq_\":\n",
1163-
" print(\"%20s: \" % key, value)\n",
1161+
" print(f\"{key:20s}:\", value)\n",
11641162
"print(\"Gradient:\", rdata[\"sllh\"])"
11651163
]
11661164
},

python/examples/example_errors.ipynb

+2-6
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@
7676
"outputs": [],
7777
"source": [
7878
"petab_problem = benchmark_models_petab.get_problem(\"Fujita_SciSignal2010\")\n",
79-
"amici_model = import_petab_problem(\n",
80-
" petab_problem, verbose=False, compile_=None\n",
81-
")\n",
79+
"amici_model = import_petab_problem(petab_problem, verbose=False, compile_=None)\n",
8280
"\n",
8381
"np.random.seed(2991)\n",
8482
"problem_parameters = dict(\n",
@@ -422,9 +420,7 @@
422420
"outputs": [],
423421
"source": [
424422
"petab_problem = benchmark_models_petab.get_problem(\"Weber_BMC2015\")\n",
425-
"amici_model = import_petab_problem(\n",
426-
" petab_problem, verbose=False, compile_=None\n",
427-
")\n",
423+
"amici_model = import_petab_problem(petab_problem, verbose=False, compile_=None)\n",
428424
"\n",
429425
"np.random.seed(4)\n",
430426
"problem_parameters = dict(\n",

python/examples/example_petab/petab.ipynb

+26-24
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
},
2929
{
3030
"cell_type": "markdown",
31-
"source": [
32-
"## Importing a PEtab problem"
33-
],
3431
"metadata": {
3532
"collapsed": false
36-
}
33+
},
34+
"source": [
35+
"## Importing a PEtab problem"
36+
]
3737
},
3838
{
3939
"cell_type": "markdown",
@@ -134,6 +134,10 @@
134134
},
135135
{
136136
"cell_type": "code",
137+
"execution_count": null,
138+
"metadata": {
139+
"collapsed": false
140+
},
137141
"outputs": [],
138142
"source": [
139143
"app = PetabProblem(petab_problem)\n",
@@ -143,43 +147,41 @@
143147
"\n",
144148
"# ExpData for a single condition:\n",
145149
"edata = app.get_edata(\"model1_data1\")"
146-
],
147-
"metadata": {
148-
"collapsed": false
149-
},
150-
"execution_count": null
150+
]
151151
},
152152
{
153153
"cell_type": "code",
154-
"outputs": [],
155-
"source": [
156-
"rdata = runAmiciSimulation(amici_model, solver=amici_model.getSolver(), edata=edata)\n",
157-
"rdata"
158-
],
154+
"execution_count": null,
159155
"metadata": {
160156
"collapsed": false
161157
},
162-
"execution_count": null
158+
"outputs": [],
159+
"source": [
160+
"rdata = runAmiciSimulation(\n",
161+
" amici_model, solver=amici_model.getSolver(), edata=edata\n",
162+
")\n",
163+
"rdata"
164+
]
163165
},
164166
{
165167
"cell_type": "code",
166-
"outputs": [],
167-
"source": [
168-
"plot_state_trajectories(rdata)"
169-
],
168+
"execution_count": null,
170169
"metadata": {
171170
"collapsed": false
172171
},
173-
"execution_count": null
172+
"outputs": [],
173+
"source": [
174+
"plot_state_trajectories(rdata)"
175+
]
174176
},
175177
{
176178
"cell_type": "markdown",
177-
"source": [
178-
"For further information, check out the [AMICI documentation](https://amici.readthedocs.io/en/latest/)."
179-
],
180179
"metadata": {
181180
"collapsed": false
182-
}
181+
},
182+
"source": [
183+
"For further information, check out the [AMICI documentation](https://amici.readthedocs.io/en/latest/)."
184+
]
183185
}
184186
],
185187
"metadata": {

python/examples/example_presimulation/ExampleExperimentalConditions.ipynb

+4-6
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@
8989
"for reaction in sbml_model.getListOfReactions():\n",
9090
" reactants = \" + \".join(\n",
9191
" [\n",
92-
" \"%s %s\"\n",
93-
" % (\n",
92+
" \"{} {}\".format(\n",
9493
" int(r.getStoichiometry()) if r.getStoichiometry() > 1 else \"\",\n",
9594
" r.getSpecies(),\n",
9695
" )\n",
@@ -99,8 +98,7 @@
9998
" )\n",
10099
" products = \" + \".join(\n",
101100
" [\n",
102-
" \"%s %s\"\n",
103-
" % (\n",
101+
" \"{} {}\".format(\n",
104102
" int(r.getStoichiometry()) if r.getStoichiometry() > 1 else \"\",\n",
105103
" r.getSpecies(),\n",
106104
" )\n",
@@ -109,7 +107,7 @@
109107
" )\n",
110108
" reversible = \"<\" if reaction.getReversible() else \"\"\n",
111109
" print(\n",
112-
" \"%3s: %10s %1s->%10s\\t\\t[%s]\"\n",
110+
" \"%3s: %10s %1s->%10s\\t\\t[%s]\" # noqa: UP031\n",
113111
" % (\n",
114112
" reaction.getName(),\n",
115113
" reactants,\n",
@@ -334,7 +332,7 @@
334332
"metadata": {},
335333
"source": [
336334
"For many biological systems, it is reasonable to assume that they start in a\n",
337-
" steady state. In this example we want to specify an experiment where a pretreatment with a drug is performed _before_ the kinase is added. We assume that the pretreatment is sufficiently long such that the system reaches steadystate before the kinase is added. To implement this in amici, we can specify `fixedParametersPreequilibration` in the `ExpData` object. This automatically adds a preequilibration phase where the model is run to steadystate, before regular simulation starts. Here we set `DRUG_0=3` and `KIN_0=0` for the preequilibration. This means that there is no kinase available in the preequilibration phase. "
335+
" steady state. In this example we want to specify an experiment where a pretreatment with a drug is performed _before_ the kinase is added. We assume that the pretreatment is sufficiently long such that the system reaches steadystate before the kinase is added. To implement this in amici, we can specify `fixedParametersPreequilibration` in the `ExpData` object. This automatically adds a preequilibration phase where the model is run to steadystate, before regular simulation starts. Here we set `DRUG_0=3` and `KIN_0=0` for the preequilibration. This means that there is no kinase available in the preequilibration phase."
338336
]
339337
},
340338
{

python/examples/example_steadystate/ExampleSteadystate.ipynb

+59-60
Large diffs are not rendered by default.

python/sdist/amici/_codegen/model_class.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,7 @@ def get_model_override_implementation(
8282
eval_signature=remove_argument_types(func_info.arguments(ode)),
8383
)
8484
)
85-
return "{return_type} f{fun}({signature}) override {{{body}}}\n".format(
86-
return_type=func_info.return_type,
87-
fun=fun,
88-
signature=func_info.arguments(ode),
89-
body=body,
90-
)
85+
return f"{func_info.return_type} f{fun}({func_info.arguments(ode)}) override {{{body}}}\n"
9186

9287

9388
def get_sunindex_override_implementation(

python/sdist/amici/cxxcodeprinter.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,7 @@ def _print_min_max(self, expr, cpp_fun: str, sympy_fun):
7575
)
7676
if len(expr.args) == 1:
7777
return self._print(arg0)
78-
return "{}{}({}, {})".format(
79-
self._ns,
80-
cpp_fun,
81-
self._print(arg0),
82-
self._print(sympy_fun(*expr.args[1:])),
83-
)
78+
return f"{self._ns}{cpp_fun}({self._print(arg0)}, {self._print(sympy_fun(*expr.args[1:]))})"
8479

8580
def _print_Min(self, expr):
8681
from sympy.functions.elementary.miscellaneous import Min

python/sdist/amici/import_utils.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from typing import (
99
Any,
1010
SupportsFloat,
11-
Union,
1211
)
1312
from collections.abc import Callable
1413
from collections.abc import Iterable, Sequence
@@ -30,7 +29,7 @@ class SBMLException(Exception):
3029
pass
3130

3231

33-
SymbolDef = dict[sp.Symbol, Union[dict[str, sp.Expr], sp.Expr]]
32+
SymbolDef = dict[sp.Symbol, dict[str, sp.Expr] | sp.Expr]
3433

3534

3635
# Monkey-patch toposort CircularDependencyError to handle non-sortable objects,
@@ -407,7 +406,7 @@ def _parse_special_functions(sym: sp.Expr, toplevel: bool = True) -> sp.Expr:
407406
if sym.__class__.__name__ == "plus" and not sym.args:
408407
return sp.Float(0.0)
409408

410-
if isinstance(sym, (sp.Function, sp.Mul, sp.Add, sp.Pow)):
409+
if isinstance(sym, (sp.Function | sp.Mul | sp.Add | sp.Pow)):
411410
sym._args = args
412411

413412
elif toplevel and isinstance(sym, BooleanAtom):
@@ -637,7 +636,7 @@ def cast_to_sym(
637636
:return:
638637
typecast value
639638
"""
640-
if isinstance(value, (sp.RealNumber, numbers.Number)):
639+
if isinstance(value, (sp.RealNumber | numbers.Number)):
641640
value = sp.Float(float(value))
642641
elif isinstance(value, BooleanAtom):
643642
value = sp.Float(float(bool(value)))

python/sdist/amici/jax/petab.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""PEtab wrappers for JAX models.""" ""
2+
23
import shutil
34
from numbers import Number
45
from collections.abc import Iterable

python/sdist/amici/logging.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def set_log_level(logger: logging.Logger, log_level: int | bool) -> None:
127127

128128
if logger.getEffectiveLevel() != log_level:
129129
logger.debug(
130-
"Changing log_level from %d to %d"
131-
% (logger.getEffectiveLevel(), log_level)
130+
f"Changing log_level from {logger.getEffectiveLevel()} "
131+
f"to {log_level}"
132132
)
133133
logger.setLevel(log_level)
134134

0 commit comments

Comments
 (0)