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

include ecr native gate for pulse scaling #9397

Merged
merged 20 commits into from
Jan 31, 2023

Conversation

nbronn
Copy link
Contributor

@nbronn nbronn commented Jan 19, 2023

Summary

The addition of IBM Quantum backends without native cx gates (i.e., ibm_sherbrooke where the native entangling gate is ecr, echoed cross resonance) is not compatible with the pulse scaling done by RZXCalibrationBuilder and RZXCalibrationBuilderNoEcho. This PR addresses this problem by treating the cx and ecr gate on equal footing in those classes.

Details and comments

The logic that handles extracting information from the entangling gates has been moved to _check_calibration_type and the corresponding gate is checked for in backend.defaults().instruction_schedule_map before assigning the correct schedule and corresponding CRCalType (either by definition as it is only assigned in one direction for ecr or an inspection of which qubit the on-resonance compensation tones are applied to).

The unit test TestCalibrationBuilder is also updated for compatibility with the same logic, however the FakeSherbrooke backend from qiskit.providers.fake_provider currently does not have a backend.defaults() method to obtain the instruction schedule map from.

@nbronn nbronn requested a review from a team as a code owner January 19, 2023 22:33
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

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.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Jan 19, 2023

Pull Request Test Coverage Report for Build 4055132298

  • 30 of 39 (76.92%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.04%) to 85.223%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/calibration/rzx_builder.py 27 36 75.0%
Totals Coverage Status
Change from base Build 4055127961: -0.04%
Covered Lines: 66835
Relevant Lines: 78424

💛 - Coveralls

@nkanazawa1989 nkanazawa1989 added the mod: pulse Related to the Pulse module label Jan 20, 2023
@nkanazawa1989 nkanazawa1989 self-assigned this Jan 20, 2023
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 @nbronn I like the new design of CRCalType enum. I think you also need to write a release note (as new feature).

qiskit/transpiler/passes/calibration/rzx_builder.py Outdated Show resolved Hide resolved
@@ -57,15 +57,21 @@ def setUp(self):
def _get_cr(time_inst, name):
return isinstance(time_inst[1], Play) and time_inst[1].pulse.name.startswith(name)

cx_sched = self.inst_map.get("cx", (0, 1))
qubits = (0, 1)
Copy link
Contributor

@nkanazawa1989 nkanazawa1989 Jan 20, 2023

Choose a reason for hiding this comment

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

Why this must be changed? This instmap is the past snapshot of Hanoi which must be the forward CX. You need to upgrade this test class with ddt to run both on (fake) Hanoi and (fake) Sherbrooke to test CX and ECR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally changed cx_sched to cr_sched to treat the native entangling gates on equal footing. But I think you are correct in that I would need to make a separate test class with ddt to test the ecr case with (fake) Sherbrooke. Might it make more sense to run the same code for the two cases of backends (also this assumes Hanoi will always default to cx and Sherbrooke to ecr)?

Copy link
Contributor

@nkanazawa1989 nkanazawa1989 Jan 21, 2023

Choose a reason for hiding this comment

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

ddt with two backends sounds better, but you need overhaul of the test class because it is currently tied to Hanoi. You can remove setup and add a method to get individual play instruction, e.g. self.u0p_play -> def get_u0p_play(self, backend): and then pass the backend with ddt at each test function.

Hanoi and Sherbrooke might change in future, but fake backend data is locally stored as a part of terra and the object is built from there. So the gate will be always cx for Hanoi (and I guess ecr for Sherbrooke) unless someone manually update the backend data (there is a command to update the data).

@nkanazawa1989
Copy link
Contributor

fix #9308

Comment on lines 9 to 15
issues:
- |
Currently the FakeSherbrooke backend does not contain `.defaults()` from which
the instruction schedule map is obtained. The unit test `TestCalibrationBuilder`
requires this to check `ecr` operations work similarly to the `cx` gate case.
As of this PR, `ibm_sherbrooke` is the only backend with native `ecr` gates, so
this requires updating.
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be resolved. The FakeSherbrooke backend is based on BackendV2 which doesn't have configuration(), properties(), or defaults() methods. The calibrations for gates are part of the Target object (backend.target) and you can get an InstructionScheduleMap from a target (backend.target.instruction_schedule_map()). This pass was updated in #9343 to take in a target directly so when you run with FakeSherbrooke you should just be able to do:

from qiskit.transpiler.passes import RZXCalibrationBuilder
from qiskit.providers.fake_provider import FakeSherbrooke

cal_pass = RZXCalibrationBuilder(target=FakeSherbrooke().target)

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 that easy. We need to build reference schedule to test, but currently the builder is tied to the V1 accessors and we cannot generate the schedule with FakeV2. I wrote this issue and assigned a team member to it. We plan to update the builder in 0.24, and then we can write a test with FakeSherbrooke. The plan is (since @nbronn needs this code in a few weeks) to wait for 0.23 release and merge this PR without test. Then add the test with followup PR after above issue is resolved.

Copy link
Contributor

Choose a reason for hiding this comment

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

@nbronn You can remove this issue note. I don't think end-users have concern about unit-test. You can leave this as a comment in the unit-test file so that developer can be aware of this.

@nkanazawa1989 nkanazawa1989 added the on hold Can not fix yet label Jan 26, 2023
@@ -88,6 +230,93 @@ def compute_stretch_width(self, play_gaussian_square_pulse, theta):
target_area = abs(theta) / self.__angle * full_area
return max(0, target_area - risefall_area)

def test_native_cr(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

This must be a part of TestRZXCalibrationBuilder because this class is a superclass of two Rzx passes of echo and non-echo. You need to write tests for

  • native cr with echo
  • backward cr with echo
  • native cr with non-echo (backward for non echo is not supported)

with both FakeHanoi, FakeHanoiV2 and Sherbrooke.

Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

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

Please also update EchoRZXWeylDecomposition to include the ECR.

@eggerdj
Copy link
Contributor

eggerdj commented Jan 26, 2023

@nbronn
Copy link
Contributor Author

nbronn commented Jan 26, 2023

Please also update EchoRZXWeylDecomposition to include the ECR.

Modified EchoRZXWeylDecomposition to use the same logic as rzx_builder.py.

@nbronn
Copy link
Contributor Author

nbronn commented Jan 26, 2023

While we are at it, should we add GaussianSquareDrag to this list:

https://github.com/Qiskit/qiskit-terra/blob/925f9f3abfdee4faeae67503082d7877f080c2ed/qiskit/transpiler/passes/calibration/rzx_builder.py#L330

?

It is my understanding that the GaussianSquareDrag were only used as compensation tones for DirectCX. Additionally, the DirectCX includes extra pulses that should not scale with the CR angle, so including them will take extra consideration that I believe is outside the scope of this PR.

@nkanazawa1989
Copy link
Contributor

nkanazawa1989 commented Jan 27, 2023

If I understand correctly GaussianSquareDrag just adds DRAG component to the risefall and can be applied to ECR to deal with noisy spectrum. So I think adding drag version to validation makes sense, though I'm not sure how we can scale this pulse in small angle regime where we need to renormalize amplitude.

It is my understanding that the GaussianSquareDrag were only used as compensation tones for DirectCX.

I think DirectCX uses GaussianSquareEcho in this PR.

@eggerdj
Copy link
Contributor

eggerdj commented Jan 27, 2023

Replying to #9397 (comment) if you remove the flat-top part you have a normal Gaussian, you can still scale the amplitude but you might have some miscalibrations you need to compensate for. This is anyhow the case for Gaussian square without the drag.

@nkanazawa1989
Copy link
Contributor

Yes. The question is how we scale the drag component in general. Since this is proportional to the derivative of amplitude, the drag coefficient must be changed with the amplitude. AFAIK there is no established method for this.

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 @nbronn . This almost looks good to me. This is one last feedback for unittest cleanup.

Comment on lines 9 to 15
issues:
- |
Currently the FakeSherbrooke backend does not contain `.defaults()` from which
the instruction schedule map is obtained. The unit test `TestCalibrationBuilder`
requires this to check `ecr` operations work similarly to the `cx` gate case.
As of this PR, `ibm_sherbrooke` is the only backend with native `ecr` gates, so
this requires updating.
Copy link
Contributor

Choose a reason for hiding this comment

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

@nbronn You can remove this issue note. I don't think end-users have concern about unit-test. You can leave this as a comment in the unit-test file so that developer can be aware of this.

test/python/transpiler/test_calibrationbuilder.py Outdated Show resolved Hide resolved
test/python/transpiler/test_calibrationbuilder.py Outdated Show resolved Hide resolved
test/python/transpiler/test_calibrationbuilder.py Outdated Show resolved Hide resolved
test/python/transpiler/test_calibrationbuilder.py Outdated Show resolved Hide resolved
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 @nbronn this looks good to me.

Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

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

This now has the ECR and Weyl decomposition update. LGTM. Thanks Nick.

@nkanazawa1989 nkanazawa1989 added automerge and removed on hold Can not fix yet labels Jan 31, 2023
@mergify mergify bot merged commit 5108380 into Qiskit:main Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod: pulse Related to the Pulse module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants