Skip to content

Commit

Permalink
Remove unused qiskit_accelerate::utils module (#13713)
Browse files Browse the repository at this point in the history
The utils module was added to have a place for some common utilities and
expose them to other rust modules or also to python. This was originally
added to expose faer's eigensolver as an alternative to numpy for
Python, but nothing ever used it and we didn't properly expose the
python submodule so it wasn't easily usable via qiskit._accelerate.
Since it's never used this opts to just remove it, if we have a future
need we can just add the function back. With the eigensolver removed the
only function that remained in the module was the arg_sort() function
which was only used by the two qubit decomposer. To simplify the code
base this is just made into a private function for that module and we
can remove the utils module altogether.
  • Loading branch information
mtreinish authored Jan 22, 2025
1 parent 7b0b6fc commit cce9e22
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 53 deletions.
1 change: 0 additions & 1 deletion crates/accelerate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ pub mod twirling;
pub mod two_qubit_decompose;
pub mod uc_gate;
pub mod unitary_synthesis;
pub mod utils;
pub mod vf2_layout;

mod rayon_ext;
Expand Down
14 changes: 11 additions & 3 deletions crates/accelerate/src/two_qubit_decompose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ use crate::euler_one_qubit_decomposer::{
angles_from_unitary, det_one_qubit, unitary_to_gate_sequence_inner, EulerBasis, EulerBasisSet,
OneQubitGateSequence, ANGLE_ZERO_EPSILON,
};
use crate::utils;
use crate::QiskitError;

use rand::prelude::*;
Expand Down Expand Up @@ -165,6 +164,15 @@ fn py_trace_to_fid(trace: Complex64) -> PyResult<f64> {
Ok(fid)
}

/// Return indices that sort partially ordered data.
/// If `data` contains two elements that are incomparable,
/// an error will be thrown.
fn arg_sort<T: PartialOrd>(data: &[T]) -> Vec<usize> {
let mut indices = (0..data.len()).collect::<Vec<_>>();
indices.sort_by(|&a, &b| data[a].partial_cmp(&data[b]).unwrap());
indices
}

fn decompose_two_qubit_product_gate(
special_unitary: ArrayView2<Complex64>,
) -> PyResult<(Array2<Complex64>, Array2<Complex64>, f64)> {
Expand Down Expand Up @@ -252,7 +260,7 @@ fn __weyl_coordinates(unitary: MatRef<c64>) -> [f64; 3] {
.map(|x| x.rem_euclid(PI2))
.map(|x| x.min(PI2 - x))
.collect();
let mut order = utils::arg_sort(&cstemp);
let mut order = arg_sort(&cstemp);
(order[0], order[1], order[2]) = (order[1], order[2], order[0]);
(cs[0], cs[1], cs[2]) = (cs[order[0]], cs[order[1]], cs[order[2]]);

Expand Down Expand Up @@ -663,7 +671,7 @@ impl TwoQubitWeylDecomposition {
.map(|x| x.rem_euclid(PI2))
.map(|x| x.min(PI2 - x))
.collect();
let mut order = utils::arg_sort(&cstemp);
let mut order = arg_sort(&cstemp);
(order[0], order[1], order[2]) = (order[1], order[2], order[0]);
(cs[0], cs[1], cs[2]) = (cs[order[0]], cs[order[1]], cs[order[2]]);
(d[0], d[1], d[2]) = (d[order[0]], d[order[1]], d[order[2]]);
Expand Down
48 changes: 0 additions & 48 deletions crates/accelerate/src/utils.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/pyext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ fn _accelerate(m: &Bound<PyModule>) -> PyResult<()> {
add_submodule(m, ::qiskit_accelerate::two_qubit_decompose::two_qubit_decompose, "two_qubit_decompose")?;
add_submodule(m, ::qiskit_accelerate::unitary_synthesis::unitary_synthesis, "unitary_synthesis")?;
add_submodule(m, ::qiskit_accelerate::uc_gate::uc_gate, "uc_gate")?;
add_submodule(m, ::qiskit_accelerate::utils::utils, "utils")?;
add_submodule(m, ::qiskit_accelerate::vf2_layout::vf2_layout, "vf2_layout")?;
add_submodule(m, ::qiskit_circuit::circuit, "circuit")?;
add_submodule(m, ::qiskit_circuit::converters::converters, "converters")?;
Expand Down

0 comments on commit cce9e22

Please sign in to comment.