You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.10
Expected behaviour
pylance not causing a constant and never ending cpu load of 100 % when using scipy.optimize.minimize
Actual behaviour
When using scipy.optimize.minimize I encounter a never ending high cpu load due to the pylance extension. I was able to figure out, that the problem arises when specifying the function which scipy.optimize.minimize should numerically minimize.
Setting "python.analysis.useLibraryCodeForTypes": false (as mentioned here) solves the issue for the high cpu load. As I am using v2021.10.1 I thought the corresponding issue to this problem should be fixed?
I confirmed this behavior on two different machines.
Code Snippet / Additional information
See this little example snippet:
importscipy.optimizedefdummy(x):
returnx*xscipy.optimize.minimize(fun=dummy, x0=5) # Causes high cpu load scipy.optimize.minimize(x0=5) # Code will not work but does not cause high cpu load
Logs
User belongs to experiment group 'pythonaa'
User belongs to experiment group 'pythonJediLSPcf'
User belongs to experiment group 'pythonSendEntireLineToREPL'
User belongs to experiment group 'pythonNotDisplayLinterPrompt'
User belongs to experiment group 'pythonDiscoveryModulecf'
User belongs to experiment group 'pythonTensorboardExperiment'
User belongs to experiment group 'PythonPyTorchProfiler'
> conda info --json
> /bin/python ~/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/interpreterInfo.py
> /bin/python2 ~/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/interpreterInfo.py
> /usr/bin/python ~/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/interpreterInfo.py
> /usr/bin/python2 ~/.vscode/extensions/ms-python.python-2021.10.1336267007/pythonFiles/interpreterInfo.py
Starting Pylance language server.
Python interpreter path: /bin/python
> conda --version
The text was updated successfully, but these errors were encountered:
I've investigated the cause of the long compute time. The scipy library is largely unannotated, so pylance needs to use return type inference to determine the return type of most functions and methods. Since input parameter types are also unannotated, pylance often needs to resort to a more expensive technique we call call-site return type inference where the input parameter types are inferred from the types of the arguments provided at the call site. Pylance currently uses this technique up to 3 levels deep (where function a calls b calls c). In the case of scipy, this was especially expensive given the complexity of the code.
I've changed the code in pylance to limit this expensive form of analysis from 3 levels to 2 levels deep. This may result in less-accurate type inference in some cases, but it greatly improves the performance in this particular example (and likely other cases in scipy).
Environment data
Expected behaviour
pylance not causing a constant and never ending cpu load of 100 % when using
scipy.optimize.minimize
Actual behaviour
When using
scipy.optimize.minimize
I encounter a never ending high cpu load due to the pylance extension. I was able to figure out, that the problem arises when specifying the function whichscipy.optimize.minimize
should numerically minimize.Setting
"python.analysis.useLibraryCodeForTypes": false
(as mentioned here) solves the issue for the high cpu load. As I am usingv2021.10.1
I thought the corresponding issue to this problem should be fixed?I confirmed this behavior on two different machines.
Code Snippet / Additional information
See this little example snippet:
Logs
The text was updated successfully, but these errors were encountered: