-
Notifications
You must be signed in to change notification settings - Fork 105
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
base: master
Are you sure you want to change the base?
Conversation
For details refer to (Bandyopadhyay & Rabuffo et al. 2023) | ||
""" | ||
|
||
x = state_variables[0] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]
There was a problem hiding this 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.
Hi
I added the numba dfun as I was working on cosimulation for this model anyway.
Michiel.