diff --git a/python/examples/example_splines_swameye/ExampleSplinesSwameye2003.ipynb b/python/examples/example_splines_swameye/ExampleSplinesSwameye2003.ipynb index 2a3c113bc7..e8b75e49aa 100644 --- a/python/examples/example_splines_swameye/ExampleSplinesSwameye2003.ipynb +++ b/python/examples/example_splines_swameye/ExampleSplinesSwameye2003.ipynb @@ -101,11 +101,11 @@ "source": [ "# If running as a GitHub action, just do the minimal amount of work required to check whether the code is working\n", "if os.getenv(\"GITHUB_ACTIONS\") is not None:\n", - " n_starts = 15\n", + " n_starts = 25\n", " pypesto_optimizer = pypesto.optimize.FidesOptimizer(\n", " verbose=logging.WARNING, options=dict(maxiter=10)\n", " )\n", - " pypesto_engine = pypesto.engine.SingleCoreEngine()" + " pypesto_engine = pypesto.engine.MultiProcessEngine()" ] }, { diff --git a/python/sdist/amici/de_export.py b/python/sdist/amici/de_export.py index b2a56d20c1..80bcb3f068 100644 --- a/python/sdist/amici/de_export.py +++ b/python/sdist/amici/de_export.py @@ -58,8 +58,8 @@ generate_flux_symbol, smart_subs_dict, strip_pysb, - symbol_with_assumptions, toposort_symbols, + unique_preserve_order, ) from .logging import get_logger, log_execution_time, set_log_level @@ -2844,16 +2844,12 @@ def _process_heavisides( :returns: dxdt with Heaviside functions replaced by amici helper variables """ - - # expanding the rhs will in general help to collect the same - # heaviside function - dt_expanded = dxdt.expand() # track all the old Heaviside expressions in tmp_roots_old # replace them later by the new expressions heavisides = [] # run through the expression tree and get the roots - tmp_roots_old = self._collect_heaviside_roots(dt_expanded.args) - for tmp_old in tmp_roots_old: + tmp_roots_old = self._collect_heaviside_roots(dxdt.args) + for tmp_old in unique_preserve_order(tmp_roots_old): # we want unique identifiers for the roots tmp_new = self._get_unique_root(tmp_old, roots) # `tmp_new` is None if the root is not time-dependent. diff --git a/python/sdist/amici/import_utils.py b/python/sdist/amici/import_utils.py index ce23fd9712..5d800f1433 100644 --- a/python/sdist/amici/import_utils.py +++ b/python/sdist/amici/import_utils.py @@ -734,5 +734,20 @@ def strip_pysb(symbol: sp.Basic) -> sp.Basic: return symbol +def unique_preserve_order(seq: Sequence) -> list: + """Return a list of unique elements in Sequence, keeping only the first + occurrence of each element + + Parameters: + seq: Sequence to prune + + Returns: + List of unique elements in ``seq`` + """ + seen = set() + seen_add = seen.add + return [x for x in seq if not (x in seen or seen_add(x))] + + sbml_time_symbol = symbol_with_assumptions("time") amici_time_symbol = symbol_with_assumptions("t") diff --git a/python/sdist/amici/sbml_import.py b/python/sdist/amici/sbml_import.py index dd24b98cf8..b6a7b37ed4 100644 --- a/python/sdist/amici/sbml_import.py +++ b/python/sdist/amici/sbml_import.py @@ -38,7 +38,6 @@ DEModel, _default_simplify, smart_is_zero_matrix, - symbol_with_assumptions, ) from .import_utils import ( RESERVED_SYMBOLS, @@ -54,6 +53,7 @@ sbml_time_symbol, smart_subs, smart_subs_dict, + symbol_with_assumptions, toposort_symbols, ) from .logging import get_logger, log_execution_time, set_log_level diff --git a/tests/benchmark-models/test_petab_benchmark.py b/tests/benchmark-models/test_petab_benchmark.py old mode 100755 new mode 100644 index d0a783e2c4..753c88e500 --- a/tests/benchmark-models/test_petab_benchmark.py +++ b/tests/benchmark-models/test_petab_benchmark.py @@ -1,5 +1,5 @@ """Tests for simulate_petab on PEtab benchmark problems.""" - +import os from pathlib import Path import amici @@ -13,13 +13,13 @@ ATOL: float = 1e-3 RTOL: float = 1e-2 -benchmark_path = ( - Path(__file__).parent.parent.parent - / "Benchmark-Models-PEtab" - / "Benchmark-Models" -) +repo_root = Path(__file__).parent.parent.parent +benchmark_path = repo_root / "Benchmark-Models-PEtab" / "Benchmark-Models" +if not benchmark_path.exists(): + benchmark_path = Path(os.environ["BENCHMARK_COLLECTION"]) + # reuse compiled models from test_benchmark_collection.sh -benchmark_outdir = Path(__file__).parent.parent.parent / "test_bmc" +benchmark_outdir = repo_root / "test_bmc" models = [ str(petab_path.stem) for petab_path in benchmark_path.glob("*") diff --git a/tests/benchmark-models/test_petab_model.py b/tests/benchmark-models/test_petab_model.py index 911c19eaa9..8f52a341c4 100755 --- a/tests/benchmark-models/test_petab_model.py +++ b/tests/benchmark-models/test_petab_model.py @@ -9,6 +9,7 @@ import logging import os import sys +from pathlib import Path import amici import numpy as np @@ -100,7 +101,7 @@ def parse_cli_args(): def main(): """Simulate the model specified on the command line""" - + script_dir = Path(__file__).parent.absolute() args = parse_cli_args() loglevel = logging.DEBUG if args.verbose else logging.INFO logger.setLevel(loglevel) @@ -168,10 +169,7 @@ def main(): times["np"] = sum(problem.parameter_df[petab.ESTIMATE]) - pd.Series(times).to_csv( - f"./tests/benchmark-models/{args.model_name}_benchmark.csv" - ) - + pd.Series(times).to_csv(script_dir / f"{args.model_name}_benchmark.csv") for rdata in rdatas: assert ( rdata.status == amici.AMICI_SUCCESS @@ -201,9 +199,7 @@ def main(): ax.get_figure().savefig(fig_path, dpi=150) if args.check: - references_yaml = os.path.join( - os.path.dirname(__file__), "benchmark_models.yaml" - ) + references_yaml = script_dir / "benchmark_models.yaml" with open(references_yaml) as f: refs = yaml.full_load(f)