diff --git a/CHANGELOG.md b/CHANGELOG.md index b3ff0593a2..6d025f1aa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## v0.X Series +### v0.11.31 (2022-07-12) + +Fixes: +* Fixed `ParameterMapping.__getitem__` to either return a + `ParameterMappingForCondition` or a new `ParameterMapping`, but not a list + by @dweindl in https://github.com/AMICI-dev/AMICI/pull/1826 + ### v0.11.30 (2022-07-07) Features: diff --git a/python/amici/parameter_mapping.py b/python/amici/parameter_mapping.py index 85969ed386..512c969da1 100644 --- a/python/amici/parameter_mapping.py +++ b/python/amici/parameter_mapping.py @@ -13,7 +13,7 @@ for usage together with PEtab, for which the whole workflow of generating the mapping is automatized. """ - +from __future__ import annotations import numbers import warnings @@ -136,8 +136,13 @@ def __init__( def __iter__(self): yield from self.parameter_mappings - def __getitem__(self, item): - return self.parameter_mappings[item] + def __getitem__( + self, item + ) -> Union[ParameterMapping, ParameterMappingForCondition]: + result = self.parameter_mappings[item] + if isinstance(result, ParameterMappingForCondition): + return result + return ParameterMapping(result) def __len__(self): return len(self.parameter_mappings) diff --git a/python/tests/test_parameter_mapping.py b/python/tests/test_parameter_mapping.py index 73f72eef8e..725e7e78cd 100644 --- a/python/tests/test_parameter_mapping.py +++ b/python/tests/test_parameter_mapping.py @@ -55,3 +55,6 @@ def test_parameter_mapping(): parameter_mapping.append(par_map_for_condition) assert len(parameter_mapping) == 1 + + assert isinstance(parameter_mapping[0], ParameterMappingForCondition) + assert isinstance(parameter_mapping[:], ParameterMapping) diff --git a/tests/benchmark-models/test_petab_model.py b/tests/benchmark-models/test_petab_model.py index 935065d10f..3a43c84347 100755 --- a/tests/benchmark-models/test_petab_model.py +++ b/tests/benchmark-models/test_petab_model.py @@ -3,8 +3,8 @@ """ Simulate a PEtab problem and compare results to reference values """ - import argparse +import contextlib import importlib import logging import os @@ -15,7 +15,7 @@ from amici.logging import get_logger from amici.petab_objective import (simulate_petab, rdatas_to_measurement_df, LLH, RDATAS) -from petab.visualize import plot_petab_problem +from petab.visualize import plot_problem logger = get_logger(f"amici.{__name__}", logging.WARNING) @@ -56,9 +56,7 @@ def parse_cli_args(): help='File to write simulation result to, in PEtab' 'measurement table format.') - args = parser.parse_args() - - return args + return parser.parse_args() def main(): @@ -103,21 +101,17 @@ def main(): sim_df.to_csv(index=False, sep="\t") if args.plot: - try: + with contextlib.suppress(NotImplementedError): # visualize fit - axs = plot_petab_problem(petab_problem=problem, sim_data=sim_df) + axs = plot_problem(petab_problem=problem, simulations_df=sim_df) # save figure for plot_id, ax in axs.items(): fig_path = os.path.join(args.model_directory, - args.model_name + "_" + plot_id - + "_vis.png") + f"{args.model_name}_{plot_id}_vis.png") logger.info(f"Saving figure to {fig_path}") ax.get_figure().savefig(fig_path, dpi=150) - except NotImplementedError: - pass - if args.check: references_yaml = os.path.join(os.path.dirname(__file__), "benchmark_models.yaml") diff --git a/version.txt b/version.txt index f41aa7fad3..487397bd7b 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.11.30 +0.11.31