-
Notifications
You must be signed in to change notification settings - Fork 188
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
Add demo "How to Quantum Just-In-Time Compile Grover's Algorithm with Catalyst" #1219
Add demo "How to Quantum Just-In-Time Compile Grover's Algorithm with Catalyst" #1219
Conversation
👋 Hey, looks like you've updated some demos! 🐘 Don't forget to update the Please hide this comment once the field(s) are updated. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use by default the lightning.qubit
device in the baseline algorithm explanation, instead of doing it with the default.qubit
device, for the same reason explained in the demo: Catalyst does not support the latter at the moment. I would also remove it from the benchmark and show only the results with lightning.qubit
. Finally, I would write a small note stating non-supported devices of Catalyst. What do you think?
My reasoning for using There's an argument to be made to leave I would prefer not to list out the devices that Catalyst does not support, and just refer to the documentation. Suppose the list of supported devices changes over time, I think it would be better to not have to keep the demo in sync with that list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great demo, can you double check the build failure? After that we can check that it renders properly.
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.py
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.py
Outdated
Show resolved
Hide resolved
Thanks @rmoyard! The build failure was due to the path to the preview image thumbnail not existing. I've put in the original Grover's algorithm preview image as a placeholder, just to check the build and rendering, which we can replace later on. |
Thank you for opening this pull request. You can find the built site at this link. Deployment Info:
Note: It may take several minutes for updates to this pull request to be reflected on the deployed site. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great first demo 💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @joeycarter, that's a cool demo! :)
The benchmarking is done quite nicely, I like the comparison of the different stages (include the first load!).
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, really nicely written how-to guide @joeycarter! Super clear and very well written.
I've left some suggestions throughout.
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.metadata.json
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.metadata.json
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.metadata.json
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.py
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.py
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.py
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.py
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.py
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.py
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.metadata.json
Outdated
Show resolved
Hide resolved
I've refactored the Interestingly, when I run this locally I no longer see a difference between the first-call runtime and subsequent-call runtimes. It's possible that when I'll see if I get the same result in the deployed version. If so, I'll remove the paragraph on the caching overhead, since this is likely the wrong interpretation of the larger runtime in the first call of the compiled circuit. |
If the first call overhead is primarily spent on loading shared libraries, then creating a new QJIT object may not recreate that state accurately. This is just a wild guess, but it could be that a lot of the shared libs (besides the program one, since that one should be new) that are needed to execute a catalyst program are still loaded in the Python process. If you comment out the first call earlier in the demo, does it revert it to the old results? |
Ah, yes if I comment out the first call then it reverts to the old results, with the first QJIT call taking significantly longer than subsequent calls. On my machine I get
So the overhead appears to be in calling for the first time any instance of a qjit-compiled circuit, rather than calling every new |
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.py
Outdated
Show resolved
Hide resolved
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.py
Outdated
Show resolved
Hide resolved
I profiled the first and second calls to the qjit-compiled circuit and in fact the hotspot is in the call to If we trace down the function call stack from That's a lot of text so here's a visualization! First, the first (slow) call: and the second (fast) call: If I'm understanding all of this correctly, the overhead isn't in Catalyst per se, but in loading a bunch of JAX and XLA things the first time we call In fact, if I throw in a This is getting far into the nitty-gritty details of the performance of Catalyst and JAX, and well beyond the scope of this demo, I think. I propose we not show the difference between the first call and the subsequent calls in the benchmarks, since I think it's a reasonable assumption that any user who cares about that level of performance will already be using JAX arrays in their programs and not notice any difference in the first and second calls to an AOT-compiled circuit. @josh146, @dime10, how does that sound? |
@joeycarter yep that sounds good to me! On another note, we discovered that the decomposition pathway for lightning+noqjit for This is likely not optimal, as these magic numbers are not always the best and can lead to slowdowns near the boundary (e.g., 10-12 qubits). I'd be curious to rerun the demo at 13 or 14 qubits (where lightning and catalyst should use the same decomposition strategy) to see what the outcome is? |
Thanks @joeycarter, nice digging! So the overhead is not related to catalyst, happy to leave it at that and not show 1st vs 2nd call 👍 |
Thanks @dime10! Sounds good. |
Co-authored-by: Ivana Kurečić <[email protected]>
Co-authored-by: Ivana Kurečić <[email protected]>
96e156a
to
51b6c4a
Compare
Heads up, I've rebased this demo onto the |
demonstrations/tutorial_qjit_compile_grovers_algorithm_with_catalyst.metadata.json
Outdated
Show resolved
Hide resolved
afe2e82
to
6308feb
Compare
Title: How to Quantum Just-In-Time Compile Grover's Algorithm with Catalyst
Summary: This demo uses the existing Grover's Algorithm tutorial to describe how to just-in-time (JIT) compile a quantum circuit using Catalyst. It also includes runtime benchmarks to demonstrate the performance improvements that JIT compiling with Catalyst offers.
Relevant references: L. K. Grover (1996) "A fast quantum mechanical algorithm for database search"
Possible Drawbacks: None
Related GitHub Issues: None
[sc-72939]
If you are writing a demonstration, please answer these questions to facilitate the marketing process.
GOALS — Why are we working on this now?
AUDIENCE — Who is this for?
KEYWORDS — What words should be included in the marketing post?
Which of the following types of documentation is most similar to your file?
(more details here)