Skip to content

Commit

Permalink
Print exceptions raised during hardware sims
Browse files Browse the repository at this point in the history
Previously exceptions raised during hardware sims would hang
because a channel was expecting data to be read or written,
causing deadlock. This write bogus data to unstick the simulation
while printing the exception so it can be debugged.
  • Loading branch information
tbekolay committed Nov 11, 2018
1 parent 2645b7b commit a43f981
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion nengo_loihi/simulator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import OrderedDict
import logging
import traceback
import warnings

import numpy as np
Expand Down Expand Up @@ -485,7 +486,25 @@ def run_steps(self, steps):
raise SimulatorClosed("Simulator cannot run because it is closed.")
if self._run_steps is None:
self._make_run_steps()
self._run_steps(steps)
try:
self._run_steps(steps)
except Exception:
if "loihi" in self.sims and self.sims["loihi"].use_snips:
# Need to write to board, otherwise it will wait indefinitely
h2c = self.sims["loihi"].nengo_io_h2c
c2h = self.sims["loihi"].nengo_io_c2h

print(traceback.format_exc())
print("\nAttempting to end simulation...")

for _ in range(steps):
h2c.write(h2c.numElements, [0] * h2c.numElements)
c2h.read(c2h.numElements)
self.sims["loihi"].wait_for_completion()
self.sims["loihi"].n2board.nxDriver.stopExecution()
self.sims["loihi"].n2board.nxDriver.stopDriver()
raise

self._n_steps += steps
logger.info("Finished running for %d steps", steps)
self._probe()
Expand Down

0 comments on commit a43f981

Please sign in to comment.