Open OverLordGoldDragon opened 3 years ago
Hi @OverLordGoldDragon thanks for reporting this. @CAM-Gerlach can you take a look at this one?
Sorry for the delay @OverLordGoldDragon and the accidental close, thought I'd submitted this yesterday but I ended up hitting the wrong button instead.
I could not reproduce the problem described/shown in the video running Spyder 4.2.1 on Win 8.1 x64 under Anaconda with Python 3.7.9 and Numpy 1.19.2 (same config as the user in the video, minus Win version), nor with Numpy 1.18.5 from defaults
, either by following the (incomplete) example code and procedure posted to this thread, or the different code and procedure shown in the video.
However, there certainly does appear to be something strange going on either pre- or post-execution of the actual cell code. Given the description, it seems possible it has something to do with strange behavior with half-precision floats, maybe something with hardware instructions/support (since unlike all the other Numpy formats, it was only recently standardized and implemented in hardware). Interestingly, my machine, despite being moderately performant, takes well over a minute to run the first instruction (regardless of data type) and the Spyder UI even hung for a good portion of that time (which it shouldn't, but unsure if related).
What I would suggest asking the user to do, to attempt to isolate the problem:
conda install qtconsole
then jupyter qtconsole
).
Unless the problem occurs in QtConsole, please also report the full output of conda list
in your working environment, try conda update numpy ipykernel jupyter_client spyder_kernels
in the same, and try different Numpy verisons to determine if is isolated to any of them. Thanks, and best of luck!
As noted in OP, IPython execution is unaffected, this includes F9 or running pasted code. I also don't reproduce this in an Anaconda python terminal. Below is after running conda install -c conda-forge spyder==4.2.3
and numpy==1.20.1
and conda update ipykernel jupyter_client spyder-kernels
(didn't help).
Thanks for the detailed information, @OverLordGoldDragon . What about runfile
(F5
by default)? Also, is the environment you've provided your Spyder environment (the environment from which you've launched Spyder), your working environment (the environment in which your code runs in the IPython Console), or both? Also, since we have not been able to reproduce it ourselves, could you test it in a clean working environment, i.e. one created with conda create -n test-env-name spyder-kernels=1 numpy python=3
?
The above environment has many critical packages installed from the defaults
Anaconda stack (mkl, python, spyder_kernels, etc.), others from the conda-forge
stack (including Spyder, Numpy and supporting libraries), and still others from PyPI (standard library backports, other assorted packages), plus a few from independent channels (that should be fine). While this can sometimes work if you're very careful, it is not supported by Anaconda/CF as they are not fully ABI-compatible and numerous tricky errors can result, especially when it comes to low-level interactions like this. This may or may not be the direct cause of the problem, but this will allow us to eliminate most of the variability between your setup and ours, to maximize the chances of reproducing the problem on our end so it can be fixed, and if we're still unable, narrow down what could be the cause. Thanks.
Also, @bcolsen , as you implemented the runcell
function in question, any insight here?
Both @ envs. Ran conda create -n test-env-name spyder-kernels=1 numpy python=3
, conda install spyder
, same results. This time I went ahead and interrupted it mid-delay:
Traceback (most recent call last):
File "<ipython-input-3-fa3bc9be62af>", line 1, in <module>
runcell(2, 'C:/Desktop/School/Deep Learning/DL_Code/signals/untitled0.py')
File "D:\Anaconda\envs\test-env-name\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 634, in runcell
cell_code = frontend_request().run_cell(cellname, filename)
File "D:\Anaconda\envs\test-env-name\lib\site-packages\spyder_kernels\comms\commbase.py", line 554, in __call__
return self._comms_wrapper._get_call_return_value(
File "D:\Anaconda\envs\test-env-name\lib\site-packages\spyder_kernels\comms\commbase.py", line 432, in _get_call_return_value
self._wait_reply(call_id, call_name, timeout)
File "D:\Anaconda\envs\test-env-name\lib\site-packages\spyder_kernels\comms\frontendcomm.py", line 181, in _wait_reply
if not self.wait_until(reply_received):
File "D:\Anaconda\envs\test-env-name\lib\site-packages\spyder_kernels\comms\frontendcomm.py", line 172, in wait_until
time.sleep(0.01)
KeyboardInterrupt
Okay, thanks so much for your help trying to narrow this down. BTW, it wasn't actually necessary to install Spyder in the new environment, but all the better I guess to ensure everything was clean Spyder-side too. I tested an identical environment following the procedure shown in your video, and could still not reproduce the error, the cells have the expected runtime.
I do note that g. for me, the first cell takes around a minute to run and the second several seconds, while the remaining are instant, while for you, the third cell takes very long, and the fourth a much shorter but still non-trivial amount of time, similar to the behavior I'm seeing for my first and second. Are you verifying, e.g. in the Variable Explorer, that the first and cell are actually getting executed when you run them? The wrong cells being sent to the console would certainly explain this behavior.
Also, can you try enabling Copy full cell contents to the console when running code cells
under Editor ---> Run Code
in Spyder's preferences?
Other than that, if none of these provide any further clues, it is difficult for me to do much more from a troubleshooting perspective if I cannot reproduce the problem, so I would defer to @bcolsen who is most familiar with the code in question and may be able to infer better what is happening. Thanks!
This seem tricky to reproduce. I am seeing about 30 sec on cell one and the rest are instantaneous.
I made the original attempt at runcell() but it's been re-implemented since then the right way :-)
@impact27 Any ideas?
Hey guys, I can reproduce this behavior if "Show arrays min/max" in variable explorer is active - no matter if variable explorer is shown or not. So it seems that whenever statististics updates are triggered for large arrays the whole program gets irresponsive. I had the same problem a little while ago and worked around it by using a variable name that was not shown in variable explorer (e.g. "__variable" with "Exclude private references" active) or by just deactivating statistics. Hope this helps?! (Win 10, Spyder 4.2.1)
(16, 16, 240, 24000) is a large size, maybe it is coputing the min/max at each step when it sends the namespace view to the frontend? It wouldn't be related to runcell then.
It takes much less time to compute .min(), .max(), .mean()
than however long Spyder is taking. And the behavior is exclusive to runcell
; code ran in IPython console, whether pasted, or F9'd, or typed, is fine. And again, this concerns float16
; float64
, which is 4x the size, doesn't affect runcell
.
@OverLordGoldDragon Can you confirm whether the option @sawtw mentions affects whether this slowdown occurs for you?
It takes much less time to compute
.min(), .max(), .mean()
than however long Spyder is taking.
Yes, but it could be computing it at individual substeps, it could be due to I/O serializing and deserializing the large array, there could be resource contention issues going on during the computation, it could be recomputing the whole array, etc.
And again, this concerns
float16
;float64
, which is 4x the size, doesn't affectruncell
.
As discussed above, float16
(IEEE Half Precision Float) is a far more recent standard than the others, and could be affected greatly by incomplete, buggy or not present support in hardware or the software toolchain. On a 64 bit CPU, without specific packing optimizations, vectorization, etc, typically only found on the very latest/high end processors these could easily perform at the same speed or much slower than their larger counterparts, depending on whether on what resources bound the operation and other complex factors.
enabling
Copy full cell contents to the console when running code cells
underEditor ---> Run Code
I misunderstood this suggestion at first; so both run via "runcell" commands, but enabling this simply pastes to IPython rather than executing runcell
; I confirm the slowdown disappears with this option.
it could be recomputing the whole array
This sounds... excessive, and not what Spyder ever seems to do as I regularly work with arrays that occupy 80%+ RAM. I also don't even have the Variable Explorer pane opened.
affected greatly by incomplete, buggy or not present support in hardware or the software toolchain
But it runs fine in IPython; if runcell
is taking some extra steps, like computing stats for panes that aren't even opened, those could be looked into.
One solution would be to profile the kernel. Create a file called kernel.py
:
from spyder_kernels.console import start
start.main()
And run it from a terminal:
python -m cProfile -o out.txt "kernel.py"
This will give you a text like:
NOTE: When using the `ipython kernel` entry point, Ctrl-C will not work.
To exit, you will have to explicitly quit this process, by either sending
"quit" from a client, or using Ctrl-\ in UNIX-like environments.
To read more about this, see https://github.com/ipython/ipython/issues/2049
To connect another client to this kernel, use:
--existing kernel-904.json
kernel-904.json
and paste it in "Consoles > Connect to an existing kernel"quit()
to quit the kernelout.txt
One solution would be to profile the kernel. Create a file called
kernel.py
: [...]
I tried this, it worked as you described, however, the lagging is gone in this scenario.
I can confirm that this is due to min max in the variable explorer. X takes 30 seconds to compute on my box and X.max() takes about 13 seconds. It seems that variable explorer is recomputing the min max of every variable in the explorer when it gets the call to refresh after runcell
or runfile
. If the variable explorer is busy when runcell
or runfile
is
@OverLordGoldDragon @sawtw thanks for helping get to the bottom of this! Here is a work around: Open variable explorer, right click on the table and uncheck "show arrays min/max" wait for a while for the explorer to refresh and then it should be speedy again.
With one array in the variable explorer and min/max enabled, it takes about 26 seconds to refresh the variable explorer. This is regardless of whether the array has changed. Just just running t0 = time()
in either IPython directly of through runcell
it takes ~26 s for the variable explorer to update.
I don't know if there is much to be done here. Perhaps we check the array size and don't give min/max past a certain size.
Runcell
and runfile
seem to wait for comms from variable explorer.The issue for this bug is that runcell
gets stuck in comms if variable explorer is already updating. If you use runcell
and variable explorer is finished updating, runcell
work just fine. I only gets stuck when you are running one cell right after the other. The first cell you run will return normally while the next cell waits until the update in the variable explorer to from the previous cell is finished.
Does the variable explorer need to respond to runcell
or is it good enough to just assume it will update.
@bcolsen Works. @CAM-Gerlach 's intuition was correct, the max()
and min()
take much longer with 'float16'
than 'float64'
, which I wouldn't expect. An obvious improvement to keeping min/max is to only recompute if the variable is modified - as to how doable it is, no clue.
Thanks to all who contributed; feel free to close the issue.
Unsure if related but long delays in IPdb
on every step are also gone after disabling min/max in variable explorer.
Seems probable that after every IPdb step the min/max of all arrays gets recomputed as well, thus causing similar delays.
Maybe we should add a message saying: "Computing min/max for the current variables took more than 2 seconds. Do you want to disable automatic variable explorer refreshing?"
Minimum code to reproduce: Run in the console:
class A():
def __len__(self):
import time
time.sleep(10)
return 10
a = A()
Any call to runcell or runfile will be super slow after that.
The best solution is likely that get_namespace_view
should be run in a thread?
demo.mp4
Despite last command printing
0.0
,runcell(3, ...)
took several seconds. Strangely,shape = (2, ...)
&dtype='float64'
, which is same size in memory, doesn't yield this effect; haven't tested with'float32'
. Also, IPython commands aren't slowed.Using spyder 4.2.1 as conda doesn't have 4.2.2 yet; Win 10 x64, Python 3.7.9, numpy 1.19.2.
Code:
Restart kernel