|
9 | 9 | import re |
10 | 10 | from collections.abc import Callable, Sequence |
11 | 11 | from itertools import chain |
| 12 | +from operator import itemgetter |
12 | 13 | from typing import TYPE_CHECKING |
13 | 14 |
|
14 | 15 | import numpy as np |
@@ -798,12 +799,16 @@ def num_events(self) -> int: |
798 | 799 |
|
799 | 800 | def num_events_solver(self) -> int: |
800 | 801 | """ |
801 | | - Number of Events. |
| 802 | + Number of Events that rely on numerical root-finding. |
802 | 803 |
|
803 | 804 | :return: |
804 | 805 | number of event symbols (length of the root vector in AMICI) |
805 | 806 | """ |
806 | | - constant_syms = set(self.sym("k")) | set(self.sym("p")) |
| 807 | + constant_syms = ( |
| 808 | + set(self.sym("k")) |
| 809 | + | set(self.sym("p")) |
| 810 | + | set(itemgetter(*self.static_indices("w"))(self.sym("w"))) |
| 811 | + ) |
807 | 812 | return sum( |
808 | 813 | not event.has_explicit_trigger_times(constant_syms) |
809 | 814 | for event in self.events() |
@@ -1307,13 +1312,12 @@ def parse_events(self) -> None: |
1307 | 1312 | # add roots of heaviside functions |
1308 | 1313 | self.add_component(root) |
1309 | 1314 |
|
1310 | | - # # Substitute 'w' expressions into root expressions, to avoid rewriting |
1311 | | - # # 'root.cpp' and 'stau.cpp' headers to include 'w.h'. |
1312 | | - # for event in self.events(): |
1313 | | - # event.set_val(event.get_val().subs(w_toposorted)) |
1314 | | - |
1315 | 1315 | # re-order events - first those that require root tracking, then the others |
1316 | | - constant_syms = set(self.sym("k")) | set(self.sym("p")) |
| 1316 | + constant_syms = ( |
| 1317 | + set(self.sym("k")) |
| 1318 | + | set(self.sym("p")) |
| 1319 | + | set(itemgetter(*self.static_indices("w"))(self.sym("w"))) |
| 1320 | + ) |
1317 | 1321 | self._events = list( |
1318 | 1322 | chain( |
1319 | 1323 | itertools.filterfalse( |
@@ -2506,11 +2510,6 @@ def _process_heavisides( |
2506 | 2510 | heavisides = [] |
2507 | 2511 | # run through the expression tree and get the roots |
2508 | 2512 | tmp_roots_old = self._collect_heaviside_roots((dxdt,)) |
2509 | | - # TODO remove: substitute 'w' symbols in the root expression by their equations, |
2510 | | - # because currently, |
2511 | | - # 1) root functions must not depend on 'w' |
2512 | | - # FIXME 2) the check for time-dependence currently assumes only state |
2513 | | - # variables are implicitly time-dependent |
2514 | 2513 | for tmp_root_old, tmp_x0_old in unique_preserve_order(tmp_roots_old): |
2515 | 2514 | # we want unique identifiers for the roots |
2516 | 2515 | tmp_root_new = self._get_unique_root(tmp_root_old, roots) |
|
0 commit comments