-
Notifications
You must be signed in to change notification settings - Fork 3k
Add 2q fractional gates to the UnitarySynthesis transpiler pass
#13568
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 17 commits
89ca81e
077ecb9
18b20f6
967da13
3bb10fd
14c7aac
eeff4cd
043a795
b94070a
0a1644b
48fec9b
009d87e
85e2962
c5d0c97
d7b84e9
ea9a2d0
132a44f
b1cb5a0
9cdf2da
1be749d
1495781
231af7f
bb874c1
c2a9ad4
d39c005
106ae4a
9131e3d
6a82649
23b9e6b
5bb55b5
f4da2da
1bd71c5
dd1b38d
55556f8
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 |
|---|---|---|
|
|
@@ -2445,14 +2445,16 @@ impl RXXEquivalent { | |
| } | ||
| } | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| #[pyclass(module = "qiskit._accelerate.two_qubit_decompose", subclass)] | ||
| pub struct TwoQubitControlledUDecomposer { | ||
| rxx_equivalent_gate: RXXEquivalent, | ||
| euler_basis: EulerBasis, | ||
| #[pyo3(get)] | ||
| scale: f64, | ||
| } | ||
|
|
||
| const DEFAULT_ATOL: f64 = 1e-12; | ||
| pub const DEFAULT_ATOL: f64 = 1e-12; | ||
| type InverseReturn = (Option<StandardGate>, SmallVec<[f64; 3]>, SmallVec<[u8; 2]>); | ||
|
|
||
| /// Decompose two-qubit unitary in terms of a desired | ||
|
|
@@ -2544,9 +2546,8 @@ impl TwoQubitControlledUDecomposer { | |
| let decomposer_inv = | ||
| TwoQubitWeylDecomposition::new_inner(mat.view(), Some(DEFAULT_FIDELITY), None)?; | ||
|
|
||
| let euler_basis = EulerBasis::ZYZ; | ||
| let mut target_1q_basis_list = EulerBasisSet::new(); | ||
| target_1q_basis_list.add_basis(euler_basis); | ||
| target_1q_basis_list.add_basis(self.euler_basis); | ||
|
|
||
| // Express the RXXGate in terms of the user-provided RXXGate equivalent gate. | ||
| let mut gates = Vec::with_capacity(13); | ||
|
|
@@ -2583,14 +2584,14 @@ impl TwoQubitControlledUDecomposer { | |
| gates.push((None, smallvec![self.scale * angle], smallvec![0, 1])); | ||
|
|
||
| if let Some(unitary_k1r) = unitary_k1r { | ||
| global_phase += unitary_k1r.global_phase; | ||
| global_phase -= unitary_k1r.global_phase; | ||
| for gate in unitary_k1r.gates.into_iter().rev() { | ||
| let (inv_gate_name, inv_gate_params) = invert_1q_gate(gate); | ||
| gates.push((Some(inv_gate_name), inv_gate_params, smallvec![0])); | ||
| } | ||
| } | ||
| if let Some(unitary_k1l) = unitary_k1l { | ||
| global_phase += unitary_k1l.global_phase; | ||
| global_phase -= unitary_k1l.global_phase; | ||
|
ElePT marked this conversation as resolved.
|
||
| for gate in unitary_k1l.gates.into_iter().rev() { | ||
| let (inv_gate_name, inv_gate_params) = invert_1q_gate(gate); | ||
| gates.push((Some(inv_gate_name), inv_gate_params, smallvec![1])); | ||
|
|
@@ -2678,7 +2679,7 @@ impl TwoQubitControlledUDecomposer { | |
|
|
||
| /// Returns the Weyl decomposition in circuit form. | ||
| /// Note: atol is passed to OneQubitEulerDecomposer. | ||
| fn call_inner( | ||
| pub fn call_inner( | ||
| &self, | ||
| py: Python, | ||
| unitary: ArrayView2<Complex64>, | ||
|
|
@@ -2687,9 +2688,8 @@ impl TwoQubitControlledUDecomposer { | |
| let target_decomposed = | ||
| TwoQubitWeylDecomposition::new_inner(unitary, Some(DEFAULT_FIDELITY), None)?; | ||
|
|
||
| let euler_basis = EulerBasis::ZYZ; | ||
| let mut target_1q_basis_list = EulerBasisSet::new(); | ||
| target_1q_basis_list.add_basis(euler_basis); | ||
| target_1q_basis_list.add_basis(self.euler_basis); | ||
|
|
||
| let c1r = target_decomposed.K1r.view(); | ||
| let c2r = target_decomposed.K2r.view(); | ||
|
|
@@ -2728,13 +2728,13 @@ impl TwoQubitControlledUDecomposer { | |
| global_phase += gates1.global_phase; | ||
|
|
||
| if let Some(unitary_c1r) = unitary_c1r { | ||
| global_phase -= unitary_c1r.global_phase; | ||
| global_phase += unitary_c1r.global_phase; | ||
| for gate in unitary_c1r.gates.into_iter() { | ||
| gates1.gates.push((Some(gate.0), gate.1, smallvec![0])); | ||
| } | ||
| } | ||
| if let Some(unitary_c1l) = unitary_c1l { | ||
| global_phase -= unitary_c1l.global_phase; | ||
| global_phase += unitary_c1l.global_phase; | ||
|
ElePT marked this conversation as resolved.
|
||
| for gate in unitary_c1l.gates.into_iter() { | ||
| gates1.gates.push((Some(gate.0), gate.1, smallvec![1])); | ||
| } | ||
|
|
@@ -2751,11 +2751,17 @@ impl TwoQubitControlledUDecomposer { | |
| /// Args: | ||
| /// rxx_equivalent_gate: Gate that is locally equivalent to an :class:`.RXXGate`: | ||
| /// :math:`U \sim U_d(\alpha, 0, 0) \sim \text{Ctrl-U}` gate. | ||
| /// euler_basis: Basis string to be provided to :class:`.OneQubitEulerDecomposer` | ||
| /// for 1Q synthesis. | ||
| /// Raises: | ||
| /// QiskitError: If the gate is not locally equivalent to an :class:`.RXXGate`. | ||
| #[new] | ||
| #[pyo3(signature=(rxx_equivalent_gate))] | ||
| pub fn new(py: Python, rxx_equivalent_gate: RXXEquivalent) -> PyResult<Self> { | ||
| #[pyo3(signature=(rxx_equivalent_gate, euler_basis="ZYZ"))] | ||
|
ShellyGarion marked this conversation as resolved.
Outdated
|
||
| pub fn new( | ||
| py: Python, | ||
| rxx_equivalent_gate: RXXEquivalent, | ||
| euler_basis: &str, | ||
| ) -> PyResult<Self> { | ||
| let atol = DEFAULT_ATOL; | ||
|
Comment on lines
+2747
to
2824
Contributor
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. I know we discussed the addition of a
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. the
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.
Contributor
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, let's keep them. |
||
| let test_angles = [0.2, 0.3, PI2]; | ||
|
|
||
|
|
@@ -2819,6 +2825,7 @@ impl TwoQubitControlledUDecomposer { | |
| Ok(TwoQubitControlledUDecomposer { | ||
| scale, | ||
| rxx_equivalent_gate, | ||
| euler_basis: EulerBasis::__new__(euler_basis)?, | ||
| }) | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.