Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Raise exception when the voltage becomes unrealistic during a neuron simulation #387

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bluepyopt/ephys/protocols.py
Original file line number Diff line number Diff line change
@@ -171,7 +171,10 @@ def _run_func(self, cell_model, param_values, sim=None):
self.instantiate(sim=sim, icell=cell_model.icell)

try:
sim.run(self.total_duration, cvode_active=self.cvode_active)
sim.run(
self.total_duration,
cvode_active=self.cvode_active,
icell=cell_model.icell)
except (RuntimeError, simulators.NrnSimulatorException):
logger.debug(
'SweepProtocol: Running of parameter set {%s} generated '
14 changes: 12 additions & 2 deletions bluepyopt/ephys/simulators.py
Original file line number Diff line number Diff line change
@@ -112,12 +112,19 @@ def neuron(self):

return neuron

def check_voltage_valid(self, icell, voltage_bound=200.):
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this dangerous though. Ideally NEURON should detect if it gets values that it can't handle. Do we know what the effect this has on optimizations? I wouldn't be surprised if a lot of initial solutions might be out of bounds here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok,I will open an issue in Neuron

Copy link
Contributor

Choose a reason for hiding this comment

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

Any news?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The engineer who was looking into it is just back from vacation. He will resume working on it.

"""Raises exception if voltage at soma is out of bound"""

if icell and abs(icell.soma[0](0.5).v) > voltage_bound:
raise NrnSimulatorException('Membrane potential is out of bound')

def run(
self,
tstop=None,
dt=None,
cvode_active=None,
random123_globalindex=None):
random123_globalindex=None,
icell=None):
"""Run protocol"""

self.neuron.h.tstop = tstop
@@ -163,7 +170,10 @@ def run(
rng.Random123_globalindex(random123_globalindex)

try:
self.neuron.h.run()
self.neuron.h.finitialize()
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure this 'exactly' replicates the 'run()' behavior of Neuron? We don't want to change results if not necessary.

while self.neuron.h.t < self.neuron.h.tstop:
self.neuron.h.fadvance()
self.check_voltage_valid(icell)
Copy link
Contributor

Choose a reason for hiding this comment

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

We also need to check how this affects the simulation time.

except Exception as e:
raise NrnSimulatorException('Neuron simulator error', e)