Comments (5)
Hi @tim-ufer. Thanks for the report, but I think we fixed this about 2 years ago with #1273. With which version of Brian are you seeing this issue?
from brian2.
I have brian==2.5.1 installed via pip. Having numpy versions >= 1.20 causes the aforementioned errors. This has happened on multiple machines if that's relevant
from brian2.
Here's the full traceback. Looks like there's at least one use of np.float
left in units/fundamentalunits.py:1600
but when checking the file in question on master, it's just float
. So I suppose the actual question is why older versions of this file are ending up in the 2.5.1 pypi distribution?
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File ~\.envs\py_snn\lib\site-packages\IPython\core\formatters.py:342, in BaseFormatter.__call__(self, obj)
340 method = get_real_method(obj, self.print_method)
341 if method is not None:
--> 342 return method()
343 return None
344 else:
File ~\.envs\py_snn\lib\site-packages\brian2\units\fundamentalunits.py:1629, in Quantity._repr_latex_(self)
1628 def _repr_latex_(self):
-> 1629 return f"${latex(self)}$"
File ~\.envs\py_snn\lib\site-packages\sympy\printing\printer.py:372, in _PrintFunction.__call__(self, *args, **kwargs)
371 def __call__(self, *args, **kwargs):
--> 372 return self.__wrapped__(*args, **kwargs)
File ~\.envs\py_snn\lib\site-packages\sympy\printing\latex.py:3140, in latex(expr, **settings)
2928 @print_function(LatexPrinter)
2929 def latex(expr, **settings):
2930 r"""Convert the given expression to LaTeX string representation.
2931
2932 Parameters
(...)
3138
3139 """
-> 3140 return LatexPrinter(settings).doprint(expr)
File ~\.envs\py_snn\lib\site-packages\sympy\printing\latex.py:264, in LatexPrinter.doprint(self, expr)
263 def doprint(self, expr) -> str:
--> 264 tex = Printer.doprint(self, expr)
266 if self._settings['mode'] == 'plain':
267 return tex
File ~\.envs\py_snn\lib\site-packages\sympy\printing\printer.py:292, in Printer.doprint(self, expr)
290 def doprint(self, expr):
291 """Returns printer's representation for expr (as a string)"""
--> 292 return self._str(self._print(expr))
File ~\.envs\py_snn\lib\site-packages\sympy\printing\printer.py:309, in Printer._print(self, expr, **kwargs)
303 try:
304 # If the printer defines a name for a printing method
305 # (Printer.printmethod) and the object knows for itself how it
306 # should be printed, use that method.
307 if (self.printmethod and hasattr(expr, self.printmethod)
308 and not isinstance(expr, BasicMeta)):
--> 309 return getattr(expr, self.printmethod)(self, **kwargs)
311 # See if the class of expr is known, or if one of its super
312 # classes is known, and use that print function
313 # Exception: ignore the subclasses of Undefined, so that, e.g.,
314 # Function('gamma') does not get dispatched to _print_gamma
315 classes = type(expr).__mro__
File ~\.envs\py_snn\lib\site-packages\brian2\units\fundamentalunits.py:1600, in Quantity._latex(self, expr)
1598 threshold = np.get_printoptions()['threshold'] // 100
1599 if unitless.ndim == 0:
-> 1600 sympy_quantity = np.float(unitless)
1601 elif unitless.ndim == 1:
1602 array_str = np.array2string(unitless, separator=" & ", threshold=threshold,
1603 max_line_width=sys.maxsize)
File ~\.envs\py_snn\lib\site-packages\numpy\__init__.py:305, in __getattr__(attr)
300 warnings.warn(
301 f"In the future `np.{attr}` will be defined as the "
302 "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
304 if attr in __former_attrs__:
--> 305 raise AttributeError(__former_attrs__[attr])
307 # Importing Tester requires importing all of UnitTest which is not a
308 # cheap import Since it is mainly used in test suits, we lazy import it
309 # here to save on the order of 10 ms of import time for most users
310 #
311 # The previous way Tester was imported also had a side effect of adding
312 # the full `numpy.testing` namespace
313 if attr == 'testing':
from brian2.
Upon further inspection, I noticed that the file in question (fundamentalunits.py
) was not updated in pull request #1273 but in another commit of yours last October. This fix is visible on master but for some reason it is not part of the pypi distribution. For now I've simply changed that single line from np.float
to float
locally (it seems to have been the only faulty leftover) and I no longer get errors for code like 20*volt
from brian2.
Hi again, and sorry for the confusion. I misread your initial post a bit, and thought you ran into this issue with general code, just by using 20*volt
somewhere. If you used a version from before the fixes in #1273, this would have been indeed the case, errors related to the aliases would pop up in many places. You are right that there is one place that I only fixed recently (and we did not yet have a release since that fix). This only concerns the LaTeX output you get in a jupyter notebook when you directly ask it to represent a Brian Quantity
instead of e.g. printing it with print
.
I hope I'll get around making a new release in the coming weeks, but until then there are also a few workarounds that you can use (apart from fixing the bug directly in the code as you did):
- Do not ask for a representation of quantities, e.g. replace
20 * volt
byprint(20 * volt)
. - Remove the LaTeX formatting for quantities by stating
del Quantity._repr_latex_
at the beginning of your session - Use a numpy version < 1.24
Note that you only get an error with numpy versions >= 1.24 (released in December last year), in versions >=1.20<1.24 you will only get a warning.
Hope that makes things a bit clearer!
from brian2.
Related Issues (20)
- SpatialNeuron (spatialstateupdate) fails with numpy without scipy HOT 7
- Improve parser for model descriptions HOT 1
- Improve the MarkDown exporter
- Use randomised timesteps to avoid artificial synchronisation
- Improve Pyodide support
- [Question] Regarding the spatial neuron equation HOT 2
- GSL incompatibility with latest Cython beta
- Problem with storing Neurongroups in dictionaries HOT 1
- the Izhikevich_2007 example neuron model bug HOT 4
- [readthedocs] Tutorials disappeared HOT 2
- Random number generation on C++ standalone is slow HOT 3
- [beginner question]step through brian2 to understand inner workings of neuronal models HOT 1
- Setting Neuron weights? HOT 2
- Floor division of integer values sometimes incorrect on C++ standalone
- Returned value needs to be retrieved for object to work HOT 7
- A bug in the Synapse.connect documentation HOT 2
- module 'brian2' has no attribute 'units' HOT 2
- problem with NeuronGroup HOT 1
- (Very) small refractory values get lost in code generation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brian2.