Skip to content

Commit 6b3bf83

Browse files
authored
Update imports/exports (#3092)
Simplify some imports. Fix type annotations. Import extension types only where necessary.
1 parent 1a80258 commit 6b3bf83

File tree

9 files changed

+30
-19
lines changed

9 files changed

+30
-19
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import sys
1515
from collections.abc import Callable, Iterable
1616
from pathlib import Path
17-
from typing import (
18-
Any,
19-
)
17+
from typing import Any
2018

2119
import numpy as np
2220
import pysb

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282

8383
SymbolicFormula = dict[sp.Symbol, sp.Expr]
8484

85-
8685
default_symbols = {symbol: {} for symbol in SymbolId}
8786

8887
ConservationLaw = dict[str, str | sp.Expr]

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
"""Find conserved quantities deterministically"""
22

3-
from typing import Literal
4-
53
import numpy as np
64

75
__all__ = ["nullspace_by_rref", "rref"]
86

97

108
def rref(
11-
mat: np.array, round_ndigits: Literal[False] | int | None = None
12-
) -> np.array:
9+
mat: np.ndarray, round_ndigits: bool | int | None = None
10+
) -> np.ndarray:
1311
"""
1412
Bring matrix ``mat`` to reduced row echelon form
1513
@@ -69,7 +67,7 @@ def _round(mat):
6967
return mat
7068

7169

72-
def pivots(mat: np.array) -> list[int]:
70+
def pivots(mat: np.ndarray) -> list[int]:
7371
"""Get indices of pivot columns in ``mat``, assumed to be in reduced row
7472
echelon form"""
7573
pivot_cols = []
@@ -83,7 +81,7 @@ def pivots(mat: np.array) -> list[int]:
8381
return pivot_cols
8482

8583

86-
def nullspace_by_rref(mat: np.array) -> np.array:
84+
def nullspace_by_rref(mat: np.ndarray) -> np.ndarray:
8785
"""Compute basis of the nullspace of ``mat`` based on the reduced row
8886
echelon form"""
8987
rref_mat = rref(mat)

python/sdist/amici/sim/sundials/_numpy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ def __repr__(self):
491491

492492
def by_id(
493493
self, entity_id: str, field: str = None, model: Model = None
494-
) -> np.array:
494+
) -> np.ndarray:
495495
"""
496496
Get the value of a given field for a named entity.
497497
@@ -635,7 +635,7 @@ def _entity_type_from_id(
635635
raise KeyError(f"Unknown symbol {entity_id}.")
636636

637637

638-
def evaluate(expr: StrOrExpr, rdata: ReturnDataView) -> np.array:
638+
def evaluate(expr: StrOrExpr, rdata: ReturnDataView) -> np.ndarray:
639639
"""Evaluate a symbolic expression based on the given simulation outputs.
640640
641641
:param expr:

python/sdist/amici/sim/sundials/gradient_check.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ExpData,
1616
Model,
1717
ParameterScaling,
18-
ReturnData,
18+
ReturnDataView,
1919
SensitivityMethod,
2020
SensitivityOrder,
2121
Solver,
@@ -272,8 +272,8 @@ def check_derivatives(
272272

273273

274274
def _check_close(
275-
result: np.array,
276-
expected: np.array,
275+
result: np.ndarray,
276+
expected: np.ndarray,
277277
atol: float,
278278
rtol: float,
279279
field: str,
@@ -342,7 +342,11 @@ def _check_close(
342342

343343

344344
def _check_results(
345-
rdata: ReturnData, field: str, expected: np.array, atol: float, rtol: float
345+
rdata: ReturnDataView,
346+
field: str,
347+
expected: np.ndarray,
348+
atol: float,
349+
rtol: float,
346350
) -> None:
347351
"""
348352
Checks whether rdata[field] agrees with expected according to provided

python/sdist/amici/sim/sundials/petab/v1/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from ._conditions import create_edatas, create_parameterized_edatas
1+
from ._conditions import (
2+
create_edatas,
3+
create_parameterized_edatas,
4+
fill_in_parameters,
5+
)
26
from ._petab_problem import PetabProblem
37
from ._simulations import (
48
EDATAS,
@@ -31,4 +35,5 @@
3135
"PetabSimulator",
3236
"create_edatas",
3337
"create_parameterized_edatas",
38+
"fill_in_parameters",
3439
]

python/sdist/amici/sim/sundials/petab/v1/_simulations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
"SRES",
6161
"RDATAS",
6262
"EDATAS",
63+
"rdatas_to_measurement_df",
64+
"rdatas_to_simulation_df",
6365
]
6466

6567

python/sdist/amici/testing/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""Test models used by AMICI."""
22

3+
from __future__ import annotations
4+
35
import sys
46
import tempfile
57
from pathlib import Path
8+
from typing import TYPE_CHECKING
69

710
import libsbml
811
import sympy as sp
@@ -11,7 +14,9 @@
1114
from amici.importers.antimony import antimony2amici, antimony2sbml
1215
from amici.importers.sbml.splines import CubicHermiteSpline
1316
from amici.importers.utils import amici_time_symbol
14-
from amici.sim.sundials import AmiciModel, Model
17+
18+
if TYPE_CHECKING:
19+
from amici.sim.sundials import AmiciModel, Model
1520

1621
model_dirac_ant = r"""
1722
p1 = 1;

python/tests/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
import numpy as np
88
import pandas as pd
9-
from amici import import_model_module
109
from amici.importers.sbml import SbmlImporter
1110
from amici.sim.sundials import (
1211
AMICI_SUCCESS,
1312
AmiciModel,
1413
ExpData,
1514
SensitivityMethod,
1615
SensitivityOrder,
16+
import_model_module,
1717
run_simulation,
1818
)
1919
from amici.sim.sundials.gradient_check import _check_close

0 commit comments

Comments
 (0)