-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle voltage via instance specific copy. (#1532)
- Loading branch information
Showing
5 changed files
with
130 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
NEURON { | ||
SUFFIX accessors | ||
NONSPECIFIC_CURRENT il | ||
} | ||
|
||
ASSIGNED { | ||
v | ||
il | ||
} | ||
|
||
BREAKPOINT { | ||
il = 0.003 | ||
} | ||
|
||
|
||
FUNCTION get_voltage() { | ||
get_voltage = v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
NEURON { | ||
SUFFIX ode | ||
NONSPECIFIC_CURRENT il | ||
} | ||
|
||
ASSIGNED { | ||
il | ||
v | ||
} | ||
|
||
FUNCTION voltage() { | ||
voltage = 0.001 * v | ||
} | ||
|
||
BREAKPOINT { | ||
il = voltage() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
NEURON { | ||
SUFFIX state_ode | ||
NONSPECIFIC_CURRENT il | ||
} | ||
|
||
STATE { | ||
X | ||
} | ||
|
||
ASSIGNED { | ||
il | ||
v | ||
} | ||
|
||
INITIAL { | ||
X = v | ||
} | ||
|
||
BREAKPOINT { | ||
SOLVE eqn | ||
il = 0.001 * X | ||
} | ||
|
||
NONLINEAR eqn { LOCAL c | ||
c = rate() | ||
~ X = c | ||
} | ||
|
||
FUNCTION rate() { | ||
rate = v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from neuron import h, gui | ||
|
||
import numpy as np | ||
|
||
|
||
def test_voltage_access(): | ||
s = h.Section() | ||
s.insert("accessors") | ||
|
||
h.finitialize() | ||
v = s(0.5).v | ||
vinst = s(0.5).accessors.get_voltage() | ||
# The voltage will be consistent right after | ||
# finitialize. | ||
assert vinst == v | ||
|
||
for _ in range(4): | ||
v = s(0.5).v | ||
h.fadvance() | ||
vinst = s(0.5).accessors.get_voltage() | ||
|
||
# During timestepping the internal copy | ||
# of the voltage lags behind the current | ||
# voltage by some timestep. | ||
assert vinst == v, f"{vinst = }, {v = }, delta = {vinst - v}" | ||
|
||
|
||
def check_ode(mech_name, step): | ||
s = h.Section() | ||
s.insert(mech_name) | ||
|
||
h.finitialize() | ||
|
||
c = -0.001 / 1e-3 | ||
|
||
for _ in range(4): | ||
v_expected = step(s(0.5).v, c) | ||
h.fadvance() | ||
np.testing.assert_approx_equal(s(0.5).v, v_expected, significant=10) | ||
|
||
|
||
def test_breakpoint(): | ||
# Results in backward Euler. | ||
check_ode("ode", lambda v, c: (1.0 - c * h.dt) ** (-1.0) * v) | ||
|
||
|
||
def test_state(): | ||
# Effectively, the timing when states are computed results in backward Euler. | ||
check_ode("state_ode", lambda v, c: (1.0 + c * h.dt) * v) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_voltage_access() | ||
test_breakpoint() | ||
test_state() |