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

Add 2q fractional gates to the UnitarySynthesis tranpiler pass #13568

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
89ca81e
TwoQubitControlledUDecomposer to _decomposer_2q_from_basis_gates
ShellyGarion Dec 16, 2024
077ecb9
update (temporarily) basis gates in test
ShellyGarion Dec 16, 2024
18b20f6
minor fix
ShellyGarion Dec 18, 2024
967da13
add EulerBasis as a parameter to TwoQubitControlledUDecomposer
ShellyGarion Dec 19, 2024
3bb10fd
fix global_phase calculation in TwoQubitContolledUDecomposer
ShellyGarion Dec 22, 2024
14c7aac
add TwoQubitControlledUDecomposer to the docs
ShellyGarion Dec 22, 2024
eeff4cd
make the choice of kak_gate deterministic
ShellyGarion Dec 22, 2024
043a795
Merge branch 'main' into unitary_synth
ShellyGarion Jan 13, 2025
b94070a
remove XXDecomposer from _decomposer_2q_from_basis_gates
ShellyGarion Jan 13, 2025
0a1644b
make call_inner pub, add Clone, Debug
ShellyGarion Jan 15, 2025
48fec9b
add TwoQubitControlledUDecomposer to unitary_synthesis.rs
ShellyGarion Jan 15, 2025
009d87e
merge main branch, fix conflict
ShellyGarion Jan 15, 2025
85e2962
Fix exit condition for GOODBYE_SET and PARAM_SET
ElePT Jan 16, 2025
c5d0c97
fix conflict with main branch
ShellyGarion Jan 16, 2025
d7b84e9
make DEFAULT_ATOL public
ShellyGarion Jan 16, 2025
ea9a2d0
add TwoQubitControlledUDecomposer to synth_su4_sequence
ShellyGarion Jan 16, 2025
132a44f
Add support for parametrized decomposer gate in apply_synth_sequence
ElePT Jan 20, 2025
b1cb5a0
change DecomposerType enum to fix clippy error
ShellyGarion Jan 20, 2025
9cdf2da
add a random unitary test to test_parametrized_basis_gate_in_target
ShellyGarion Jan 20, 2025
1be749d
add public new_inner for TwoQubitControlledUDecomposer
ShellyGarion Jan 21, 2025
1495781
replace default 'ZYZ' by 'ZXZ' in TwoQubitControlledUDecomposer
ShellyGarion Jan 21, 2025
231af7f
remove using py in rust functions
ShellyGarion Jan 23, 2025
bb874c1
minor update to test
ShellyGarion Jan 23, 2025
c2a9ad4
make atol optional
ShellyGarion Jan 23, 2025
d39c005
fix conflict with main branch
ShellyGarion Jan 23, 2025
106ae4a
add a test with fractional gates in the backend
ShellyGarion Jan 23, 2025
9131e3d
add release notes
ShellyGarion Jan 23, 2025
6a82649
enhance tests following review
ShellyGarion Jan 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions crates/accelerate/src/two_qubit_decompose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
ShellyGarion marked this conversation as resolved.
Show resolved Hide resolved
type InverseReturn = (Option<StandardGate>, SmallVec<[f64; 3]>, SmallVec<[u8; 2]>);

/// Decompose two-qubit unitary in terms of a desired
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Show resolved Hide 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]));
Expand Down Expand Up @@ -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>,
Expand All @@ -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();
Expand Down Expand Up @@ -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.
Show resolved Hide resolved
for gate in unitary_c1l.gates.into_iter() {
gates1.gates.push((Some(gate.0), gate.1, smallvec![1]));
}
Expand All @@ -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"))]
Copy link
Member Author

@ShellyGarion ShellyGarion Jan 20, 2025

Choose a reason for hiding this comment

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

should we replace the default value here to "ZXZ"? If so, we should better do this in other places of this file.

Copy link
Member Author

Choose a reason for hiding this comment

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

I replaced the default to "ZXZ". Should we do it in other classes as well?

pub fn new(
py: Python,
rxx_equivalent_gate: RXXEquivalent,
euler_basis: &str,
) -> PyResult<Self> {
let atol = DEFAULT_ATOL;
let test_angles = [0.2, 0.3, PI2];

Expand Down Expand Up @@ -2819,6 +2825,7 @@ impl TwoQubitControlledUDecomposer {
Ok(TwoQubitControlledUDecomposer {
scale,
rxx_equivalent_gate,
euler_basis: EulerBasis::__new__(euler_basis)?,
})
}

Expand Down
Loading
Loading