-
Notifications
You must be signed in to change notification settings - Fork 218
Demo: How to use PennyLane for Resource Estimation #1592
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
base: master
Are you sure you want to change the base?
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! |
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
After the update to Sphinx, Sphinx Gallery now outputs a different format for generated code blocks, where the code block is now part of an entirely separate element and no longer nested in `rst-class` directive. This PR adds a fix to be able to handle both the new and old `sphx-glr-script-out` formats. It has been tested on #1592 .
Your preview is ready 🎉!You can view your changes here
|
| # Fault tolerant quantum computing is on its way. But are there useful algorithms which are ready for | ||
| # it? The development of meaningful applications of quantum computing is an active area of research, | ||
| # and one of the major challenges in the process of assessing a potential quantum algorithm is | ||
| # determining the amount of resources required to execute it on hardware. An algorithm may still be | ||
| # helpful even when it cannot be executed, but is only truly helpful when it can. | ||
| # | ||
| # PennyLane is here to make that process easy, with our new resource estimation module: | ||
| # `pennylane.estimator <https://docs.pennylane.ai/en/latest/code/qml_estimator.html>`__. |
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.
Spent some time thinking of alternatives and suggestions. Not an improvement, but sharing in case it's useful or sparks ideas ✨ 💡 ✨
| # Fault tolerant quantum computing is on its way. But are there useful algorithms which are ready for | |
| # it? The development of meaningful applications of quantum computing is an active area of research, | |
| # and one of the major challenges in the process of assessing a potential quantum algorithm is | |
| # determining the amount of resources required to execute it on hardware. An algorithm may still be | |
| # helpful even when it cannot be executed, but is only truly helpful when it can. | |
| # | |
| # PennyLane is here to make that process easy, with our new resource estimation module: | |
| # `pennylane.estimator <https://docs.pennylane.ai/en/latest/code/qml_estimator.html>`__. | |
| # Fault tolerant quantum computers are on their way. But do we have useful algorithms to run on them? | |
| # Answering this question is a major challenge of quantum algorithm development. It involves | |
| # calculating algorithmic gate requirements to ensure reasonable runtimes and determining qubit | |
| # requirements to ensure they fit in a quantum computer's memory. | |
| # | |
| # PennyLane is here to make that process easy, with our new resource estimation module: | |
| # `pennylane.estimator <https://docs.pennylane.ai/en/latest/code/qml_estimator.html>`__. |
DSGuala
left a comment
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! Overall comments for now are that I think the demo could be more compact and some polishing is pending. Left several comments which hopefully help with this 🤞
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Show resolved
Hide resolved
josh146
left a comment
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 @AntonNI8! I read through and left some comments.
At a high level, my main comment is that the flow/story can be adjusted and tightened somewhat.
-
The introduction can be reduced, and made sure to emphasize what the how-to demo is going to show the reader to do.
-
The first section (with the timing of the hamiltonian computation) I find a bit distracting/doesn't quite fit. As a reader looking for 'how to do resource estimation', I've already decided to do resource estimation -- so no need to motivate it to me from the point of avoiding hamiltonian construction! However this section is still quite nice, so could be kept as an appendix.
-
For the overall story, I actually found the last section the easiest to follow. Putting myself into the shoes of a reader who wants to know, succinctly, 'how to do resource estimation', I recommend drawing inspiration from the last section, and using it to tell a cohesive story:
-
First section: show the reader how to do resource estimation with an existing, executable PL Kitaev model.
-
Second section:
- introduce the compact Hamiltonian and briefly describe why it is useful, and show that its resource estimation matches the full one.
- Show the reader how to rewrite their circuit using resource operators, and again compute the resources.
-
Third section: Change the default gateset, swap out one of the decompositions, and change the precision, and again compute the resources. I would probably avoid showing too many examples on single operators, as it is a bit distracting from the overall story.
-
Conclusion: the reader now knows how to do resource estimation in PL! Provide links to docs and other demos for more examples for them to read up on, or other configuration options that might be interesting.
-
Appendix
-
references
-
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Outdated
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Show resolved
Hide resolved
demonstrations_v2/re_how_to_use_pennylane_for_resource_estimation/demo.py
Show resolved
Hide resolved
|
|
||
|
|
||
| def gridsynth_decomp(precision): | ||
| t_resource_rep = qre.resource_rep(qre.T) |
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.
What is the resource_rep function? I think this is the first time a reader sees it
| t_gate_counts = qre.GateCount( | ||
| t_resource_rep, t_counts | ||
| ) # GateCounts tell us how many of this type of gate are used |
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.
Because I don't understand what resource rep is, I don't quite understand this function either!
| grisynth_rc = qre.ResourceConfig() | ||
| grisynth_rc.set_decomp(qre.RZ, gridsynth_decomp) | ||
| grisynth_cost_RZ = qre.estimate(qre.RZ(precision=1e-9), config=grisynth_rc) |
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.
More of a broader question outside the scope of this demo, but how come the way you define decompositions in the QRE API is different from how you do it in the regular PL API?
As a user, I would definitely love for them to be much closer (if not identical!) in API, as that makes PL a much more intuitive experience for me.
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.
@josh146 this is a great question!
Actually while we were developing this functionality the UI changed a few times. Initially we didn't even have a resource config object, we had a function qre.set_decmp(Op_type, new_decomp) which would override the base classes decomposition method.
The reason this doesn't currently sync up with PLs Alt and Fixed decomp structure is because at the time the graph based decomposition pipeline was also under development. There was no clear spec for what the UI should be.
I don't think there are any technical reasons for why were can't switch to a similar UI for setting the decomposition now to match PLs set decomposition.
Before submitting
Please complete the following checklist when submitting a PR:
Ensure that your tutorial executes correctly, and conforms to the
guidelines specified in the README.
Remember to do a grammar check of the content you include.
All tutorials conform to
PEP8 standards.
To auto format files, simply
pip install black, and thenrun
black -l 100 path/to/file.py.When all the above are checked, delete everything above the dashed
line and fill in the pull request template.
Title:
Summary:
Relevant references:
Possible Drawbacks:
Related GitHub Issues:
If you are writing a demonstration, please answer these questions to facilitate the marketing process.
GOALS — Why are we working on this now?
Eg. Promote a new PL feature or show a PL implementation of a recent paper.
AUDIENCE — Who is this for?
Eg. Chemistry researchers, PL educators, beginners in quantum computing.
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)