microsoft / Quantum

Microsoft Quantum Development Kit Samples
https://docs.microsoft.com/quantum
MIT License
3.87k stars 920 forks source link

mybinder notebook integer-factorization does not work #677

Open wim-van-dam opened 2 years ago

wim-van-dam commented 2 years ago

When trying to run the integer-factorization mybinder notebook, the from Microsoft.Quantum.Samples.IntegerFactorization import FactorSemiprimeInteger in the first cell gives a ModuleNotFoundError: No module named 'Microsoft' error.

To reproduce this error:

  1. Go to: https://aka.ms/try-qsharp
  2. Under Integer factorization, select Q#+ Python to Run in browser; this is the URL: https://hub.gke2.mybinder.org/user/microsoft-quantum-698yo5d6/notebooks/samples/algorithms/integer-factorization/host.py
  3. Execute the first cell.

I'm running this using Edge V102 on Windows 11.

Screenshot is attached.

Screenshot 2022-06-10 100930
tcNickolas commented 2 years ago

I can reproduce this when running this sample locally as a Python script.

I could fix that by adding the following lines

qsharp.packages.add("Microsoft.Quantum.Numerics::0.25.218240")
qsharp.reload()

right after import iqsharp. It looks like Python cannot discover the Microsoft.Quantum.Numerics NuGet package when building Q# code? I think Ryan added automatic package load on startup back in fall 2020, which removed the need to do qsharp.packages.add manually.

@cgranade @anjbur Were there any recent changes to the way IQ# discovers NuGet packages that could cause this?

tcNickolas commented 2 years ago

The failure on the first cell should be fixed now with https://github.com/microsoft/Quantum/pull/705. However, we still won't get a result by running this sample on Binder as is, since host.py assumes it's running from the command line rather than as a Jupyter Notebook, and Binder passes it some arguments that are not recognized, so it throws the following error:

usage: ipykernel_launcher.py [-h] [-n NUMBER] [-t TRIALS] [-u]
ipykernel_launcher.py: error: unrecognized arguments: -f /home/jovyan/.local/share/jupyter/runtime/kernel-8d0b3e96-97eb-4d4e-8cb9-9ed5c0f951fe.json
cgranade commented 2 years ago

Thanks for the report! In general, not all of our CLI-style samples have been converted to notebooks yet; will mark this as an enhancement to track that suggestion.