Skip to content

Commit

Permalink
Update deprecated amici imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed May 2, 2024
1 parent e197a8b commit 1530bb6
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 27 deletions.
6 changes: 3 additions & 3 deletions pypesto/hierarchical/inner_calculator_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
try:
import amici
import petab
from amici.parameter_mapping import ParameterMapping
from amici.petab.parameter_mapping import ParameterMapping
except ImportError:
petab = None
ParameterMapping = None
Expand Down Expand Up @@ -325,7 +325,7 @@ def __call__(
Whether to use the FIM (if available) instead of the Hessian (if
requested).
"""
import amici.parameter_mapping
from amici.petab.conditions import fill_in_parameters

if mode == MODE_RES and any(
data_type in self.data_types
Expand Down Expand Up @@ -403,7 +403,7 @@ def __call__(
x_dct = copy.deepcopy(x_dct)
x_dct.update(self.necessary_par_dummy_values)
# fill in parameters
amici.parameter_mapping.fill_in_parameters(
fill_in_parameters(
edatas=edatas,
problem_parameters=x_dct,
scaled_parameters=True,
Expand Down
5 changes: 3 additions & 2 deletions pypesto/hierarchical/ordinal/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@

try:
import amici
from amici.parameter_mapping import ParameterMapping
from amici.petab.conditions import fill_in_parameters
from amici.petab.parameter_mapping import ParameterMapping
except ImportError:
pass

Expand Down Expand Up @@ -155,7 +156,7 @@ def __call__(
x_dct = copy.deepcopy(x_dct)

# fill in parameters
amici.parameter_mapping.fill_in_parameters(
fill_in_parameters(
edatas=edatas,
problem_parameters=x_dct,
scaled_parameters=True,
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 @@ -37,7 +37,7 @@
from .problem import OrdinalProblem

try:
from amici.parameter_mapping import ParameterMapping
from amici.petab.parameter_mapping import ParameterMapping
except ImportError:
pass

Expand Down
6 changes: 3 additions & 3 deletions pypesto/hierarchical/relative/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

try:
import amici
import amici.parameter_mapping
from amici.parameter_mapping import ParameterMapping
from amici.petab.conditions import fill_in_parameters
from amici.petab.parameter_mapping import ParameterMapping
except ImportError:
pass

Expand Down Expand Up @@ -296,7 +296,7 @@ def calculate_directly(
amici_solver.setSensitivityOrder(sensi_order)
x_dct.update(self.inner_problem.get_dummy_values(scaled=True))
# fill in parameters
amici.parameter_mapping.fill_in_parameters(
fill_in_parameters(
edatas=edatas,
problem_parameters=x_dct,
scaled_parameters=True,
Expand Down
2 changes: 1 addition & 1 deletion pypesto/hierarchical/relative/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

try:
import amici
from amici.parameter_mapping import ParameterMapping
from amici.petab.parameter_mapping import ParameterMapping
except ImportError:
pass

Expand Down
5 changes: 3 additions & 2 deletions pypesto/hierarchical/semiquantitative/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@

try:
import amici
from amici.parameter_mapping import ParameterMapping
from amici.petab.conditions import fill_in_parameters
from amici.petab.parameter_mapping import ParameterMapping
except ImportError:
pass

Expand Down Expand Up @@ -154,7 +155,7 @@ def __call__(
)

# fill in parameters
amici.parameter_mapping.fill_in_parameters(
fill_in_parameters(
edatas=edatas,
problem_parameters=x_dct,
scaled_parameters=True,
Expand Down
2 changes: 1 addition & 1 deletion pypesto/hierarchical/semiquantitative/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .problem import SemiquantProblem

try:
from amici.parameter_mapping import ParameterMapping
from amici.petab.parameter_mapping import ParameterMapping
except ImportError:
pass

Expand Down
20 changes: 11 additions & 9 deletions pypesto/objective/amici/amici_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
if TYPE_CHECKING:
try:
import amici
from amici.parameter_mapping import (
from amici.petab.parameter_mapping import (
ParameterMapping,
ParameterMappingForCondition,
)
Expand Down Expand Up @@ -124,23 +124,25 @@ def create_identity_parameter_mapping(
both in preequilibration and simulation, are assumed to be provided
correctly in model or edatas already.
"""
import amici.parameter_mapping
from amici.petab.parameter_mapping import (
ParameterMapping,
ParameterMappingForCondition,
amici_to_petab_scale,
)

x_ids = list(amici_model.getParameterIds())
x_scales = list(amici_model.getParameterScale())
parameter_mapping = amici.parameter_mapping.ParameterMapping()
parameter_mapping = ParameterMapping()
for _ in range(n_conditions):
condition_map_sim_var = {x_id: x_id for x_id in x_ids}
condition_scale_map_sim_var = {
x_id: amici.parameter_mapping.amici_to_petab_scale(x_scale)
x_id: amici_to_petab_scale(x_scale)
for x_id, x_scale in zip(x_ids, x_scales)
}
# assumes fixed parameters are filled in already
mapping_for_condition = (
amici.parameter_mapping.ParameterMappingForCondition(
map_sim_var=condition_map_sim_var,
scale_map_sim_var=condition_scale_map_sim_var,
)
mapping_for_condition = ParameterMappingForCondition(
map_sim_var=condition_map_sim_var,
scale_map_sim_var=condition_scale_map_sim_var,
)

parameter_mapping.append(mapping_for_condition)
Expand Down
3 changes: 2 additions & 1 deletion pypesto/visualize/model_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import matplotlib.pyplot as plt
import numpy as np
import petab
from amici.petab.conditions import fill_in_parameters
from amici.petab.simulations import rdatas_to_simulation_df
from petab.visualize import plot_problem

Expand Down Expand Up @@ -269,7 +270,7 @@ def _get_simulation_rdatas(
for j in range(len(edatas)):
edatas[j].setTimepoints(simulation_timepoints)

amici.parameter_mapping.fill_in_parameters(
fill_in_parameters(
edatas=edatas,
problem_parameters=x_dct,
scaled_parameters=True,
Expand Down
3 changes: 2 additions & 1 deletion pypesto/visualize/ordinal_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

try:
import amici
from amici.petab.conditions import fill_in_parameters
from petab.C import OBSERVABLE_ID

from ..hierarchical.ordinal.calculator import OrdinalCalculator
Expand Down Expand Up @@ -86,7 +87,7 @@ def plot_categories_from_pypesto_result(
n_threads = pypesto_result.problem.objective.n_threads

# Fill in the parameters.
amici.parameter_mapping.fill_in_parameters(
fill_in_parameters(
edatas=edatas,
problem_parameters=x_dct,
scaled_parameters=True,
Expand Down
7 changes: 4 additions & 3 deletions pypesto/visualize/spline_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

try:
import amici
from amici.petab.conditions import fill_in_parameters

from ..hierarchical import InnerCalculatorCollector
from ..hierarchical.semiquantitative.calculator import SemiquantCalculator
Expand Down Expand Up @@ -105,7 +106,7 @@ def plot_splines_from_pypesto_result(
observable_ids = amici_model.getObservableIds()

# Fill in the parameters.
amici.parameter_mapping.fill_in_parameters(
fill_in_parameters(
edatas=edatas,
problem_parameters=x_dct,
scaled_parameters=True,
Expand Down Expand Up @@ -379,7 +380,7 @@ def _add_spline_mapped_simulations_to_model_fit(
n_threads = pypesto_problem.objective.n_threads

# Fill in the parameters.
amici.parameter_mapping.fill_in_parameters(
fill_in_parameters(
edatas=edatas,
problem_parameters=x_dct,
scaled_parameters=True,
Expand Down Expand Up @@ -528,7 +529,7 @@ def _obtain_regularization_for_start(
n_threads = pypesto_result.problem.objective.n_threads

# Fill in the parameters.
amici.parameter_mapping.fill_in_parameters(
fill_in_parameters(
edatas=edatas,
problem_parameters=x_dct,
scaled_parameters=True,
Expand Down

0 comments on commit 1530bb6

Please sign in to comment.