Skip to content

Commit 54fe09b

Browse files
authored
Remove duplicated weyl_coordinates python function (Qiskit#13193)
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 Qiskit#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: Qiskit#8459
1 parent fbfe738 commit 54fe09b

File tree

4 files changed

+20
-100
lines changed

4 files changed

+20
-100
lines changed

crates/accelerate/src/two_qubit_decompose.rs

+17
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,22 @@ fn py_decompose_two_qubit_product_gate(
216216
))
217217
}
218218

219+
/// Computes the Weyl coordinates for a given two-qubit unitary matrix.
220+
///
221+
/// Args:
222+
/// U (np.ndarray): Input two-qubit unitary.
223+
///
224+
/// Returns:
225+
/// np.ndarray: Array of the 3 Weyl coordinates.
226+
#[pyfunction]
227+
fn weyl_coordinates(py: Python, unitary: PyReadonlyArray2<Complex64>) -> PyObject {
228+
let array = unitary.as_array();
229+
__weyl_coordinates(array.into_faer_complex())
230+
.to_vec()
231+
.into_pyarray_bound(py)
232+
.into()
233+
}
234+
219235
fn __weyl_coordinates(unitary: MatRef<c64>) -> [f64; 3] {
220236
let uscaled = scale(C1 / unitary.determinant().powf(0.25)) * unitary;
221237
let uup = transform_from_magic_basis(uscaled);
@@ -2353,6 +2369,7 @@ pub fn two_qubit_decompose(m: &Bound<PyModule>) -> PyResult<()> {
23532369
m.add_wrapped(wrap_pyfunction!(local_equivalence))?;
23542370
m.add_wrapped(wrap_pyfunction!(py_trace_to_fid))?;
23552371
m.add_wrapped(wrap_pyfunction!(py_ud))?;
2372+
m.add_wrapped(wrap_pyfunction!(weyl_coordinates))?;
23562373
m.add_class::<TwoQubitGateSequence>()?;
23572374
m.add_class::<TwoQubitWeylDecomposition>()?;
23582375
m.add_class::<Specialization>()?;

qiskit/synthesis/two_qubit/weyl.py

-97
This file was deleted.

test/python/synthesis/test_weyl.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import numpy as np
1818
from numpy.testing import assert_allclose
1919

20+
from qiskit._accelerate.two_qubit_decompose import weyl_coordinates
2021
from qiskit.quantum_info.random import random_unitary
21-
from qiskit.synthesis.two_qubit.weyl import weyl_coordinates
2222
from qiskit.synthesis.two_qubit.local_invariance import (
2323
two_qubit_local_invariants,
2424
local_equivalence,
@@ -32,7 +32,7 @@ class TestWeyl(QiskitTestCase):
3232
def test_weyl_coordinates_simple(self):
3333
"""Check Weyl coordinates against known cases."""
3434
# Identity [0,0,0]
35-
U = np.identity(4)
35+
U = np.identity(4, dtype=complex)
3636
weyl = weyl_coordinates(U)
3737
assert_allclose(weyl, [0, 0, 0])
3838

test/python/synthesis/xx_decompose/test_circuits.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import ddt
2121
import numpy as np
2222

23+
from qiskit._accelerate.two_qubit_decompose import weyl_coordinates
2324
from qiskit.circuit import QuantumCircuit
2425
from qiskit.circuit.library import RZGate, UnitaryGate
2526
import qiskit.quantum_info.operators
26-
from qiskit.synthesis.two_qubit.weyl import weyl_coordinates
2727
from qiskit.synthesis.two_qubit.xx_decompose.circuits import (
2828
decompose_xxyy_into_xxyy_xx,
2929
xx_circuit_step,

0 commit comments

Comments
 (0)