Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added numba dfun for model #727

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

added numba dfun for model #727

wants to merge 3 commits into from

Conversation

DeLaVlag
Copy link
Collaborator

@DeLaVlag DeLaVlag commented Sep 3, 2024

Hi
I added the numba dfun as I was working on cosimulation for this model anyway.
Michiel.

@DeLaVlag DeLaVlag requested a review from maedoc September 3, 2024 11:06
For details refer to (Bandyopadhyay & Rabuffo et al. 2023)
"""

x = state_variables[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can probably tuple unpack this like

x, V, n, DKi, Kg = state_variables

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


# helper functions

def m_inf(V):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does numba compile this efficiently?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed decoration with @njit is more efficient

r = R_minus[0] * x / numpy.pi
Vdot = (-1.0 / Cm[0]) * (I_Na + I_K + I_Cl + I_pump)

if_xdot = Delta[0] + 2 * R_minus[0] * (V - c_minus[0]) * x - J[0] * r * x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to see these if else terms factored for readability. e.g.

Vsmall = V <= Vstar
RVc = where(Vsmall, R_minus[0]*(V-c_minus[0]), R_plus[0]*(V - c_plus[0]))
dx[0] = Delta[0] + 2*RVc*x - J[0]*r*x

or even better just

if V <= Vstar:
  R, c = R_minus[0], c_minus[0]
else:
  R, c = R_plus[0], c_plus[0]
dx[0] = Delta[0] + 2*R*(V - c)*x - J[0]*r*x

makes it clear that we're just switching two parameter values on the V <= Vstar branch not the whole expression

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. added the necessary reshapes also

if_Vdot = Vdot - R_minus[0] * x ** 2 + eta[0] + (R_minus[0] / numpy.pi) * Coupling_Term * (E[0] - V)
else_Vdot = Vdot - R_plus[0] * x ** 2 + eta[0] + (R_minus[0] / numpy.pi) * Coupling_Term * (E[0] - V)

dx[0] = numpy.where(V <= (Vstar * numpy.ones_like(V)), if_xdot, else_xdot)[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there a [0] at the end of this expression?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the np.where was removed and so the [0]

Copy link
Member

@maedoc maedoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some minor comments. I didn't check the math in the numba is the same as numpy, I trust you have checked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants