qsharp
qsharp copied to clipboard
Sample for modern QDK project with Python
Is your feature request related to a problem? Please describe. Its a bit cumbersome to copy-paste code from Sample for modern QDK project with Python as described here.
Describe the solution you'd like Discussed with @tcNickolas who recommends creating a sample for this in the qsharp repository itself, since it's the main source of truth for Q# samples.
Like this one? https://github.com/microsoft/qsharp/blob/main/samples/notebooks/project.ipynb
This notebook is nice. It would be good if documentation could point to this notebook 📒
The notebook sample is great for showing how to work with Q# only from a notebook, without Python.
- It needs to be updated (or a new sample created) to show how to pass arguments from Python to Q#, and get the results from Q# into Python for post-processing.
- We also need to cover the scenario of Q# + Python non-notebook project. Python files don't have Q# magic to rely on, so they need to use qsharp.eval, the syntax is not trivial to figure out.
We do have the double factorized chemistry sample for resource estimation which is straight Python and Q# (https://github.com/microsoft/qsharp/blob/main/samples/estimation/df-chemistry/chemistry.py#L472), but agree we could do with something more accessible.
I would suggest creating a new folder under https://github.com/microsoft/qsharp/blob/main/samples/ called "python_interop", and add two projects to it, each in its own folder:
- Teleportation project from our documentation, covering the basic no-inputs-no-outputs scenario, just calling Q# from Python, so that we can point to that project from that docs page.
- A slightly more complicated project that would call Q# with some input parameter and get some return value from it.
- One issue I ran into when working with Q# results in Python was converting Q# Result type into something Python-readable (it used to be cast into an integer but now it's a special data type with constants
qsharp.Result.Zeroandqsharp.Result.One- this test has an example but we don't have it in actual samples). - Maybe we can do something like Q# taking N, generating N random bits, and returning an array of them, and Python counting the number of 1s in the results?
- One issue I ran into when working with Q# results in Python was converting Q# Result type into something Python-readable (it used to be cast into an integer but now it's a special data type with constants