ioam / topographica

A general-purpose neural simulator focusing on topographic maps.
topographica.org
BSD 3-Clause "New" or "Revised" License
53 stars 32 forks source link

Floating point error if optimized code used #689

Open fcr opened 5 years ago

fcr commented 5 years ago

Run GCAL_Tutorial.ipynb after building the optimized code. During the stage of "Rebuilding snapshot 'lissom_oo_or_10000.typ' " generally get:

FloatingPointError Traceback (most recent call last)

in () 9 model_dir = param.resolve_path('examples' if model=='GCAL' else 'models', path_to_file=False) 10 runscript(os.path.join(model_dir, basename + ".ty")) # Load the model ---> 11 topo.sim.views = c(times=times) 12 save_snapshot(snapshot_name) 13 /Users/fred/Development/topographica/external/featuremapper/featuremapper/collector.pyc in __call__(self, attrtree, times, strict) 541 try: 542 for i, t in enumerate(np.diff(times)): --> 543 interval_hook(float(t)) 544 545 # An empty attrtree buffer stops analysis repeatedly /Users/fred/Development/topographica/external/holoviews/holoviews/ipython/widgets.pyc in __call__(self, value) 203 remaining = value - completed 204 if remaining != 0: --> 205 self.run_hook(remaining) 206 super(RunProgress, self).__call__(100) 207 /Users/fred/Development/topographica/topo/base/simulation.pyc in run(self, duration, until) 1345 event = self.events.pop(0) 1346 self.debug("Delivering %s",event) -> 1347 event(self) 1348 did_event=True 1349 /Users/fred/Development/topographica/topo/base/simulation.pyc in __call__(self, sim) 446 447 def __call__(self,sim): --> 448 self.conn.dest.input_event(self.conn,self.data) 449 450 def __repr__(self): /Users/fred/Development/topographica/topo/sheet/__init__.pyc in input_event(self, conn, data) 314 proj.activity *= 0.0 315 self.mask.reset() --> 316 super(SettlingCFSheet,self).input_event(conn,data) 317 318 /Users/fred/Development/topographica/topo/base/projection.pyc in input_event(self, conn, data) 467 """ 468 self.verbose("Received input from %s on dest_port %s via connection %s.", conn.src.name,conn.dest_port,conn.name) --> 469 self.present_input(data,conn) 470 self.new_input = True 471 /Users/fred/Development/topographica/topo/base/projection.pyc in present_input(self, input_activity, conn) 596 is called. 597 """ --> 598 conn.activate(input_activity) 599 600 /Users/fred/Development/topographica/topo/base/cf.pyc in activate(self, input_activity) 811 iaf(input_activity) 812 self.input_buffer = input_activity --> 813 self.activity *=0.0 814 self.response_fn(CFIter(self), input_activity, self.activity, self.strength) 815 for of in self.output_fns: FloatingPointError: invalid value encountered in multiply Note that this does not occur if the non optimized code is used (but the process takes forever).
philippjfr commented 5 years ago

Presumably the optimized code is the weave version of the code? Maybe you could try to switch to the cythonized version in that case. You can see those being added here: https://github.com/ioam/topographica/blob/f945a8b9fc307a3a32c4fe1296a3e1e37b5491a1/topo/submodel/scal.py#L217

fcr commented 5 years ago

AFAIK I am using the Cython code:

python setup.py build_ext In file included from /Users/fred/anaconda/envs/python2/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1818:0, from /Users/fred/anaconda/envs/python2/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:18, from /Users/fred/anaconda/envs/python2/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4, from topo/optimized/optimized.c:567: /Users/fred/anaconda/envs/python2/lib/python2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

warning "Using deprecated NumPy API, disable it by " \

^~~ cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++

fcr commented 5 years ago

Correction. Okay, seems that weave was active. I just remembered that I installed weave when I was first trying to run topographica a few weeks ago, after I ran the LISSOM tutorial and I got this message: "Caution: Unable to import Weave. Will use non-optimized versions of most components. Note: Inline-optimized components are currently disabled; see topo.misc.inlinec".

This was in spite of building with Cython as you saw in my previous message. This is my first time encountering weave.

When I uninstall weave I get back the "Unable to import Weave" message again.

Now that you showed how to activate the cython code in the model I'll give it a try.

fcr commented 5 years ago

Ran with the Cython code. Got the same error: `FloatingPointError Traceback (most recent call last)

in () 11 print(model_path) 12 runscript(model_path) # Load the model ---> 13 topo.sim.views = c(times=times) 14 save_snapshot(snapshot_name) 15 /Users/fred/Development/topographica/external/featuremapper/featuremapper/collector.pyc in __call__(self, attrtree, times, strict) 541 try: 542 for i, t in enumerate(np.diff(times)): --> 543 interval_hook(float(t)) 544 545 # An empty attrtree buffer stops analysis repeatedly /Users/fred/Development/topographica/external/holoviews/holoviews/ipython/widgets.pyc in __call__(self, value) 203 remaining = value - completed 204 if remaining != 0: --> 205 self.run_hook(remaining) 206 super(RunProgress, self).__call__(100) 207 /Users/fred/Development/topographica/topo/base/simulation.pyc in run(self, duration, until) 1345 event = self.events.pop(0) 1346 self.debug("Delivering %s",event) -> 1347 event(self) 1348 did_event=True 1349 /Users/fred/Development/topographica/topo/base/simulation.pyc in __call__(self, sim) 446 447 def __call__(self,sim): --> 448 self.conn.dest.input_event(self.conn,self.data) 449 450 def __repr__(self): /Users/fred/Development/topographica/topo/sheet/__init__.pyc in input_event(self, conn, data) 314 proj.activity *= 0.0 315 self.mask.reset() --> 316 super(SettlingCFSheet,self).input_event(conn,data) 317 318 /Users/fred/Development/topographica/topo/base/projection.pyc in input_event(self, conn, data) 467 """ 468 self.verbose("Received input from %s on dest_port %s via connection %s.", conn.src.name,conn.dest_port,conn.name) --> 469 self.present_input(data,conn) 470 self.new_input = True 471 /Users/fred/Development/topographica/topo/base/projection.pyc in present_input(self, input_activity, conn) 596 is called. 597 """ --> 598 conn.activate(input_activity) 599 600 /Users/fred/Development/topographica/topo/base/cf.pyc in activate(self, input_activity) 811 iaf(input_activity) 812 self.input_buffer = input_activity --> 813 self.activity *=0.0 814 self.response_fn(CFIter(self), input_activity, self.activity, self.strength) 815 for of in self.output_fns: FloatingPointError: invalid value encountered in multiply`