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

tutorial_qrack.py #1137

Merged
merged 23 commits into from
Jul 3, 2024
Merged

tutorial_qrack.py #1137

merged 23 commits into from
Jul 3, 2024

Conversation

WrathfulSpatula
Copy link
Contributor

Title:
The Qrack device back end (with Catalyst)

Summary:
In this tutorial you will learn how to use the Qrack device back end for PennyLane and Catalyst, and you'll learn certain suggested cases of use where Qrack might particularly excel at delivering lightning-fast performance or minimizing required memory resources.

Relevant references:
https://github.com/unitaryfund/qrack
https://github.com/unitaryfund/pyqrack
https://arxiv.org/abs/2304.14969

Possible Drawbacks:
Not all users might have Catalyst installed, and this tutorial will require Catalyst v0.7 or later.


If you are writing a demonstration, please answer these questions to facilitate the marketing process.

  • GOALS — Why are we working on this now?

    The Catalyst and Unitary Fund teams are working together to update the Qrack PennyLane device back end (based on open-source code reuse from the Qulacs device and original work with Qrack and Catalyst) to make use of the Catalyst compiler and potentially achieve leading performance on a wide range of qml.qnode subroutine qubit widths and applications. Notably, Qrack automatically switches between CPU-based and GPU-used based simulation methods as appropriate to maximize overall performance, whether circuits are wide enough to benefit from thousands of parallel work items in a job dispatched to a GPU. The Qrack device back end is also open source and can serve as an example or basis for other simulator device back ends that may reuse its code.

  • AUDIENCE — Who is this for?

    The potential audience includes researchers, educators, students, hobbyists, and anyone with an interest in faster and more efficient quantum computer simulation in PennyLane.

  • KEYWORDS — What words should be included in the marketing post?

    GPU, high-performance computing (HPC), hybrid CPU/GPU, near-Clifford simulation, quantum binary decision diagrams (QBDD), vendor-agnostic GPU support (OpenCL), optional CUDA

  • Which of the following types of documentation is most similar to your file?
    (more details here)

  • Tutorial
  • Demo
  • How-to

demonstrations/tutorial_qrack.py Outdated Show resolved Hide resolved
demonstrations/tutorial_qrack.py Outdated Show resolved Hide resolved
demonstrations/tutorial_qrack.py Outdated Show resolved Hide resolved
demonstrations/tutorial_qrack.py Outdated Show resolved Hide resolved
Copy link

@cosenal cosenal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tutorial!

I left two suggestions for improvement, but in my opinion it's also ready to be shipped 🛳️

demonstrations/tutorial_qrack.py Outdated Show resolved Hide resolved
demonstrations/tutorial_qrack.py Outdated Show resolved Hide resolved
@josh146
Copy link
Member

josh146 commented Jun 21, 2024

@WrathfulSpatula due to how our website is set up, all tutorials are actually executed to generate the site :) So at the moment, your tutorial is failing due to qrack not being found: https://github.com/PennyLaneAI/qml/actions/runs/9604177897/job/26489349281?pr=1137#step:19:1658

We have two options:

  • Add pre-release version of pennylane-qrack with the catalyst support to the pyproject.toml. This way the tutorial will build correctly. Prior to merging in July, though, we should update the pyproject.toml to use the release version.

    • This is preferred, because then the tutorial also acts as an integration/system test!
  • Or, we could potentially turn the tutorial into a non-executable tutorial, with the output hardcoded into the .py file.

@ikurecic
Copy link
Contributor

Thanks a lot for creating this pull request, @WrathfulSpatula !

Josh has added a useful comment above mine, but I will also add the minutiae: if you could look at the bullet points on contributing here, that would be great.
There you can also find instructions for adding your author bio, figures and so on. It will be helpful if you could set those up first. ☺

But please let me know if something doesn't work right for you and we'll figure it out. Thank you!

Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @WrathfulSpatula, have left some additional suggestions!

demonstrations/tutorial_qrack.py Outdated Show resolved Hide resolved
demonstrations/tutorial_qrack.py Outdated Show resolved Hide resolved
demonstrations/tutorial_qrack.py Outdated Show resolved Hide resolved
demonstrations/tutorial_qrack.py Outdated Show resolved Hide resolved
demonstrations/tutorial_qrack.py Outdated Show resolved Hide resolved
demonstrations/tutorial_qrack.py Outdated Show resolved Hide resolved
@josh146 josh146 added the dependencies Pull requests that update a dependency file label Jul 2, 2024
@josh146
Copy link
Member

josh146 commented Jul 2, 2024

Hey @WrathfulSpatula, there seems to be an issue installing pennylane-qrack: https://github.com/PennyLaneAI/qml/actions/runs/9753062668/job/26917741222?pr=1137#step:9:312

I tried to pip install pennylane-qrack locally, and unfortunately ran into a packaging error myself:

Collecting pennylane-qrack
  Using cached pennylane_qrack-0.6.11.tar.gz (36 kB)
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Preparing metadata (setup.py) ... error
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

@WrathfulSpatula
Copy link
Contributor Author

@josh146 This is the exact issue: scikit-build/scikit-build#262

Since scikit-build changes the imports on setup.py before the dependency installation hook is invoked, scikit-build must already be installed. Also, scikit-build is likely to be a relatively popular dependency for device back end developers, if you suggest a CMake-based build of C++ back ends.

The solution for now is simply to add scikit-build to poetry. Unless you could propose a way to eliminate the reliance on scikit-build, this is just how we invoke "vanilla" CMake for a Python module, since pybind11 (or pure language standard ctypes like PyQrack uses, only) are not appropriate for the task.

@WrathfulSpatula
Copy link
Contributor Author

@josh146 Now it installs, but it's saying that qml.device can't find qrack.simulator. I'm not sure if this section of the pyproject.toml might have anything to do with it, given that pennylane-qrack is a PennyLane plugin, specifically: https://github.com/WrathfulSpatula/qml/blob/083e3429316308d9d12c0f2b3c6db4507375682c/pyproject.toml#L37

@WrathfulSpatula
Copy link
Contributor Author

If I locally uninstall pennylane-qrack, I get the same error as the tests:

Traceback (most recent call last):
  File "/home/iamu/GitHub/qml/demonstrations/tutorial_qrack.py", line 43, in <module>
    dev = qml.device("qrack.simulator", qubits, shots=8)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/iamu/qrack_venv/lib/python3.12/site-packages/pennylane/__init__.py", line 423, in device
    raise DeviceError(f"Device {name} does not exist. Make sure the required plugin is installed.")
pennylane._device.DeviceError: Device qrack.simulator does not exist. Make sure the required plugin is installed.

Then, when I reinstall pennylane-qrack, the tutorial works, as normally.

My guess is that something in the workflow configuration is removing the pennylane-qrack dependency while likely expecting it to be built from source. That can be done like in https://github.com/unitaryfund/pennylane-qrack/blob/master/.github/workflows/build.yml, but I'm not sure where to set it up here on the QML repository.

@josh146 josh146 merged commit 3dd0882 into PennyLaneAI:dev Jul 3, 2024
9 of 10 checks passed
@nathanshammah
Copy link

Congrats @WrathfulSpatula and thanks @josh146 @ikurecic and @cosenal. Let us know if there is anything that we can do wrt to the tests failing.

@WrathfulSpatula WrathfulSpatula mentioned this pull request Jul 3, 2024
3 tasks
ikurecic added a commit that referenced this pull request Jul 10, 2024
**Title:**
The Qrack device back end (with Catalyst)

**Summary:**
In this tutorial you will learn how to use the Qrack device back end for
PennyLane and Catalyst, and you'll learn certain suggested cases of use
where Qrack might particularly excel at delivering lightning-fast
performance or minimizing required memory resources. (See #1137: this
recreates the PR for further review)

**Relevant references:**
https://github.com/unitaryfund/qrack
https://github.com/unitaryfund/pyqrack
https://arxiv.org/abs/2304.14969

**Possible Drawbacks:**
Not all users might have Catalyst installed, and this tutorial will
require Catalyst v0.7 or later.

----
If you are writing a demonstration, please answer these questions to
facilitate the marketing process.

* GOALS — Why are we working on this now?

The Catalyst and Unitary Fund teams are working together to update the
Qrack PennyLane device back end (based on open-source code reuse from
the Qulacs device and original work with Qrack and Catalyst) to make use
of the Catalyst compiler and potentially achieve leading performance on
a wide range of `qml.qnode` subroutine qubit widths and applications.
Notably, Qrack automatically switches between CPU-based and GPU-used
based simulation methods as appropriate to maximize overall performance,
whether circuits are wide enough to benefit from thousands of parallel
work items in a job dispatched to a GPU. The Qrack device back end is
also open source and can serve as an example or basis for other
simulator device back ends that may reuse its code.


* AUDIENCE — Who is this for?

The potential audience includes researchers, educators, students,
hobbyists, and anyone with an interest in faster and more efficient
quantum computer simulation in PennyLane.


* KEYWORDS — What words should be included in the marketing post?

GPU, high-performance computing (HPC), hybrid CPU/GPU, near-Clifford
simulation, quantum binary decision diagrams (QBDD), vendor-agnostic GPU
support (OpenCL), optional CUDA

* Which of the following types of documentation is most similar to your
file?
(more details
[here](https://www.notion.so/xanaduai/Different-kinds-of-documentation-69200645fe59442991c71f9e7d8a77f8))
    
- [ ] Tutorial
- [x] Demo
- [ ] How-to

---------

Co-authored-by: Josh Izaac <[email protected]>
Co-authored-by: Ivana Kurečić <[email protected]>
Co-authored-by: Ivana Kurečić <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants