Skip to content

Commit 1863690

Browse files
author
C.A.P. Linssen
committed
merge inhomogeneous and propagator singularity handling
1 parent 6458833 commit 1863690

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

odetoolbox/analytic_integrator.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,29 @@ def __init__(self, solver_dict, spike_times: Optional[Dict[str, List[float]]] =
9191

9292

9393
def _condition_holds(self, condition_string) -> bool:
94+
r"""Check boolean conditions of the form:
95+
96+
::
97+
98+
(p_1 && p_2 .. && p_k) || (q_1 && q_2 .. && q_j) || ...
99+
100+
"""
101+
for sub_condition_string in condition_string.split("||"):
102+
# if any of the subterms hold, the whole expression holds (OR-ed together)
103+
if self._and_condition_holds(sub_condition_string):
104+
return True
105+
106+
return False
107+
108+
109+
def _and_condition_holds(self, condition_string) -> bool:
110+
r"""Check boolean conditions of the form:
111+
112+
::
113+
114+
p_1 && p_2 .. && p_k
115+
116+
"""
94117
sub_conditions = condition_string.split("&&")
95118
for sub_condition_string in sub_conditions:
96119
sub_condition_string = sub_condition_string.strip().strip("()")
@@ -110,6 +133,7 @@ def _condition_holds(self, condition_string) -> bool:
110133
sub_condition_holds = equation.subs(self.solver_dict["parameters"])
111134

112135
if not sub_condition_holds:
136+
# if any of the subterms do not hold, the whole expression does not hold (AND-ed together)
113137
return False
114138

115139
return True

odetoolbox/system_of_shapes.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,25 @@ def _generate_propagator_matrix(self, A) -> sympy.Matrix:
226226

227227
return P
228228

229+
def _merge_conditions(self, solver_dict):
230+
r"""merge together conditions (a OR b OR c OR...) if the propagators and update_expressions are the same"""
231+
232+
for condition, sub_solver_dict in solver_dict["conditions"].items():
233+
for condition2, sub_solver_dict2 in solver_dict["conditions"].items():
234+
if condition == condition2:
235+
# don't check a condition against itself
236+
continue
237+
238+
if sub_solver_dict["propagators"] == sub_solver_dict2["propagators"] and sub_solver_dict["update_expressions"] == sub_solver_dict2["update_expressions"]:
239+
# ``condition`` and ``condition2`` can be merged
240+
solver_dict["conditions"]["(" + condition + ") || (" + condition2 + ")"] = sub_solver_dict
241+
solver_dict["conditions"].pop(condition)
242+
solver_dict["conditions"].pop(condition2)
243+
print("\n\n\n\n\n\nwqweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeen\n\n\n\n\n")
244+
return self._merge_conditions(solver_dict)
245+
246+
return solver_dict
247+
229248
def generate_propagator_solver(self, disable_singularity_detection: bool = False):
230249
r"""
231250
Generate the propagator matrix and symbolic expressions for propagator-based updates; return as JSON.
@@ -303,7 +322,7 @@ def generate_propagator_solver(self, disable_singularity_detection: bool = False
303322
solver_dict["conditions"][condition_str] = {"propagators": solver_dict_conditional["propagators"],
304323
"update_expressions": solver_dict_conditional["update_expressions"]}
305324

306-
# XXX: TODO: merge together conditions (a OR b OR c OR...) if the propagators and update_expressions are the same
325+
solver_dict = self._merge_conditions(solver_dict)
307326

308327
return solver_dict
309328

0 commit comments

Comments
 (0)