Skip to content

Commit

Permalink
performance improvement to linearity check for rush-larsen using cach…
Browse files Browse the repository at this point in the history
…ing (#224)

* performance improvement to linearity check for rush-larsen using caching
  • Loading branch information
MauriceHendrix committed Jan 20, 2022
1 parent 697fc46 commit f493de2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ authors:
given-names: "Gary R."

title: "chaste-codegen"
version: 0.9.1
version: 0.9.3
doi: 10.5281/zenodo.5517000
date-released: 2021-09-20
url: "https://github.com/ModellingWebLab/chaste-codegen"
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Release 0.9.3
- Performance upgrade for `--rush-larsen` using caching on linearity checking.

# Release 0.9.2
- Corrected a typo in command line argument `--skip-ingularity-fixes` renaming it to `--skip-singularity-fixes`

Expand Down
5 changes: 4 additions & 1 deletion chaste_codegen/_linearity_check.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from functools import lru_cache

from cellmlmanip.model import Variable
from sympy import (
Expand Down Expand Up @@ -26,6 +27,7 @@ class KINDS(Enum):
NONLINEAR = 3


@lru_cache(maxsize=128)
def _check_expr(expr, state_var, membrane_voltage_var, state_vars):
"""Check the kind of expression given (NONE, LINEAR or NONLINEAR)
Expand All @@ -38,6 +40,7 @@ def _check_expr(expr, state_var, membrane_voltage_var, state_vars):
:param state_vars: the state variables in the model the expression comes from
:return: the kind of expr (NONE, LINEAR or NONLINEAR)
"""
@lru_cache(maxsize=128)
def max_kind(state_var, operands):
result = KINDS.NONE
for op in operands:
Expand Down Expand Up @@ -126,7 +129,7 @@ def get_non_linear_state_vars(derivative_equations, membrane_voltage_var, state_
return set([eq.lhs.args[0] for eq in derivative_equations
if isinstance(eq.lhs, Derivative) and
eq.lhs.args[0] != membrane_voltage_var and
_check_expr(eq.rhs, eq.lhs.args[0], membrane_voltage_var, state_vars) != KINDS.LINEAR])
_check_expr(eq.rhs, eq.lhs.args[0], membrane_voltage_var, tuple(state_vars)) != KINDS.LINEAR])


def subst_deriv_eqs_non_linear_vars(y_derivatives, non_linear_state_vars, membrane_voltage_var, state_vars,
Expand Down
2 changes: 1 addition & 1 deletion chaste_codegen/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.2
0.9.3

0 comments on commit f493de2

Please sign in to comment.