Skip to content

Commit

Permalink
changed time prop (neuronsimulator/nrn#1112)
Browse files Browse the repository at this point in the history
  • Loading branch information
Helveg committed Mar 23, 2021
1 parent d5a4916 commit 7fa59ed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ Python interfaces should be Pythonic, this wrapper offers just that:
- Correct garbage collection, objects connected to eachother don't
dissapear: Objects that rely on eachother store a reference to
eachother. As is the basis for any sane object oriented interface.
- Explicit exceptions: I catch silent failures and gotchas and raise
semantic errors with a class hierarchy instead for granular
exception handling.

**Warning:** When running MPI simulations errors cannot be caught due to a
[bug](https://github.com/neuronsimulator/nrn/issues/1112) in NEURON where every
exception results in NEURON calling `MPI_Abort` and shutting down the
simulation. If this leads to confusing failure modes please post an issue with
your Patch code to the GitHub repo!

# Basic usage

Expand Down
2 changes: 1 addition & 1 deletion patch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PythonHocModule(types.ModuleType):
transform_record = staticmethod(transform_record)
transform_arc = staticmethod(transform_arc)

__version__ = "3.0.0b4"
__version__ = "3.0.0b5"
__path__ = __path__

@property
Expand Down
22 changes: 8 additions & 14 deletions patch/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from .exceptions import *
from .error_handler import catch_hoc_error, CatchNetCon, CatchSectionAccess, _suppress_nrn
from functools import wraps
from functools import wraps, cached_property

# We don't need to reraise ImportErrors, they should be clear enough by themselves. If not
# and you're reading this: Fix the NEURON install, it's currently not importable ;)
Expand Down Expand Up @@ -229,20 +229,14 @@ def SEClamp(self, sec, x=0.5):
sec.__ref__(clamp)
return clamp

@property
@cached_property
def time(self):
if not hasattr(self, "_time"):
t = self.Vector()
# Fix for upstream NEURON bug. See https://github.com/neuronsimulator/nrn/issues/416
try:
with catch_hoc_error(CatchSectionAccess):
t.record(self._ref_t)
except HocSectionAccessError as e:
self.__dud_section = self.Section(name="this_is_here_to_record_time")
# Recurse to try again.
return self.time
self._time = t
return self._time
t = self.Vector()
# Fix for upstream NEURON bug. See https://github.com/neuronsimulator/nrn/issues/416
if not any(self.allsec()):
self.__dud_section = self.Section(name="this_is_here_to_record_time")
t.record(self._ref_t)
return t

def load_extension(self, extension): # pragma: nocover
if extension in self.__loaded_extensions:
Expand Down

0 comments on commit 7fa59ed

Please sign in to comment.