Skip to content

Commit

Permalink
Merge branch 'develop' into adjoint_event
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl authored Dec 14, 2023
2 parents 34fde49 + 594b07e commit 8ea8bdf
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
]
},
{
Expand Down
10 changes: 3 additions & 7 deletions python/sdist/amici/de_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions python/sdist/amici/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion python/sdist/amici/sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
DEModel,
_default_simplify,
smart_is_zero_matrix,
symbol_with_assumptions,
)
from .import_utils import (
RESERVED_SYMBOLS,
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions tests/benchmark-models/test_petab_benchmark.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Tests for simulate_petab on PEtab benchmark problems."""

import os
from pathlib import Path

import amici
Expand All @@ -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("*")
Expand Down
12 changes: 4 additions & 8 deletions tests/benchmark-models/test_petab_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging
import os
import sys
from pathlib import Path

import amici
import numpy as np
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 8ea8bdf

Please sign in to comment.