Hi Harold,
Nice to hear from you and thanks a lot for the detailed explanations and the solution for
this mystery 😊!
Would you want to prepare a PR for this, so you get credit assigned for the solution?
Ideally today, since we plan to roll NEST 3.7-RC1 very, very soon now.
Best,
Hans Ekkehard
--
Prof. Dr. Hans Ekkehard Plesser
Department of Data Science
Faculty of Science and Technology
Norwegian University of Life Sciences
PO Box 5003, 1432 Aas, Norway
Phone +47 6723 1560
Email hans.ekkehard.plesser@nmbu.no<mailto:hans.ekkehard.plesser@nmbu.no>
Home
http://arken.nmbu.no/~plesser
From: Harold Gutch <nest-hg(a)gutch.de>
Date: Monday, 11 March 2024 at 22:52
To: NEST User Mailing List <users(a)nest-simulator.org>
Subject: [NEST Users] Re: Strange interaction between NEST and IPython
[Du mottar ikke ofte e-post fra nest-hg(a)gutch.de. Finn ut hvorfor dette er viktig p?
https://aka.ms/LearnAboutSenderIdentification ]
Hello Hans,
On Fri, Mar 08, 2024 at 02:24:17PM +0000, Hans Ekkehard Plesser wrote:
Dear Python experts among the NEST Users!
I just notice a strange interaction between NEST and Ipython. In a freshly started
Ipython, I execute the following three statements
import nest
n = nest.Create('parrot_neuron', positions=nest.spatial.free([(x, 0) for x in
range(10000)]))
n
The last one takes extraordinarily long, over 10 seconds, I think. But if I instead do
print(n)
it executes instantaneously.
What happens is that IPython's pretty printing calls (a bit down the
line) the IPythonDisplayFormatter() class. The first thing that does
is test if for the given object there is an _ipython_display_() method
- if that exists, it calls that, otherwise it falls back to a more
generic method. In your case the latter happens, it falls back to the
more generic method and that is what then produces the output.
When looking up if there is an _iython_display_() method, the first
thing IPython does is check for a method called
_ipython_canary_method_should_not_exist_() - and it is precisely this
lookup that takes so long. You can verify this by
getattr(n, "_ipython_canary_method_should_not_exist_")
which will also take rather long. As the output here also contains
some SLI things, one might need to dig deeper to actually speed this
up.
Instead, adding a check specifically for exactly the above mentioned
lookup of _ipython_canary_method_should_not_exist_() also does the
job (for me), see the attachment. With that workaround, your example
returns instantaneously - as one would expect it to.
regards,
Harold