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

Introduce fractional gates #1734

Merged
merged 25 commits into from
Nov 7, 2024
Merged

Introduce fractional gates #1734

merged 25 commits into from
Nov 7, 2024

Conversation

kaelynj
Copy link
Collaborator

@kaelynj kaelynj commented Jul 18, 2024

Closes #1526 (and will likely close #1471 @lerongil).

FYI @nbronn here's the draft of the fractional gates page.

@kaelynj kaelynj requested a review from javabster July 18, 2024 16:01
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@qiskit-bot
Copy link
Contributor

Thanks for contributing to Qiskit documentation!

Before your PR can be merged, it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. Thanks! 🙌

Copy link
Collaborator

@javabster javabster left a comment

Choose a reason for hiding this comment

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

Overall looks great!! Just a few minor comments from me

docs/guides/fractional-gates.ipynb Outdated Show resolved Hide resolved
"outputs": [],
"source": [
"# Draw timeline of circuit with conventional gates\n",
"draw_timeline(ising_circuit_conventional, idle_wires=False, time_range=(0, 500), style=IQXSimple())"
Copy link
Collaborator

Choose a reason for hiding this comment

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

are these draw_timeline functions supposed to print out an image? I don't see anything in the preview

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They will, the code won't work until the use_fractional_gates flag is enabled. That's part of why I put in the temporary code to show what the images will look like.

"id": "22007518-b6fb-4341-b483-894feb5d8947",
"metadata": {},
"source": [
"For workflows that require many single qubit $R_X(\\theta)$ or two-qubit rotations, especially ones where the rotation angle $\\theta$ is small (such as in a variational ansatze or when simulating the time evolution of quantum systems), this constraint causes the circuit depth to grow quite quickly. Thankfully however, the fleet of IBM Quantum QPUs now support *fractional gates* which can significantly reduce the circuit depth for workflows like these."
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this info could be brought out in the first paragraph before launching into the code examples, otherwise I feel like I have to read a lot before I get to the point. I think generally a better format for short-attention-span-readers (i.e. most docs readers lets be honest 😆) is to make the point in the first paragraph and then evidence it with code examples second

Copy link
Contributor

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

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

Thanks for writing up this nice tutorial. I added several suggestions.

"source": [
"# Fractional gates\n",
"\n",
"This page introduces two newly supported gate types on the IBM Quantum fleet of QPUs. These *fractional* gates are supported on:\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not correct. Eagle must implement RZX and Heron must implement RZZ. Unfortunately we don't plan to provide fractional gates for Eagle, so in here you can just say fractional gates will be provided with Heron devices.

"source": [
"## How to use fractional gates\n",
"\n",
"Internally, these fractional gates work by dynamically modifying the microwave pulses that are sent to individual qubits based on the angle, $\\theta$, that a circuit instruction specifies. This has the advantage of shorter gate durations -- and thus lower dephasing error, especially for small angles -- which reduces the overall circuit duration, in addition to the cost savings of executing fewer gates.\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is bit misleading because we don't shorten pulse duration with the modification. We can reduce gate count by directly implementing RZZ and RX, and thus we can reduce the circuit duration. Gate duration will be the same.

"backend = service.least_busy(use_fractional_gates=True)\n",
"```\n",
"\n",
"To demonstrate how to use fractional gates, the code example below depicts an example workflow of simulating the dynamics of an Ising chain using fractional gates. Then the circuit duration is compared against a backend which does not use fractional gates."
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's worth showing control flow instructions such as if_else and for_loop will be removed (and thus we can support fractional gates and control flow only exclusively). It is important to say that this behavior might change in the future as our backend software stack evolves.

"source": [
"## Where to use fractional gates\n",
"\n",
"Historically, the basis gates available on QPUs in the fleet of IBM Quantum hardware have been **`ECR`**, **`X`**, **`RZ`**, **`SX`**, and **`ID`** which creates a constraint on circuits with single and two-qubit rotations. For example, an $R_X(\\theta)$ gate, when transpiled to a QPU in the IBM Quantum fleet, must decompose into a series of $RZ$ and $\\sqrt{X}$ gates -- creating a circuit with a depth of five instead of one.\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

RZ is virtual-Z gate and zero cost. Here you can replace two physical pulses implementing SX gates with one pulse.

@@ -126,8 +126,42 @@
"title": "Circuits and operators",
"children": [
{
<<<<<<< HEAD
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bad merge conflict

@@ -0,0 +1,365 @@
{
Copy link
Collaborator

@blakejohnson blakejohnson Oct 28, 2024

Choose a reason for hiding this comment

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

For the initial release, we are just adding rzz and rx on Heron. Additional gates for Eagle will come later.


Reply via ReviewNB

@@ -0,0 +1,365 @@
{
Copy link
Collaborator

@blakejohnson blakejohnson Oct 28, 2024

Choose a reason for hiding this comment

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

In terms of describing the benefit, we can be more concrete. Specifically:

With rx gates, all single-qubit rotations (u3) can be achieved with a single control pulse, rather than being decomposed into two sx gates and three rz gates. This reduces the duration and error for single-qubit gates by up to a factor of two.

Similarly, with rzz gates, this avoids a decomposition into multiple cz gates for a common operation in time evolution circuits.

Also, can we please also show an example of using use_fractional_gates with service.backend(...)? The least_busy(...) method is also not guaranteed to return a Heron processor, which is necessary for these examples to work.


Reply via ReviewNB

@@ -0,0 +1,365 @@
{
Copy link
Collaborator

@blakejohnson blakejohnson Oct 28, 2024

Choose a reason for hiding this comment

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

This paragraph needs to be updated to reference the ISA of the Heron processors, which is cz based rather than ecr.


Reply via ReviewNB

@@ -0,0 +1,365 @@
{
Copy link
Collaborator

@blakejohnson blakejohnson Oct 28, 2024

Choose a reason for hiding this comment

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

Need to update the example to ensure we pick a Heron processor.


Reply via ReviewNB

@@ -0,0 +1,365 @@
{
Copy link
Collaborator

@blakejohnson blakejohnson Oct 28, 2024

Choose a reason for hiding this comment

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

Again, please update for a Heron processor.


Reply via ReviewNB

@blakejohnson
Copy link
Collaborator

In addition to the comments I added from ReviewNB, we also need a section on when NOT to use fractional gates. In particular, we currently do not support using fractional gates with dynamic circuits or with any error mitigation features of the Qiskit Runtime. Furthermore, the Qiskit transpiler has limited capability to use rzz in its optimization passes. So, this is mostly relevant for users hand-crafting circuits and using the Sampler.

@@ -0,0 +1,365 @@
{
Copy link
Collaborator

@blakejohnson blakejohnson Oct 28, 2024

Choose a reason for hiding this comment

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

One other comment is that we support rzz(theta) for theta in the range of [0, pi].


Reply via ReviewNB

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got it, is that also true for the rx(theta) gate?

Copy link
Contributor

Choose a reason for hiding this comment

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

No Rx supports full range.

Copy link
Contributor

Choose a reason for hiding this comment

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

The range of rzz is [0, pi/2].

@nkanazawa1989
Copy link
Contributor

@abbycross Can you also mention that the "error" value of rx (rzz) gate reported in Target is a copy of non-fractional counterpart, i.e. sx (cz) gate? This is worth noting because user may want to choose optimal decomposition based on net error, but this strategy doesn't work currently because the actual error of fractional gates are not reported.

Since gate time of fractional/non-fractional gates are the same, we can expect their error values are also almost comparable when dominant source of error is relaxation, but they could differ because of the difference in calibration protocol.

@kaelynj
Copy link
Collaborator Author

kaelynj commented Nov 6, 2024

@abbycross Can you also mention that the "error" value of rx (rzz) gate reported in Target is a copy of non-fractional counterpart, i.e. sx (cz) gate? This is worth noting because user may want to choose optimal decomposition based on net error, but this strategy doesn't work currently because the actual error of fractional gates are not reported.

Since gate time of fractional/non-fractional gates are the same, we can expect their error values are also almost comparable when dominant source of error is relaxation, but they could differ because of the difference in calibration protocol.

Just added this as a note in the first section of the page. @blakejohnson and @javabster I believe this page should be ready to go now that fractional gates are live.

@yaelbh
Copy link
Contributor

yaelbh commented Nov 7, 2024

@kaelynj Can you please check again my comments? Some of them were not addressed. Thanks.

Copy link
Collaborator

@abbycross abbycross left a comment

Choose a reason for hiding this comment

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

Merging now - may require some followup tweaks

@abbycross abbycross added this pull request to the merge queue Nov 7, 2024
Merged via the queue into main with commit 0b6711a Nov 7, 2024
4 checks passed
@abbycross abbycross deleted the kjf/fractional-gates branch November 7, 2024 14:09
github-merge-queue bot pushed a commit that referenced this pull request Nov 7, 2024
Closes #1527 

~~Currently blocked by #1734 which will need to be merged before CI
passes.~~

Utilizing fractional gates is a flag that is set when requesting a
backend from a `QiskitRuntimeService()` instance and there didn't appear
to be a clear page for a flag to be explained. I ended up adding it as
an admonition to the "get started with primitives" page.

---------

Co-authored-by: Eric Arellano <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[NEW PAGE] introduction to fractional gates Update basis gate set documentation
9 participants