Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit autoupdate #2635

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
Expand All @@ -12,7 +12,7 @@ repos:
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.7
rev: v0.8.6
hooks:
# Run the linter.
- id: ruff
Expand All @@ -28,7 +28,7 @@ repos:
- python/sdist/pyproject.toml

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
rev: v3.19.1
hooks:
- id: pyupgrade
args: ["--py310-plus"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@
"for reaction in sbml_model.getListOfReactions():\n",
" reactants = \" + \".join(\n",
" [\n",
" \"%s %s\"\n",
" % (\n",
" \"{} {}\".format(\n",
" int(r.getStoichiometry()) if r.getStoichiometry() > 1 else \"\",\n",
" r.getSpecies(),\n",
" )\n",
Expand All @@ -134,8 +133,7 @@
" )\n",
" products = \" + \".join(\n",
" [\n",
" \"%s %s\"\n",
" % (\n",
" \"{} {}\".format(\n",
" int(r.getStoichiometry()) if r.getStoichiometry() > 1 else \"\",\n",
" r.getSpecies(),\n",
" )\n",
Expand All @@ -144,7 +142,7 @@
" )\n",
" reversible = \"<\" if reaction.getReversible() else \"\"\n",
" print(\n",
" \"%3s: %10s %1s->%10s\\t\\t[%s]\"\n",
" \"%3s: %10s %1s->%10s\\t\\t[%s]\" # noqa: UP031\n",
" % (\n",
" reaction.getId(),\n",
" reactants,\n",
Expand Down Expand Up @@ -370,7 +368,7 @@
"\n",
"# np.set_printoptions(threshold=8, edgeitems=2)\n",
"for key, value in rdata.items():\n",
" print(\"%12s: \" % key, value)"
" print(f\"{key:12s}: \", value)"
]
},
{
Expand Down Expand Up @@ -664,15 +662,15 @@
"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",
"\n",
" $$p(t) = e^{t J(x^*, \\theta)^T} p_{\\text{end}}.$$\n",
" \n",
"\n",
"As a consequence, the quadratures in adjoint computation also reduce to a matrix-vector product:\n",
"\n",
" $$Q(x, \\theta) = Q(x^*, \\theta) = p_{\\text{integral}} * \\frac{\\partial f}{\\partial \\theta}$$\n",
"\n",
"with\n",
"\n",
" $$p_{\\text{integral}} = \\int_0^\\infty p(s) ds = (J(x^*, \\theta)^T)^{-1} p_{\\text{end}}.$$ \n",
" \n",
" $$p_{\\text{integral}} = \\int_0^\\infty p(s) ds = (J(x^*, \\theta)^T)^{-1} p_{\\text{end}}.$$\n",
"\n",
"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",
"In this case, standard integration must be carried out."
]
Expand Down Expand Up @@ -922,7 +920,7 @@
"\n",
"for key, value in rdata.items():\n",
" if key[0:6] == \"preeq_\":\n",
" print(\"%20s: \" % key, value)"
" print(f\"{key:20s}:\", value)"
]
},
{
Expand Down Expand Up @@ -960,7 +958,7 @@
"\n",
"for key, value in rdata.items():\n",
" if key[0:6] == \"preeq_\":\n",
" print(\"%20s: \" % key, value)"
" print(f\"{key:20s}:\", value)"
]
},
{
Expand Down Expand Up @@ -993,7 +991,7 @@
"\n",
"for key, value in rdata_reduced.items():\n",
" if key[0:6] == \"preeq_\":\n",
" print(\"%20s: \" % key, value)"
" print(f\"{key:20s}:\", value)"
]
},
{
Expand Down Expand Up @@ -1044,7 +1042,7 @@
"\n",
"for key, value in rdata_reduced.items():\n",
" if key[0:6] == \"preeq_\":\n",
" print(\"%20s: \" % key, value)\n",
" print(f\"{key:20s}:\", value)\n",
"print(\"Gradient:\", rdata_reduced[\"sllh\"])"
]
},
Expand Down Expand Up @@ -1079,7 +1077,7 @@
"\n",
"for key, value in rdata_reduced.items():\n",
" if key[0:6] == \"preeq_\":\n",
" print(\"%20s: \" % key, value)\n",
" print(f\"{key:20s}:\", value)\n",
"print(\"Gradient:\", rdata_reduced[\"sllh\"])"
]
},
Expand Down Expand Up @@ -1117,7 +1115,7 @@
"\n",
"for key, value in rdata_reduced.items():\n",
" if key[0:6] == \"preeq_\":\n",
" print(\"%20s: \" % key, value)\n",
" print(f\"{key:20s}:\", value)\n",
"print(\"Gradient:\", rdata_reduced[\"sllh\"])"
]
},
Expand Down Expand Up @@ -1160,7 +1158,7 @@
"\n",
"for key, value in rdata.items():\n",
" if key[0:6] == \"preeq_\":\n",
" print(\"%20s: \" % key, value)\n",
" print(f\"{key:20s}:\", value)\n",
"print(\"Gradient:\", rdata[\"sllh\"])"
]
},
Expand Down
8 changes: 2 additions & 6 deletions python/examples/example_errors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@
"outputs": [],
"source": [
"petab_problem = benchmark_models_petab.get_problem(\"Fujita_SciSignal2010\")\n",
"amici_model = import_petab_problem(\n",
" petab_problem, verbose=False, compile_=None\n",
")\n",
"amici_model = import_petab_problem(petab_problem, verbose=False, compile_=None)\n",
"\n",
"np.random.seed(2991)\n",
"problem_parameters = dict(\n",
Expand Down Expand Up @@ -422,9 +420,7 @@
"outputs": [],
"source": [
"petab_problem = benchmark_models_petab.get_problem(\"Weber_BMC2015\")\n",
"amici_model = import_petab_problem(\n",
" petab_problem, verbose=False, compile_=None\n",
")\n",
"amici_model = import_petab_problem(petab_problem, verbose=False, compile_=None)\n",
"\n",
"np.random.seed(4)\n",
"problem_parameters = dict(\n",
Expand Down
50 changes: 26 additions & 24 deletions python/examples/example_petab/petab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
},
{
"cell_type": "markdown",
"source": [
"## Importing a PEtab problem"
],
"metadata": {
"collapsed": false
}
},
"source": [
"## Importing a PEtab problem"
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -134,6 +134,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"app = PetabProblem(petab_problem)\n",
Expand All @@ -143,43 +147,41 @@
"\n",
"# ExpData for a single condition:\n",
"edata = app.get_edata(\"model1_data1\")"
],
"metadata": {
"collapsed": false
},
"execution_count": null
]
},
{
"cell_type": "code",
"outputs": [],
"source": [
"rdata = runAmiciSimulation(amici_model, solver=amici_model.getSolver(), edata=edata)\n",
"rdata"
],
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": null
"outputs": [],
"source": [
"rdata = runAmiciSimulation(\n",
" amici_model, solver=amici_model.getSolver(), edata=edata\n",
")\n",
"rdata"
]
},
{
"cell_type": "code",
"outputs": [],
"source": [
"plot_state_trajectories(rdata)"
],
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": null
"outputs": [],
"source": [
"plot_state_trajectories(rdata)"
]
},
{
"cell_type": "markdown",
"source": [
"For further information, check out the [AMICI documentation](https://amici.readthedocs.io/en/latest/)."
],
"metadata": {
"collapsed": false
}
},
"source": [
"For further information, check out the [AMICI documentation](https://amici.readthedocs.io/en/latest/)."
]
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@
"for reaction in sbml_model.getListOfReactions():\n",
" reactants = \" + \".join(\n",
" [\n",
" \"%s %s\"\n",
" % (\n",
" \"{} {}\".format(\n",
" int(r.getStoichiometry()) if r.getStoichiometry() > 1 else \"\",\n",
" r.getSpecies(),\n",
" )\n",
Expand All @@ -99,8 +98,7 @@
" )\n",
" products = \" + \".join(\n",
" [\n",
" \"%s %s\"\n",
" % (\n",
" \"{} {}\".format(\n",
" int(r.getStoichiometry()) if r.getStoichiometry() > 1 else \"\",\n",
" r.getSpecies(),\n",
" )\n",
Expand All @@ -109,7 +107,7 @@
" )\n",
" reversible = \"<\" if reaction.getReversible() else \"\"\n",
" print(\n",
" \"%3s: %10s %1s->%10s\\t\\t[%s]\"\n",
" \"%3s: %10s %1s->%10s\\t\\t[%s]\" # noqa: UP031\n",
" % (\n",
" reaction.getName(),\n",
" reactants,\n",
Expand Down Expand Up @@ -334,7 +332,7 @@
"metadata": {},
"source": [
"For many biological systems, it is reasonable to assume that they start in a\n",
" 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. "
" 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."
]
},
{
Expand Down
119 changes: 59 additions & 60 deletions python/examples/example_steadystate/ExampleSteadystate.ipynb

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions python/sdist/amici/_codegen/model_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ def get_model_override_implementation(
eval_signature=remove_argument_types(func_info.arguments(ode)),
)
)
return "{return_type} f{fun}({signature}) override {{{body}}}\n".format(
return_type=func_info.return_type,
fun=fun,
signature=func_info.arguments(ode),
body=body,
)
return f"{func_info.return_type} f{fun}({func_info.arguments(ode)}) override {{{body}}}\n"


def get_sunindex_override_implementation(
Expand Down
7 changes: 1 addition & 6 deletions python/sdist/amici/cxxcodeprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ def _print_min_max(self, expr, cpp_fun: str, sympy_fun):
)
if len(expr.args) == 1:
return self._print(arg0)
return "{}{}({}, {})".format(
self._ns,
cpp_fun,
self._print(arg0),
self._print(sympy_fun(*expr.args[1:])),
)
return f"{self._ns}{cpp_fun}({self._print(arg0)}, {self._print(sympy_fun(*expr.args[1:]))})"

def _print_Min(self, expr):
from sympy.functions.elementary.miscellaneous import Min
Expand Down
7 changes: 3 additions & 4 deletions python/sdist/amici/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import (
Any,
SupportsFloat,
Union,
)
from collections.abc import Callable
from collections.abc import Iterable, Sequence
Expand All @@ -30,7 +29,7 @@ class SBMLException(Exception):
pass


SymbolDef = dict[sp.Symbol, Union[dict[str, sp.Expr], sp.Expr]]
SymbolDef = dict[sp.Symbol, dict[str, sp.Expr] | sp.Expr]


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

if isinstance(sym, (sp.Function, sp.Mul, sp.Add, sp.Pow)):
if isinstance(sym, (sp.Function | sp.Mul | sp.Add | sp.Pow)):
sym._args = args

elif toplevel and isinstance(sym, BooleanAtom):
Expand Down Expand Up @@ -637,7 +636,7 @@ def cast_to_sym(
:return:
typecast value
"""
if isinstance(value, (sp.RealNumber, numbers.Number)):
if isinstance(value, (sp.RealNumber | numbers.Number)):
value = sp.Float(float(value))
elif isinstance(value, BooleanAtom):
value = sp.Float(float(bool(value)))
Expand Down
1 change: 1 addition & 0 deletions python/sdist/amici/jax/petab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PEtab wrappers for JAX models.""" ""

import shutil
from numbers import Number
from collections.abc import Iterable
Expand Down
4 changes: 2 additions & 2 deletions python/sdist/amici/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def set_log_level(logger: logging.Logger, log_level: int | bool) -> None:

if logger.getEffectiveLevel() != log_level:
logger.debug(
"Changing log_level from %d to %d"
% (logger.getEffectiveLevel(), log_level)
f"Changing log_level from {logger.getEffectiveLevel()} "
f"to {log_level}"
)
logger.setLevel(log_level)

Expand Down
Loading
Loading