Skip to content

Commit

Permalink
Remove duplicated weyl_coordinates python function (#13193)
Browse files Browse the repository at this point in the history
This commit removes the weyl_coordinates() function from the private
qiskit.synthesis.two_qubit.weyl module. This function's internal use was
ported to rust as part of #11019 but it left the python implementation
intact while we ensured the rust implementation was reliable longer
term. Since then we've ported the majority of the two qubit synthesis to
rust now and the only usage of this python implementation was the unit
tests. This commit removes the python implementation and the entire
internal weyl module as nothing uses it anymore. A python interface is
added to the rust function and the tests are updated to call that
instead.

Fixes: #8459
  • Loading branch information
mtreinish authored Oct 15, 2024
1 parent fbfe738 commit 54fe09b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 100 deletions.
17 changes: 17 additions & 0 deletions crates/accelerate/src/two_qubit_decompose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ fn py_decompose_two_qubit_product_gate(
))
}

/// Computes the Weyl coordinates for a given two-qubit unitary matrix.
///
/// Args:
/// U (np.ndarray): Input two-qubit unitary.
///
/// Returns:
/// np.ndarray: Array of the 3 Weyl coordinates.
#[pyfunction]
fn weyl_coordinates(py: Python, unitary: PyReadonlyArray2<Complex64>) -> PyObject {
let array = unitary.as_array();
__weyl_coordinates(array.into_faer_complex())
.to_vec()
.into_pyarray_bound(py)
.into()
}

fn __weyl_coordinates(unitary: MatRef<c64>) -> [f64; 3] {
let uscaled = scale(C1 / unitary.determinant().powf(0.25)) * unitary;
let uup = transform_from_magic_basis(uscaled);
Expand Down Expand Up @@ -2353,6 +2369,7 @@ pub fn two_qubit_decompose(m: &Bound<PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(local_equivalence))?;
m.add_wrapped(wrap_pyfunction!(py_trace_to_fid))?;
m.add_wrapped(wrap_pyfunction!(py_ud))?;
m.add_wrapped(wrap_pyfunction!(weyl_coordinates))?;
m.add_class::<TwoQubitGateSequence>()?;
m.add_class::<TwoQubitWeylDecomposition>()?;
m.add_class::<Specialization>()?;
Expand Down
97 changes: 0 additions & 97 deletions qiskit/synthesis/two_qubit/weyl.py

This file was deleted.

4 changes: 2 additions & 2 deletions test/python/synthesis/test_weyl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import numpy as np
from numpy.testing import assert_allclose

from qiskit._accelerate.two_qubit_decompose import weyl_coordinates
from qiskit.quantum_info.random import random_unitary
from qiskit.synthesis.two_qubit.weyl import weyl_coordinates
from qiskit.synthesis.two_qubit.local_invariance import (
two_qubit_local_invariants,
local_equivalence,
Expand All @@ -32,7 +32,7 @@ class TestWeyl(QiskitTestCase):
def test_weyl_coordinates_simple(self):
"""Check Weyl coordinates against known cases."""
# Identity [0,0,0]
U = np.identity(4)
U = np.identity(4, dtype=complex)
weyl = weyl_coordinates(U)
assert_allclose(weyl, [0, 0, 0])

Expand Down
2 changes: 1 addition & 1 deletion test/python/synthesis/xx_decompose/test_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import ddt
import numpy as np

from qiskit._accelerate.two_qubit_decompose import weyl_coordinates
from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import RZGate, UnitaryGate
import qiskit.quantum_info.operators
from qiskit.synthesis.two_qubit.weyl import weyl_coordinates
from qiskit.synthesis.two_qubit.xx_decompose.circuits import (
decompose_xxyy_into_xxyy_xx,
xx_circuit_step,
Expand Down

0 comments on commit 54fe09b

Please sign in to comment.