microsoft / iqsharp

Microsoft's IQ# Server.
https://docs.microsoft.com/quantum
MIT License
126 stars 58 forks source link

`import qsharp` takes a very long time #338

Closed rmshaffer closed 4 years ago

rmshaffer commented 4 years ago

Issue description below copied from https://github.com/MicrosoftDocs/quantum-docs-pr/issues/1076. Reported by @sanori.

Note that this affects only the first run after installation. Once everything is cached, then subsequent runs are fast, as expected.


$ python
Python 3.7.6 | packaged by conda-forge | (default, Jun  1 2020, 18:57:50) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import qsharp
Preparing Q# environment...
...................Q# environment was not available in allocated time.
Please check the instructions at https://aka.ms/qdk-install/python.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.7/site-packages/qsharp/__init__.py", line 123, in <module>
    client = _start_client()
  File "/opt/conda/lib/python3.7/site-packages/qsharp/clients/__init__.py", line 64, in _start_client
    raise IQSharpNotAvailableError(message)
qsharp.clients.IQSharpNotAvailableError: Q# environment was not available in allocated time.
Please check the instructions at https://aka.ms/qdk-install/python.
>>> 

Runtime Environment: OS Name: ubuntu OS Version: 20.04 OS Platform: Linux RID: ubuntu.20.04-x64 Base Path: /usr/share/dotnet/sdk/3.1.402/

Host (useful for support): Version: 3.1.8 Commit: 9c1330dedd

.NET Core SDKs installed: 3.1.402 [/usr/share/dotnet/sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download


I tried "import qsharp" again several times.
Then, the error message disappeared and it worked.

I guess that it takes too long time to run "import qsharp" for the first time.

With qsharp 0.12.2009.2803, "import qsharp" does not take long time:

$ python Python 3.7.6 | packaged by conda-forge | (default, Jun 1 2020, 18:57:50) [GCC 7.5.0] on linux Type "help", "copyright", "credits" or "license" for more information.

import qsharp Preparing Q# environment... .>>>

rmshaffer commented 4 years ago

The root cause of this issue appears to be that Microsoft.Quantum.Standard.Visualization, which is now being loaded at startup, has a dependency on Microsoft.Quantum.IQSharp.Jupyter. When resolving package dependencies, IQ# is not aware that the assemblies from this package are already available in its own installation, and proceeds to download that package and all of its dependencies from nuget.org.

As evidence of that, here is the list of packages downloaded at startup by the previous release 0.12.2009.2803:

 Directory of C:\Users\WDAGUtilityAccount\.nuget\packages

10/12/2020  07:53 AM    <DIR>          .
10/12/2020  07:53 AM    <DIR>          ..
10/12/2020  07:53 AM    <DIR>          microsoft.quantum.qsharp.core
10/12/2020  07:53 AM    <DIR>          microsoft.quantum.runtime.core
10/12/2020  07:53 AM    <DIR>          microsoft.quantum.simulators
10/12/2020  07:53 AM    <DIR>          microsoft.quantum.standard
10/12/2020  07:53 AM    <DIR>          newtonsoft.json
10/12/2020  07:53 AM    <DIR>          numsharp

And here is the list of packages downloaded at startup by the current release 0.12.2010.504:

 Directory of C:\Users\WDAGUtilityAccount\.nuget\packages

10/12/2020  07:59 AM    <DIR>          .
10/12/2020  07:59 AM    <DIR>          ..
10/12/2020  07:59 AM    <DIR>          asyncio
10/12/2020  07:59 AM    <DIR>          fparsec
10/12/2020  07:59 AM    <DIR>          fsharp.core
10/12/2020  07:59 AM    <DIR>          humanizer.core
10/12/2020  07:59 AM    <DIR>          markdig.signed
10/12/2020  07:59 AM    <DIR>          mcmaster.extensions.commandlineutils
10/12/2020  07:59 AM    <DIR>          microsoft.bcl.asyncinterfaces
10/12/2020  07:59 AM    <DIR>          microsoft.codeanalysis.analyzers
10/12/2020  07:59 AM    <DIR>          microsoft.codeanalysis.common
10/12/2020  07:59 AM    <DIR>          microsoft.codeanalysis.csharp
10/12/2020  07:59 AM    <DIR>          microsoft.codeanalysis.csharp.workspaces
10/12/2020  07:59 AM    <DIR>          microsoft.codeanalysis.workspaces.common
10/12/2020  07:59 AM    <DIR>          microsoft.csharp
10/12/2020  07:59 AM    <DIR>          microsoft.extensions.configuration
10/12/2020  07:59 AM    <DIR>          microsoft.extensions.configuration.abstractions
10/12/2020  07:59 AM    <DIR>          microsoft.extensions.configuration.binder
10/12/2020  07:59 AM    <DIR>          microsoft.extensions.dependencyinjection
10/12/2020  07:59 AM    <DIR>          microsoft.extensions.dependencyinjection.abstractions
10/12/2020  07:59 AM    <DIR>          microsoft.extensions.logging
10/12/2020  07:59 AM    <DIR>          microsoft.extensions.logging.abstractions
10/12/2020  07:59 AM    <DIR>          microsoft.extensions.logging.configuration
10/12/2020  07:59 AM    <DIR>          microsoft.extensions.logging.console
10/12/2020  07:59 AM    <DIR>          microsoft.extensions.options
10/12/2020  07:59 AM    <DIR>          microsoft.extensions.options.configurationextensions
10/12/2020  07:59 AM    <DIR>          microsoft.extensions.primitives
10/12/2020  07:59 AM    <DIR>          microsoft.jupyter.core
10/12/2020  07:59 AM    <DIR>          microsoft.quantum.compiler
10/12/2020  07:59 AM    <DIR>          microsoft.quantum.csharpgeneration
10/12/2020  07:59 AM    <DIR>          microsoft.quantum.iqsharp.core
10/12/2020  07:59 AM    <DIR>          microsoft.quantum.iqsharp.jupyter
10/12/2020  07:59 AM    <DIR>          microsoft.quantum.qsharp.core
10/12/2020  07:59 AM    <DIR>          microsoft.quantum.runtime.core
10/12/2020  07:59 AM    <DIR>          microsoft.quantum.simulators
10/12/2020  07:59 AM    <DIR>          microsoft.quantum.standard
10/12/2020  07:59 AM    <DIR>          microsoft.quantum.standard.visualization
10/12/2020  07:59 AM    <DIR>          microsoft.visualstudio.languageserver.protocol
10/12/2020  07:59 AM    <DIR>          netmq
10/12/2020  07:59 AM    <DIR>          newtonsoft.json
10/12/2020  07:59 AM    <DIR>          newtonsoft.json.bson
10/12/2020  07:59 AM    <DIR>          nuget.common
10/12/2020  07:59 AM    <DIR>          nuget.configuration
10/12/2020  07:59 AM    <DIR>          nuget.frameworks
10/12/2020  07:59 AM    <DIR>          nuget.packaging
10/12/2020  07:59 AM    <DIR>          nuget.protocol
10/12/2020  07:59 AM    <DIR>          nuget.resolver
10/12/2020  07:59 AM    <DIR>          nuget.versioning
10/12/2020  07:59 AM    <DIR>          numsharp
10/12/2020  07:59 AM    <DIR>          runtime.debian.8-x64.runtime.native.system.security.cryptography.openssl
10/12/2020  07:59 AM    <DIR>          runtime.fedora.23-x64.runtime.native.system.security.cryptography.openssl
10/12/2020  07:59 AM    <DIR>          runtime.fedora.24-x64.runtime.native.system.security.cryptography.openssl
10/12/2020  07:59 AM    <DIR>          runtime.native.system
10/12/2020  07:59 AM    <DIR>          runtime.native.system.io.compression
10/12/2020  07:59 AM    <DIR>          runtime.native.system.net.http
10/12/2020  07:59 AM    <DIR>          runtime.native.system.net.security
10/12/2020  07:59 AM    <DIR>          runtime.native.system.security.cryptography.apple
10/12/2020  07:59 AM    <DIR>          runtime.native.system.security.cryptography.openssl
10/12/2020  07:59 AM    <DIR>          runtime.opensuse.13.2-x64.runtime.native.system.security.cryptography.openssl
10/12/2020  07:59 AM    <DIR>          runtime.opensuse.42.1-x64.runtime.native.system.security.cryptography.openssl
10/12/2020  07:59 AM    <DIR>          runtime.osx.10.10-x64.runtime.native.system.security.cryptography.apple
10/12/2020  07:59 AM    <DIR>          runtime.osx.10.10-x64.runtime.native.system.security.cryptography.openssl
10/12/2020  07:59 AM    <DIR>          runtime.rhel.7-x64.runtime.native.system.security.cryptography.openssl
10/12/2020  07:59 AM    <DIR>          runtime.ubuntu.14.04-x64.runtime.native.system.security.cryptography.openssl
10/12/2020  07:59 AM    <DIR>          runtime.ubuntu.16.04-x64.runtime.native.system.security.cryptography.openssl
10/12/2020  07:59 AM    <DIR>          runtime.ubuntu.16.10-x64.runtime.native.system.security.cryptography.openssl
10/12/2020  07:59 AM    <DIR>          yamldotnet