Skip to content

Commit 4efab94

Browse files
authored
maint: ruff, modernize (#3131)
* update ruff * modernize & reformat
1 parent 7d74016 commit 4efab94

19 files changed

Lines changed: 338 additions & 227 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.14.1
15+
rev: v0.15.2
1616
hooks:
1717
# Run the linter.
1818
- id: ruff

doc/examples/example_jax_petab/ExampleJaxPEtab.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"metadata": {},
3232
"outputs": [],
3333
"source": [
34-
"import petab.v1 as petab\n",
3534
"from amici.importers.petab import *\n",
3635
"from petab.v2 import Problem\n",
3736
"\n",
@@ -403,7 +402,9 @@
403402
"nps = jax_problem._np_numeric[ic, :]\n",
404403
"\n",
405404
"# Load parameters for the specified condition\n",
406-
"p = jax_problem.load_model_parameters(jax_problem._petab_problem.experiments[0], is_preeq=False)\n",
405+
"p = jax_problem.load_model_parameters(\n",
406+
" jax_problem._petab_problem.experiments[0], is_preeq=False\n",
407+
")\n",
407408
"\n",
408409
"\n",
409410
"# Define a function to compute the gradient with respect to dynamic timepoints\n",
@@ -576,7 +577,6 @@
576577
"outputs": [],
577578
"source": [
578579
"from amici.sim.sundials import SensitivityMethod, SensitivityOrder\n",
579-
"from amici.sim.sundials.petab.v1 import simulate_petab\n",
580580
"\n",
581581
"# Import the PEtab problem as a standard AMICI model\n",
582582
"pi = PetabImporter(\n",

python/sdist/amici/_symbolic/de_model.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,7 +2648,7 @@ def get_implicit_roots(self) -> list[sp.Expr]:
26482648
for e in self._events
26492649
if not e.has_explicit_trigger_times()
26502650
]
2651-
2651+
26522652
def has_algebraic_states(self) -> bool:
26532653
"""
26542654
Checks whether the model has algebraic states
@@ -2666,7 +2666,7 @@ def has_event_assignments(self) -> bool:
26662666
boolean indicating if event assignments are present
26672667
"""
26682668
return any(event.updates_state for event in self._events)
2669-
2669+
26702670
def has_priority_events(self) -> bool:
26712671
"""
26722672
Checks whether the model has events with priorities defined
@@ -2675,7 +2675,7 @@ def has_priority_events(self) -> bool:
26752675
boolean indicating if priority events are present
26762676
"""
26772677
return any(event.get_priority() is not None for event in self._events)
2678-
2678+
26792679
def has_implicit_event_assignments(self) -> bool:
26802680
"""
26812681
Checks whether the model has event assignments with implicit triggers
@@ -2686,9 +2686,13 @@ def has_implicit_event_assignments(self) -> bool:
26862686
"""
26872687
fixed_symbols = set([k._symbol for k in self._fixed_parameters])
26882688
allowed_symbols = fixed_symbols | {amici_time_symbol}
2689-
# TODO: update to use has_explicit_trigger_times once
2689+
# TODO: update to use has_explicit_trigger_times once
26902690
# https://github.com/AMICI-dev/AMICI/issues/3126 is resolved
2691-
return any(event.updates_state and event._has_implicit_triggers(allowed_symbols) for event in self._events)
2691+
return any(
2692+
event.updates_state
2693+
and event._has_implicit_triggers(allowed_symbols)
2694+
for event in self._events
2695+
)
26922696

26932697
def toposort_expressions(
26942698
self, reorder: bool = True

python/sdist/amici/_symbolic/de_model_components.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ def __init__(
740740
:param priority: The priority of the event assignment.
741741
742742
:param is_negative_event:
743-
Whether this event is a "negative" event, i.e., an event that is
743+
Whether this event is a "negative" event, i.e., an event that is
744744
added to mirror an existing event with inverted trigger condition
745745
to avoid immediate retriggering of the original event (JAX simulations).
746746
@@ -863,17 +863,16 @@ def has_explicit_trigger_times(
863863
"""
864864
if allowed_symbols is None:
865865
return len(self._t_root) > 0
866-
866+
867867
return len(self._t_root) > 0 and all(
868868
t.is_Number or t.free_symbols.issubset(allowed_symbols)
869869
for t in self._t_root
870870
)
871-
871+
872872
def _has_implicit_triggers(
873873
self, allowed_symbols: set[sp.Symbol] | None = None
874874
) -> bool:
875-
"""Check whether the event has implicit triggers.
876-
"""
875+
"""Check whether the event has implicit triggers."""
877876
t = self.get_val()
878877
return not t.free_symbols.issubset(allowed_symbols)
879878

python/sdist/amici/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import enum
99

1010

11-
class SymbolId(str, enum.Enum):
11+
class SymbolId(enum.StrEnum):
1212
"""
1313
Defines the different fields in the symbol dict to which sbml entities
1414
get parsed to.

python/sdist/amici/importers/petab/_petab_importer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
from amici import get_model_dir
2424
from amici._symbolic import DEModel, Event
2525
from amici.importers.utils import MeasurementChannel, amici_time_symbol
26-
from amici.logging import get_logger
2726
from amici.jax.petab import JAXProblem
27+
from amici.logging import get_logger
2828

2929
from .v1.sbml_import import _add_global_parameter
3030

@@ -608,7 +608,7 @@ def create_simulator(
608608
model_module = self.import_module(force_import=force_import)
609609
model = model_module.Model()
610610
return JAXProblem(model, self.petab_problem)
611-
611+
612612
model = self.import_module(force_import=force_import).get_model()
613613
em = ExperimentManager(model=model, petab_problem=self.petab_problem)
614614
return PetabSimulator(em=em)

python/sdist/amici/importers/pysb/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import itertools
1111
import logging
1212
import os
13-
import re
1413
import sys
1514
from collections.abc import Callable, Iterable
1615
from pathlib import Path
@@ -31,9 +30,7 @@
3130
FixedParameter,
3231
FreeParameter,
3332
LogLikelihoodY,
34-
NoiseParameter,
3533
Observable,
36-
ObservableParameter,
3734
SigmaY,
3835
)
3936
from amici.logging import get_logger, log_execution_time, set_log_level

python/sdist/amici/importers/sbml/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ def _process_events(self) -> None:
19021902

19031903
if self.jax:
19041904
# Add a negative event for JAX models to handle
1905-
# TODO: remove once condition function directions can be
1905+
# TODO: remove once condition function directions can be
19061906
# traced through diffrax solve
19071907
neg_event_id = event_id + "_negative"
19081908
neg_event_sym = sp.Symbol(neg_event_id)

python/sdist/amici/importers/sbml/splines.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,10 +1511,9 @@ def _spline_user_functions(
15111511
"AmiciSplineSensitivity": [
15121512
(
15131513
lambda *args: True,
1514-
lambda spline_id,
1515-
x,
1516-
param_id,
1517-
*p: f"sspl_{spline_ids.index(spline_id)}_{p_index[param_id]}",
1514+
lambda spline_id, x, param_id, *p: (
1515+
f"sspl_{spline_ids.index(spline_id)}_{p_index[param_id]}"
1516+
),
15181517
)
15191518
],
15201519
}

python/sdist/amici/importers/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(self, data):
7171
annotation_namespace = "https://github.com/AMICI-dev/AMICI"
7272

7373

74-
class ObservableTransformation(str, enum.Enum):
74+
class ObservableTransformation(enum.StrEnum):
7575
"""
7676
Different modes of observable transformation.
7777
"""

0 commit comments

Comments
 (0)