Quantum
Quantum copied to clipboard
mybinder notebook integer-factorization does not work
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:
- Go to: https://aka.ms/try-qsharp
- 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
- Execute the first cell.
I'm running this using Edge V102 on Windows 11.
Screenshot is attached.

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?
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
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.