-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Transpiler pass that converts a generic circuit to PBC #15502
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
Changes from 1 commit
16688b8
d7f06d8
bff9262
09ab911
cd35a4d
9c2b9f0
6f09d15
e8434fc
826eb3b
2448eb7
e7cb094
82da8f7
642fb0e
76d3465
025297e
4859585
5e2cece
9cefe36
a04c1ac
7b046ff
57212a6
8bcdaf4
37449f0
db88f4d
572f0e3
0c1cb7b
9c28e17
9befd0f
3750154
dd0093a
ae7d9cb
7a7813c
c3d09a4
a15e778
8f6cbbd
399cb76
1f5bcb8
5b65ac4
b7ad3e6
bbd4812
ba71485
70d401e
7f03852
b2c1bda
3f64cbe
9533e44
0b75b1c
a70c1a9
e15c9d4
a146c03
65a5e75
e83d398
7fab525
52ae177
e24fde6
b58d030
7b69aef
3bd8e70
23544af
5ba0d47
dc24546
0c243f1
dd7301f
653a7d2
0bdcb42
ad52f46
9720d84
a11105c
34f741d
230b03e
2aaec38
bb80d47
fc8f385
56a05e5
4ef37dc
9064b73
80478eb
f0cf83e
737156f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| // This code is part of Qiskit. | ||
| // | ||
| // (C) Copyright IBM 2026 | ||
| // | ||
| // This code is licensed under the Apache License, Version 2.0. You may | ||
| // obtain a copy of this license in the LICENSE.txt file in the root directory | ||
| // of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
| // | ||
| // Any modifications or derivative works of this code must retain this | ||
| // copyright notice, and modified files need to carry a notice indicating | ||
| // that they have been altered from the originals. | ||
|
|
||
| use std::f64::consts::{FRAC_PI_2, FRAC_PI_4, FRAC_PI_8, PI}; | ||
|
|
||
| use qiskit_circuit::operations::StandardGate; | ||
|
|
||
| /// Map gates to a list of equivalent Pauli rotations and a global phase. | ||
| /// Each element of the list is of the form ((Pauli string, phase rescale factor, [qubit indices]), global phase). | ||
| /// For gates that didn't have a phase (e.g. X) | ||
| /// the phase rescale factor is simply the phase of the rotation gate. The convention is | ||
| /// `original_gate = PauliEvolutionGate(pauli, phase) * e^{i global_phase * phase}` | ||
|
|
||
| fn replace_gate_by_pauli_rotation( | ||
| gate: &StandardGate, | ||
| ) -> (&'static [(&str, f64, &'static [u32])], f64) { | ||
|
alexanderivrii marked this conversation as resolved.
Outdated
|
||
| match gate { | ||
| StandardGate::I => (&[("I", 0.0, &[0])], 0.0), | ||
| StandardGate::X => (&[("X", FRAC_PI_2, &[0])], FRAC_PI_2), | ||
| StandardGate::Y => (&[("Y", FRAC_PI_2, &[0])], FRAC_PI_2), | ||
| StandardGate::Z => (&[("Z", FRAC_PI_2, &[0])], FRAC_PI_2), | ||
| StandardGate::S => (&[("Z", FRAC_PI_4, &[0])], FRAC_PI_4), | ||
| StandardGate::Sdg => (&[("Z", -FRAC_PI_4, &[0])], -FRAC_PI_4), | ||
| StandardGate::T => (&[("Z", FRAC_PI_8, &[0])], FRAC_PI_8), | ||
| StandardGate::Tdg => (&[("Z", -FRAC_PI_8, &[0])], -FRAC_PI_8), | ||
| StandardGate::SX => (&[("X", FRAC_PI_4, &[0])], FRAC_PI_4), | ||
| StandardGate::SXdg => (&[("X", -FRAC_PI_4, &[0])], -FRAC_PI_4), | ||
| StandardGate::H => ( | ||
| &[ | ||
| ("Z", FRAC_PI_4, &[0]), | ||
| ("X", FRAC_PI_4, &[0]), | ||
| ("Z", FRAC_PI_4, &[0]), | ||
| ], | ||
| FRAC_PI_2, | ||
| ), | ||
| StandardGate::RZ => (&[("Z", 0.5, &[0])], 0.0), | ||
| StandardGate::RX => (&[("X", 0.5, &[0])], 0.0), | ||
| StandardGate::RY => (&[("Y", 0.5, &[0])], 0.0), | ||
| StandardGate::Phase => (&[("Z", 0.5, &[0])], 0.5), | ||
| StandardGate::U1 => (&[("Z", 0.5, &[0])], 0.5), | ||
| StandardGate::CX => ( | ||
| &[ | ||
| ("XZ", FRAC_PI_4, &[0, 1]), | ||
| ("Z", -FRAC_PI_4, &[0]), | ||
| ("X", -FRAC_PI_4, &[1]), | ||
| ], | ||
| -FRAC_PI_4, | ||
| ), | ||
| StandardGate::CZ => ( | ||
| &[ | ||
| ("ZZ", FRAC_PI_4, &[0, 1]), | ||
| ("Z", -FRAC_PI_4, &[0]), | ||
| ("Z", -FRAC_PI_4, &[1]), | ||
| ], | ||
| -FRAC_PI_4, | ||
| ), | ||
| StandardGate::CY => ( | ||
| &[ | ||
| ("YZ", FRAC_PI_4, &[0, 1]), | ||
| ("Z", -FRAC_PI_4, &[0]), | ||
| ("Y", -FRAC_PI_4, &[1]), | ||
| ], | ||
| -FRAC_PI_4, | ||
| ), | ||
| StandardGate::CH => ( | ||
| &[ | ||
| ("Z", FRAC_PI_2, &[1]), | ||
| ("X", FRAC_PI_4, &[1]), | ||
| ("Z", 3.0 * FRAC_PI_8, &[1]), | ||
| ("XZ", FRAC_PI_4, &[0, 1]), | ||
| ("Z", -FRAC_PI_4, &[0]), | ||
| ("X", -FRAC_PI_4, &[1]), | ||
| ("Z", FRAC_PI_8, &[1]), | ||
| ("X", FRAC_PI_4, &[1]), | ||
| ], | ||
| 3.0 * FRAC_PI_4, | ||
| ), | ||
| StandardGate::CS => ( | ||
| &[ | ||
| ("ZZ", -FRAC_PI_8, &[0, 1]), | ||
| ("Z", FRAC_PI_8, &[0]), | ||
| ("Z", FRAC_PI_8, &[1]), | ||
| ], | ||
| FRAC_PI_8, | ||
| ), | ||
| StandardGate::CSdg => ( | ||
| &[ | ||
| ("ZZ", FRAC_PI_8, &[0, 1]), | ||
| ("Z", -FRAC_PI_8, &[0]), | ||
| ("Z", -FRAC_PI_8, &[1]), | ||
| ], | ||
| -FRAC_PI_8, | ||
| ), | ||
| StandardGate::CSX => ( | ||
| &[ | ||
| ("XZ", -FRAC_PI_8, &[0, 1]), | ||
| ("Z", FRAC_PI_8, &[0]), | ||
| ("X", FRAC_PI_8, &[1]), | ||
| ], | ||
| FRAC_PI_8, | ||
| ), | ||
| StandardGate::Swap => ( | ||
| &[ | ||
| ("XX", FRAC_PI_4, &[0, 1]), | ||
| ("YY", FRAC_PI_4, &[0, 1]), | ||
| ("ZZ", FRAC_PI_4, &[0, 1]), | ||
| ], | ||
| FRAC_PI_4, | ||
| ), | ||
| StandardGate::ISwap => ( | ||
| &[("XX", -FRAC_PI_4, &[0, 1]), ("YY", -FRAC_PI_4, &[0, 1])], | ||
| 0.0, | ||
| ), | ||
| StandardGate::DCX => ( | ||
| &[ | ||
| ("XZ", FRAC_PI_4, &[0, 1]), | ||
| ("Z", -FRAC_PI_4, &[0]), | ||
| ("X", -FRAC_PI_4, &[1]), | ||
| ("XZ", FRAC_PI_4, &[0, 1]), | ||
| ("Z", -FRAC_PI_4, &[0]), | ||
| ("X", -FRAC_PI_4, &[1]), | ||
| ], | ||
| -FRAC_PI_2, | ||
| ), | ||
| StandardGate::ECR => ( | ||
| &[ | ||
| ("Y", -FRAC_PI_2, &[0]), | ||
| ("Z", FRAC_PI_4, &[0]), | ||
| ("X", -FRAC_PI_4, &[1]), | ||
| ("XZ", FRAC_PI_4, &[0, 1]), | ||
| ("Z", -FRAC_PI_4, &[0]), | ||
| ("X", -FRAC_PI_4, &[1]), | ||
| ], | ||
| -2.0 * PI, | ||
| ), | ||
| StandardGate::RZZ => (&[("ZZ", 0.5, &[0, 1])], 0.0), | ||
| StandardGate::RXX => (&[("XX", 0.5, &[0, 1])], 0.0), | ||
| StandardGate::RYY => (&[("YY", 0.5, &[0, 1])], 0.0), | ||
| StandardGate::RZX => (&[("ZX", 0.5, &[0, 1])], 0.0), | ||
| StandardGate::CPhase => ( | ||
| &[("ZZ", -0.25, &[0, 1]), ("Z", 0.25, &[0]), ("Z", 0.25, &[1])], | ||
| 0.25, | ||
| ), | ||
| StandardGate::CU1 => ( | ||
| &[("ZZ", -0.25, &[0, 1]), ("Z", 0.25, &[0]), ("Z", 0.25, &[1])], | ||
| 0.25, | ||
| ), | ||
| StandardGate::CRZ => (&[("ZZ", -0.25, &[0, 1]), ("Z", 0.25, &[1])], 0.0), | ||
| StandardGate::CRX => (&[("XZ", -0.25, &[0, 1]), ("X", 0.25, &[1])], 0.0), | ||
| StandardGate::CRY => (&[("YZ", -0.25, &[0, 1]), ("Y", 0.25, &[1])], 0.0), | ||
| _ => unreachable!( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this distinction is to give a better indication of what went wrong. With
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replaced unreachable be panic in 0b75b1c |
||
| "This is only called for one and two qubit gates with no paramers or with a single parameter." | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now support any standard gate with up to 1 parameter, and can update this message, right?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but this is unreachable since we call this function only for 1q and 2q gates with 0 or 1 parameters ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replaced unreachable be panic in 0b75b1c |
||
| ), | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.