Skip to content

Commit f493de2

Browse files
performance improvement to linearity check for rush-larsen using caching (#224)
* performance improvement to linearity check for rush-larsen using caching
1 parent 697fc46 commit f493de2

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ authors:
2323
given-names: "Gary R."
2424

2525
title: "chaste-codegen"
26-
version: 0.9.1
26+
version: 0.9.3
2727
doi: 10.5281/zenodo.5517000
2828
date-released: 2021-09-20
2929
url: "https://github.com/ModellingWebLab/chaste-codegen"

RELEASE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Release 0.9.3
2+
- Performance upgrade for `--rush-larsen` using caching on linearity checking.
3+
14
# Release 0.9.2
25
- Corrected a typo in command line argument `--skip-ingularity-fixes` renaming it to `--skip-singularity-fixes`
36

chaste_codegen/_linearity_check.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from enum import Enum
2+
from functools import lru_cache
23

34
from cellmlmanip.model import Variable
45
from sympy import (
@@ -26,6 +27,7 @@ class KINDS(Enum):
2627
NONLINEAR = 3
2728

2829

30+
@lru_cache(maxsize=128)
2931
def _check_expr(expr, state_var, membrane_voltage_var, state_vars):
3032
"""Check the kind of expression given (NONE, LINEAR or NONLINEAR)
3133
@@ -38,6 +40,7 @@ def _check_expr(expr, state_var, membrane_voltage_var, state_vars):
3840
:param state_vars: the state variables in the model the expression comes from
3941
:return: the kind of expr (NONE, LINEAR or NONLINEAR)
4042
"""
43+
@lru_cache(maxsize=128)
4144
def max_kind(state_var, operands):
4245
result = KINDS.NONE
4346
for op in operands:
@@ -126,7 +129,7 @@ def get_non_linear_state_vars(derivative_equations, membrane_voltage_var, state_
126129
return set([eq.lhs.args[0] for eq in derivative_equations
127130
if isinstance(eq.lhs, Derivative) and
128131
eq.lhs.args[0] != membrane_voltage_var and
129-
_check_expr(eq.rhs, eq.lhs.args[0], membrane_voltage_var, state_vars) != KINDS.LINEAR])
132+
_check_expr(eq.rhs, eq.lhs.args[0], membrane_voltage_var, tuple(state_vars)) != KINDS.LINEAR])
130133

131134

132135
def subst_deriv_eqs_non_linear_vars(y_derivatives, non_linear_state_vars, membrane_voltage_var, state_vars,

chaste_codegen/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.2
1+
0.9.3

0 commit comments

Comments
 (0)