Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample for modern QDK project with Python #1384

Open
Manvi-Agrawal opened this issue Apr 14, 2024 · 5 comments
Open

Sample for modern QDK project with Python #1384

Manvi-Agrawal opened this issue Apr 14, 2024 · 5 comments
Labels
enhancement New feature or request samples

Comments

@Manvi-Agrawal
Copy link
Contributor

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.

@billti
Copy link
Member

billti commented Apr 17, 2024

Like this one? https://github.com/microsoft/qsharp/blob/main/samples/notebooks/project.ipynb

@Manvi-Agrawal
Copy link
Contributor Author

This notebook is nice. It would be good if documentation could point to this notebook 📒

@tcNickolas
Copy link
Member

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.

@billti
Copy link
Member

billti commented Apr 24, 2024

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.

@tcNickolas
Copy link
Member

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:

  1. 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.
  2. 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.Zero and qsharp.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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request samples
Projects
None yet
Development

No branches or pull requests

3 participants