Skip to content

Commit c10af83

Browse files
committed
Prepare for amici>=1.0.0
1 parent e2caf55 commit c10af83

File tree

10 files changed

+66
-43
lines changed

10 files changed

+66
-43
lines changed

pypesto/hierarchical/inner_calculator_collector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def _get_quantitative_data_mask(
225225
) -> list[np.ndarray]:
226226
# transform experimental data
227227
edatas = [
228-
amici.numpy.ExpDataView(edata)["observedData"] for edata in edatas
228+
amici.numpy.ExpDataView(edata)["observed_data"] for edata in edatas
229229
]
230230

231231
quantitative_data_mask = [

pypesto/hierarchical/relative/problem.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ def inner_problem_from_petab_problem(
123123
)
124124

125125
# transform experimental data
126-
data = [amici.numpy.ExpDataView(edata)["observedData"] for edata in edatas]
126+
data = [
127+
amici.numpy.ExpDataView(edata)["observed_data"] for edata in edatas
128+
]
127129

128130
# matrixify
129131
ix_matrices = ix_matrices_from_arrays(ixs, data)
@@ -135,7 +137,7 @@ def inner_problem_from_petab_problem(
135137
meas_indices[2] for meas_indices in ixs[par.inner_parameter_id]
136138
]
137139
par.observable_ids = [
138-
amici_model.getObservableIds()[obs_idx]
140+
amici_model.get_observable_ids()[obs_idx]
139141
for obs_idx in par.observable_indices
140142
]
141143

@@ -256,7 +258,7 @@ def ixs_for_measurement_specific_parameters(
256258
a sorted list of non-unique time points for which there are measurements.
257259
"""
258260
ixs_for_par = {}
259-
observable_ids = amici_model.getObservableIds()
261+
observable_ids = amici_model.get_observable_ids()
260262

261263
simulation_conditions = (
262264
petab_problem.get_simulation_conditions_from_measurement_df()

pypesto/objective/amici/amici.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def __init__(
204204

205205
if (
206206
self.guess_steadystate is not False
207-
and self.amici_model.getSteadyStateSensitivityMode()
207+
and self.amici_model.get_steady_state_sensitivity_mode()
208208
== amici.SteadyStateSensitivityMode.integrationOnly
209209
):
210210
if self.guess_steadystate:
@@ -226,7 +226,7 @@ def __init__(
226226
"data": {
227227
iexp: {}
228228
for iexp, edata in enumerate(self.edatas)
229-
if len(edata.fixedParametersPreequilibration)
229+
if len(edata.fixed_parameters_pre_equilibration)
230230
},
231231
}
232232
# optimization parameter names
@@ -331,7 +331,7 @@ def __getstate__(self) -> dict:
331331
try:
332332
# write amici solver settings to file
333333
try:
334-
amici.writeSolverSettingsToHDF5(self.amici_solver, _file)
334+
amici.write_solver_settings_to_hdf5(self.amici_solver, _file)
335335
except AttributeError as e:
336336
e.args += (
337337
"Pickling the AmiciObjective requires an AMICI "
@@ -415,10 +415,10 @@ def check_sensi_orders(
415415
if max_sensi_order is None:
416416
max_sensi_order = 1
417417
# check whether it is ok to request 2nd order
418-
sensi_mthd = self.amici_solver.getSensitivityMethod()
419-
mthd_fwd = amici.SensitivityMethod_forward
418+
sensi_mthd = self.amici_solver.get_sensitivity_method()
419+
mthd_fwd = amici.SensitivityMethod.forward
420420
if mode == MODE_FUN and (
421-
self.amici_model.o2mode
421+
self.amici_model.get_second_order_mode()
422422
or (sensi_mthd == mthd_fwd and self.fim_for_hess)
423423
):
424424
max_sensi_order = 2
@@ -469,7 +469,7 @@ def call_unprocessed(
469469
if mode == MODE_FUN
470470
else amici.RDataReporting.residuals
471471
)
472-
self.amici_solver.setReturnDataReportingMode(amici_reporting)
472+
self.amici_solver.set_return_data_reporting_mode(amici_reporting)
473473

474474
# update steady state
475475
if (
@@ -601,7 +601,9 @@ def apply_custom_timepoints(self) -> None:
601601
"""
602602
if self.custom_timepoints is not None:
603603
for index in range(len(self.edatas)):
604-
self.edatas[index].setTimepoints(self.custom_timepoints[index])
604+
self.edatas[index].set_timepoints(
605+
self.custom_timepoints[index]
606+
)
605607

606608
def set_custom_timepoints(
607609
self,

pypesto/objective/amici/amici_calculator.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ def __call__(
9696

9797
if sensi_order == 2 and fim_for_hess:
9898
# we use the FIM
99-
amici_solver.setSensitivityOrder(sensi_order - 1)
99+
amici_solver.set_sensitivity_order(sensi_order - 1)
100100
else:
101-
amici_solver.setSensitivityOrder(sensi_order)
101+
amici_solver.set_sensitivity_order(sensi_order)
102102

103103
# fill in parameters
104104
amici.petab.conditions.fill_in_parameters(
@@ -110,7 +110,7 @@ def __call__(
110110
)
111111

112112
# run amici simulation
113-
rdatas = amici.runAmiciSimulations(
113+
rdatas = amici.run_simulations(
114114
amici_model,
115115
amici_solver,
116116
edatas,
@@ -121,7 +121,7 @@ def __call__(
121121
and mode == MODE_RES
122122
and 1 in sensi_orders
123123
):
124-
if not amici_model.getAddSigmaResiduals() and any(
124+
if not amici_model.get_add_sigma_residuals() and any(
125125
(
126126
(r["ssigmay"] is not None and np.any(r["ssigmay"]))
127127
or (r["ssigmaz"] is not None and np.any(r["ssigmaz"]))
@@ -176,8 +176,8 @@ def calculate_function_values(
176176
sensi_orders, mode, dim
177177
)
178178

179-
par_sim_ids = list(amici_model.getParameterIds())
180-
sensi_method = amici_solver.getSensitivityMethod()
179+
par_sim_ids = list(amici_model.get_parameter_ids())
180+
sensi_method = amici_solver.get_sensitivity_method()
181181

182182
# iterate over return data
183183
for data_ix, rdata in enumerate(rdatas):
@@ -213,7 +213,7 @@ def calculate_function_values(
213213
# Hessian
214214
if 2 in sensi_orders:
215215
if (
216-
sensi_method != amici.SensitivityMethod_forward
216+
sensi_method != amici.SensitivityMethod.forward
217217
or not fim_for_hess
218218
):
219219
raise ValueError("AMICI cannot compute Hessians yet.")

pypesto/petab/objective_creator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def _create_model(self) -> amici.Model:
170170
module = amici.import_model_module(
171171
module_name=self.model_name, module_path=self.output_folder
172172
)
173-
model = module.getModel()
173+
model = module.get_model()
174174
check_model(
175175
amici_model=model,
176176
petab_problem=self.petab_problem,
@@ -238,7 +238,7 @@ def create_solver(
238238
if model is None:
239239
model = self.create_model(verbose=verbose)
240240

241-
solver = model.getSolver()
241+
solver = model.create_solver()
242242
return solver
243243

244244
def create_edatas(

pypesto/predict/amici_predictor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def _default_output(
361361
to AMICI was successful (``status == 0``), before writing the output.
362362
"""
363363
amici_nt = [
364-
len(edata.getTimepoints())
364+
len(edata.get_timepoints())
365365
for edata in self.amici_objective.edatas
366366
]
367367
amici_ny = len(self.output_ids)

pypesto/visualize/model_fit.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def time_trajectory_model(
240240
problem = result.problem
241241
# add timepoints as needed
242242
if timepoints is None:
243-
end_time = max(problem.objective.edatas[0].getTimepoints())
243+
end_time = max(problem.objective.edatas[0].get_timepoints())
244244
timepoints = np.linspace(start=0, stop=end_time, num=n_timepoints)
245245

246246
# get rdatas
@@ -422,13 +422,13 @@ def _time_trajectory_model_with_states(
422422
axes = np.atleast_2d(axes)
423423

424424
for i_cond, rdata in enumerate(rdatas):
425-
amici.plotting.plotStateTrajectories(
425+
amici.plotting.plot_state_trajectories(
426426
rdata=rdata,
427427
state_indices=state_indices,
428428
ax=axes[i_cond, 0],
429429
model=model,
430430
)
431-
amici.plotting.plotObservableTrajectories(
431+
amici.plotting.plot_observable_trajectories(
432432
rdata=rdata,
433433
observable_indices=observable_indices,
434434
ax=axes[i_cond, 1],
@@ -468,13 +468,14 @@ def _time_trajectory_model_without_states(
468468
observable_indices = None
469469
if observable_ids is not None:
470470
observable_indices = [
471-
model.getObservableIds().index(obs_id) for obs_id in observable_ids
471+
model.get_observable_ids().index(obs_id)
472+
for obs_id in observable_ids
472473
]
473474

474475
fig, axes = plt.subplots(len(rdatas))
475476

476477
for i_cond, rdata in enumerate(rdatas):
477-
amici.plotting.plotObservableTrajectories(
478+
amici.plotting.plot_observable_trajectories(
478479
rdata=rdata,
479480
observable_indices=observable_indices,
480481
ax=axes[i_cond] if len(rdatas) > 1 else axes,

test/petab/test_petab_import.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_1_compile(self):
5656
)
5757

5858
# observable ids
59-
model_obs_ids = list(model.getObservableIds())
59+
model_obs_ids = list(model.get_observable_ids())
6060
problem_obs_ids = list(petab_problem.get_observable_ids())
6161
self.assertEqual(set(model_obs_ids), set(problem_obs_ids))
6262

@@ -123,11 +123,11 @@ def test_check_gradients(self):
123123
)
124124

125125
objective = importer.create_problem().objective
126-
objective.amici_solver.setSensitivityMethod(
127-
amici.SensitivityMethod_forward
126+
objective.amici_solver.set_sensitivity_method(
127+
amici.SensitivityMethod.forward
128128
)
129-
objective.amici_solver.setAbsoluteTolerance(1e-10)
130-
objective.amici_solver.setRelativeTolerance(1e-12)
129+
objective.amici_solver.set_absolute_tolerance(1e-10)
130+
objective.amici_solver.set_relative_tolerance(1e-12)
131131

132132
self.assertFalse(
133133
objective.check_gradients_match_finite_differences(
@@ -157,11 +157,11 @@ def test_plist_mapping():
157157
objective_creator.create_objective()
158158
)
159159
objective = problem.objective
160-
objective.amici_solver.setSensitivityMethod(
160+
objective.amici_solver.set_sensitivity_method(
161161
amici.SensitivityMethod.forward
162162
)
163-
objective.amici_solver.setAbsoluteTolerance(1e-16)
164-
objective.amici_solver.setRelativeTolerance(1e-15)
163+
objective.amici_solver.set_absolute_tolerance(1e-16)
164+
objective.amici_solver.set_relative_tolerance(1e-15)
165165

166166
# slightly perturb the parameters to avoid vanishing gradients
167167
par = np.asarray(petab_importer.petab_problem.x_nominal_free_scaled) * 1.01
@@ -187,7 +187,7 @@ def test_plist_mapping():
187187
# `plist` later on)
188188
fixed_model_par_ids = ["init_b10", "init_bcry"]
189189
fixed_model_par_idxs = [
190-
objective.amici_model.getParameterIds().index(id)
190+
objective.amici_model.get_parameter_ids().index(id)
191191
for id in fixed_model_par_ids
192192
]
193193
fixed_idxs = [problem.x_names.index(id) for id in fixed_ids]
@@ -226,13 +226,13 @@ def test_max_sensi_order():
226226
hess = objective(par, sensi_orders=(2,))
227227
assert hess.shape == (npar, npar)
228228
assert (hess != 0).any()
229-
objective.amici_solver.setSensitivityMethod(
230-
amici.SensitivityMethod_adjoint
229+
objective.amici_solver.set_sensitivity_method(
230+
amici.SensitivityMethod.adjoint
231231
)
232232
with pytest.raises(ValueError):
233233
objective(par, sensi_orders=(2,))
234-
objective.amici_solver.setSensitivityMethod(
235-
amici.SensitivityMethod_forward
234+
objective.amici_solver.set_sensitivity_method(
235+
amici.SensitivityMethod.forward
236236
)
237237

238238
# fix max_sensi_order to 1

test/visualize/test_visualize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,12 +1080,12 @@ def test_sampling_prediction_trajectories():
10801080
post_processor_amici_x = functools.partial(
10811081
post_processor,
10821082
output_type=pypesto.C.AMICI_X,
1083-
output_ids=result.problem.objective.amici_model.getStateIds(),
1083+
output_ids=result.problem.objective.amici_model.get_state_ids(),
10841084
)
10851085
predictor = predict.AmiciPredictor(
10861086
result.problem.objective,
10871087
post_processor=post_processor_amici_x,
1088-
output_ids=result.problem.objective.amici_model.getStateIds(),
1088+
output_ids=result.problem.objective.amici_model.get_state_ids(),
10891089
)
10901090

10911091
sample_ensemble = ensemble.Ensemble.from_sample(

tox.ini

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ deps =
5757
# with the pseudo-v2 format for pysb tests instead of `main`
5858
# git+https://github.com/PEtab-dev/petab_test_suite@main
5959
git+https://github.com/PEtab-dev/petab_test_suite@10ffb050380933b60ac192962bf9550a9df65a9c
60+
commands_pre =
61+
python3 -m pip uninstall -y amici
62+
python3 -m pip install git+https://github.com/AMICI-dev/amici.git@snakecase\#egg=amici&subdirectory=python/sdist
6063
commands =
6164
pytest --cov=pypesto --cov-report=xml --cov-append \
6265
test/base --durations=0 \
@@ -84,7 +87,7 @@ deps =
8487
# to skip re-installation, run `tox -e petab --override testenv:petab.commands_pre=`
8588
commands_pre =
8689
python3 -m pip uninstall -y amici
87-
python3 -m pip install git+https://github.com/AMICI-dev/amici.git@main\#egg=amici&subdirectory=python/sdist
90+
python3 -m pip install git+https://github.com/AMICI-dev/amici.git@snakecase\#egg=amici&subdirectory=python/sdist
8891
commands =
8992
# FIXME: Until we have proper PEtab v2 import
9093
# we need `10ffb050380933b60ac192962bf9550a9df65a9c`
@@ -125,6 +128,9 @@ commands =
125128
# workaround as ipopt has incomplete build
126129
pytest --cov=pypesto --cov-report=xml --cov-append \
127130
test/hierarchical
131+
commands_pre =
132+
python3 -m pip uninstall -y amici
133+
python3 -m pip install git+https://github.com/AMICI-dev/amici.git@snakecase\#egg=amici&subdirectory=python/sdist
128134
description =
129135
Test hierarchical optimization module
130136

@@ -135,6 +141,9 @@ commands =
135141
test/select
136142
description =
137143
Test model selection functionality
144+
commands_pre =
145+
python3 -m pip uninstall -y amici
146+
python3 -m pip install git+https://github.com/AMICI-dev/amici.git@snakecase\#egg=amici&subdirectory=python/sdist
138147

139148
[testenv:notebooks1]
140149
allowlist_externals = bash
@@ -143,6 +152,9 @@ commands =
143152
bash test/run_notebook.sh 1
144153
description =
145154
Run notebooks 1
155+
commands_pre =
156+
python3 -m pip uninstall -y amici
157+
python3 -m pip install git+https://github.com/AMICI-dev/amici.git@snakecase\#egg=amici&subdirectory=python/sdist
146158

147159
[testenv:notebooks2]
148160
allowlist_externals = bash
@@ -151,6 +163,9 @@ commands =
151163
bash test/run_notebook.sh 2
152164
description =
153165
Run notebooks 2
166+
commands_pre =
167+
python3 -m pip uninstall -y amici
168+
python3 -m pip install git+https://github.com/AMICI-dev/amici.git@snakecase\#egg=amici&subdirectory=python/sdist
154169

155170
# Management, docs
156171

@@ -161,6 +176,9 @@ commands =
161176
sphinx-build -W -b html doc/ doc/_build/html
162177
description =
163178
Test whether docs build passes
179+
commands_pre =
180+
python3 -m pip uninstall -y amici
181+
python3 -m pip install git+https://github.com/AMICI-dev/amici.git@snakecase\#egg=amici&subdirectory=python/sdist
164182

165183
[testenv:size]
166184
skip_install = true

0 commit comments

Comments
 (0)