Skip to content
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

Certain models may fail in direct mode #1178

Closed
jgosmann opened this issue Oct 11, 2016 · 0 comments · Fixed by #1286
Closed

Certain models may fail in direct mode #1178

jgosmann opened this issue Oct 11, 2016 · 0 comments · Fixed by #1286

Comments

@jgosmann
Copy link
Collaborator

I'm trying to run Spaun in direct mode (just for benchmarking, I don't care whether the behaviour is replicated), but I am getting an exception. I didn't look into Spaun itself for the cause of this problem, but I have a minimal example that at least gives the similar exception.

Consider this network:

with nengo.Network() as model:
    e1 = nengo.Ensemble(50, 1)
    e2 = nengo.Ensemble(50, 1)
    nengo.Connection(e1, e2, function=lambda x: 1. / x)

Running this will work fine. Yes, there might be a division by 0 and the output may be way off, but it will run because the network is just producing spikes, filtering them, and multiplying them with some weights. No actual division is performed. But when I switch the first ensemble to direct mode like this:

e1.neuron_type = nengo.Direct()

This exception will be produced when running because an actual divison by 0 is performed which feeds nan values to the neuron code:

FloatingPointError                        Traceback (most recent call last)
<ipython-input-52-83cea7b88218> in <module>()
      1 with nengo.Simulator(model) as sim:
----> 2     sim.run(1.)

/home/jgosmann/.pyenv/versions/3.5.2/lib/python3.5/site-packages/nengo/simulator.py in run(self, time_in_seconds, progress_bar)
    259         logger.info("Running %s for %f seconds, or %d steps",
    260                     self.model.label, time_in_seconds, steps)
--> 261         self.run_steps(steps, progress_bar=progress_bar)
    262 
    263     def run_steps(self, steps, progress_bar=True):

/home/jgosmann/.pyenv/versions/3.5.2/lib/python3.5/site-packages/nengo/simulator.py in run_steps(self, steps, progress_bar)
    279         with ProgressTracker(steps, progress_bar) as progress:
    280             for i in range(steps):
--> 281                 self.step()
    282                 progress.step()
    283 

/home/jgosmann/.pyenv/versions/3.5.2/lib/python3.5/site-packages/nengo/simulator.py in step(self)
    290         try:
    291             for step_fn in self._steps:
--> 292                 step_fn()
    293         finally:
    294             np.seterr(**old_err)

/home/jgosmann/.pyenv/versions/3.5.2/lib/python3.5/site-packages/nengo/builder/neurons.py in step_simneurons()
     66 
     67         def step_simneurons():
---> 68             self.neurons.step_math(dt, J, output, *states)
     69         return step_simneurons
     70 

/home/jgosmann/.pyenv/versions/3.5.2/lib/python3.5/site-packages/nengo/neurons.py in step_math(self, dt, J, spiked, voltage, refractory_time)
    319         # set v(0) = 1 and solve for t to compute the spike time
    320         t_spike = dt + self.tau_rc * np.log1p(
--> 321             -(voltage[spiked_mask] - 1) / (J[spiked_mask] - 1))
    322 
    323         # set spiked voltages to zero, refractory times to tau_ref, and

FloatingPointError: invalid value encountered in true_divide

I think we should handle this more gracefully. But I'm not sure whether to convert all nan values in direct mode to some fixed number or provide an option to do that. Also note, that the exception right now is not helpful in providing a pointer what the actual problem is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants