Skip to content

Commit

Permalink
Merge branch 'develop' into fixing_warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJonasJost committed Jul 22, 2024
2 parents 9342e3c + 3179bbe commit 7e169a6
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 37 deletions.
15 changes: 7 additions & 8 deletions pypesto/hierarchical/base_problem.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Inner optimization problem in hierarchical optimization."""

from __future__ import annotations

import copy
import logging
from typing import Union

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -60,10 +61,10 @@ def __init__(self, xs: list[InnerParameter], data: list[np.ndarray]):

@staticmethod
def from_petab_amici(
petab_problem: "petab.Problem",
amici_model: "amici.Model",
edatas: list["amici.ExpData"],
) -> "InnerProblem":
petab_problem: petab.Problem,
amici_model: amici.Model,
edatas: list[amici.ExpData],
) -> InnerProblem:
"""Create an InnerProblem from a PEtab problem and AMICI objects."""

def get_x_ids(self) -> list[str]:
Expand Down Expand Up @@ -219,9 +220,7 @@ def scale_value_dict(
return scaled_dct


def scale_value(
val: Union[float, np.array], scale: str
) -> Union[float, np.array]:
def scale_value(val: float | np.array, scale: str) -> float | np.array:
"""Scale a single value."""
if scale == "lin":
return val
Expand Down
6 changes: 4 additions & 2 deletions pypesto/hierarchical/ordinal/calculator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Definition of an optimal scaling calculator class."""

from __future__ import annotations

import copy
from collections.abc import Sequence

Expand Down Expand Up @@ -86,12 +88,12 @@ def __call__(
mode: str,
amici_model: AmiciModel,
amici_solver: AmiciSolver,
edatas: list["amici.ExpData"],
edatas: list[amici.ExpData],
n_threads: int,
x_ids: Sequence[str],
parameter_mapping: ParameterMapping,
fim_for_hess: bool,
rdatas: list["amici.ReturnData"] = None,
rdatas: list[amici.ReturnData] = None,
):
"""Perform the actual AMICI call.
Expand Down
18 changes: 10 additions & 8 deletions pypesto/hierarchical/ordinal/problem.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Definition of an optimal scaling parameter class."""

from __future__ import annotations

import numpy as np
import pandas as pd

Expand Down Expand Up @@ -172,10 +174,10 @@ def initialize(self) -> None:
@staticmethod
def from_petab_amici(
petab_problem: petab.Problem,
amici_model: "amici.Model",
edatas: list["amici.ExpData"],
amici_model: amici.Model,
edatas: list[amici.ExpData],
method: str = None,
) -> "OrdinalProblem":
) -> OrdinalProblem:
"""Construct the inner problem from the `petab_problem`."""
if not method:
method = REDUCED
Expand Down Expand Up @@ -475,8 +477,8 @@ def get_inner_parameter_dictionary(self) -> dict:

def optimal_scaling_inner_problem_from_petab_problem(
petab_problem: petab.Problem,
amici_model: "amici.Model",
edatas: list["amici.ExpData"],
amici_model: amici.Model,
edatas: list[amici.ExpData],
method: str,
):
"""Construct the inner problem from the `petab_problem`."""
Expand Down Expand Up @@ -511,7 +513,7 @@ def optimal_scaling_inner_problem_from_petab_problem(
def optimal_scaling_inner_parameters_from_measurement_df(
df: pd.DataFrame,
method: str,
amici_model: "amici.Model",
amici_model: amici.Model,
) -> list[OrdinalParameter]:
"""Create list of inner free parameters from PEtab measurement table dependent on the method provided."""
df = df.reset_index()
Expand Down Expand Up @@ -611,8 +613,8 @@ def get_estimate_for_method(method: str) -> tuple[bool, bool]:


def optimal_scaling_ixs_for_measurement_specific_parameters(
petab_problem: "petab.Problem",
amici_model: "amici.Model",
petab_problem: petab.Problem,
amici_model: amici.Model,
inner_parameters: list[OrdinalParameter],
) -> dict[str, list[tuple[int, int, int]]]:
"""Create mapping of parameters to measurements.
Expand Down
2 changes: 1 addition & 1 deletion pypesto/hierarchical/ordinal/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
try:
from amici.petab.parameter_mapping import ParameterMapping
except ImportError:
pass
ParameterMapping = None


class OrdinalInnerSolver(InnerSolver):
Expand Down
2 changes: 2 additions & 0 deletions pypesto/hierarchical/relative/solver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import copy
from typing import Any

Expand Down
6 changes: 4 additions & 2 deletions pypesto/hierarchical/semiquantitative/calculator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import copy
from collections.abc import Sequence

Expand Down Expand Up @@ -79,12 +81,12 @@ def __call__(
mode: str,
amici_model: AmiciModel,
amici_solver: AmiciSolver,
edatas: list["amici.ExpData"],
edatas: list[amici.ExpData],
n_threads: int,
x_ids: Sequence[str],
parameter_mapping: ParameterMapping,
fim_for_hess: bool,
rdatas: list["amici.ReturnData"] = None,
rdatas: list[amici.ReturnData] = None,
):
"""Perform the actual AMICI call.
Expand Down
22 changes: 12 additions & 10 deletions pypesto/hierarchical/semiquantitative/problem.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import numpy as np
import pandas as pd

Expand Down Expand Up @@ -124,10 +126,10 @@ def initialize(self) -> None:
@staticmethod
def from_petab_amici(
petab_problem: petab.Problem,
amici_model: "amici.Model",
edatas: list["amici.ExpData"],
amici_model: amici.Model,
edatas: list[amici.ExpData],
spline_ratio: float = None,
) -> "SemiquantProblem":
) -> SemiquantProblem:
"""Construct the inner problem from the `petab_problem`."""
if spline_ratio is None:
spline_ratio = get_default_options()
Expand Down Expand Up @@ -289,8 +291,8 @@ def get_default_options() -> dict:

def spline_inner_problem_from_petab_problem(
petab_problem: petab.Problem,
amici_model: "amici.Model",
edatas: list["amici.ExpData"],
amici_model: amici.Model,
edatas: list[amici.ExpData],
spline_ratio: float = None,
):
"""Construct the inner problem from the `petab_problem`."""
Expand Down Expand Up @@ -336,7 +338,7 @@ def spline_inner_problem_from_petab_problem(
def spline_inner_parameters_from_measurement_df(
df: pd.DataFrame,
spline_ratio: float,
amici_model: "amici.Model",
amici_model: amici.Model,
) -> list[SplineInnerParameter]:
"""Create list of inner free spline parameters from PEtab measurement table."""
df = df.reset_index()
Expand Down Expand Up @@ -382,8 +384,8 @@ def spline_inner_parameters_from_measurement_df(


def noise_inner_parameters_from_parameter_df(
petab_problem: "petab.Problem",
amici_model: "amici.Model",
petab_problem: petab.Problem,
amici_model: amici.Model,
) -> list[SplineInnerParameter]:
"""Create list of inner free noise parameters from PEtab parameter table."""
# Select the semiquantitative measurements.
Expand Down Expand Up @@ -432,8 +434,8 @@ def noise_inner_parameters_from_parameter_df(


def spline_ixs_for_measurement_specific_parameters(
petab_problem: "petab.Problem",
amici_model: "amici.Model",
petab_problem: petab.Problem,
amici_model: amici.Model,
inner_parameters: list[SplineInnerParameter],
) -> dict[str, list[tuple[int, int, int]]]:
"""Create mapping of parameters to measurements.
Expand Down
2 changes: 2 additions & 0 deletions pypesto/hierarchical/semiquantitative/solver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import warnings

import numpy as np
Expand Down
7 changes: 1 addition & 6 deletions pypesto/petab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,4 @@
try:
import amici
except ImportError:
warnings.warn(
"PEtab import requires an installation of amici "
"(https://github.com/AMICI-dev/AMICI). "
"Install via `pip3 install amici`.",
stacklevel=1,
)
amici = None
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ amici =
amici >= 0.21.0
roadrunner =
libroadrunner >= 2.7.0
%(petab)s
python-libsbml >= 5.20.2
petab =
petab >= 0.4.0
ipopt =
Expand Down

0 comments on commit 7e169a6

Please sign in to comment.