diff --git a/crates/accelerate/src/euler_one_qubit_decomposer.rs b/crates/accelerate/src/euler_one_qubit_decomposer.rs index 8fe0eaf87b4..e74f7000669 100644 --- a/crates/accelerate/src/euler_one_qubit_decomposer.rs +++ b/crates/accelerate/src/euler_one_qubit_decomposer.rs @@ -19,20 +19,15 @@ use std::f64::consts::PI; use pyo3::exceptions::{PyIndexError, PyTypeError}; use pyo3::prelude::*; -use pyo3::types::PySlice; use pyo3::wrap_pyfunction; use pyo3::Python; use ndarray::prelude::*; use numpy::PyReadonlyArray2; -const DEFAULT_ATOL: f64 = 1e-12; +use crate::utils::SliceOrInt; -#[derive(FromPyObject)] -enum SliceOrInt<'a> { - Slice(&'a PySlice), - Int(isize), -} +const DEFAULT_ATOL: f64 = 1e-12; #[pyclass(module = "qiskit._accelerate.euler_one_qubit_decomposer")] pub struct OneQubitGateErrorMap { diff --git a/crates/accelerate/src/quantum_circuit/circuit_data.rs b/crates/accelerate/src/quantum_circuit/circuit_data.rs index cbafeb79f38..915285f6ad6 100644 --- a/crates/accelerate/src/quantum_circuit/circuit_data.rs +++ b/crates/accelerate/src/quantum_circuit/circuit_data.rs @@ -13,6 +13,7 @@ use crate::quantum_circuit::circuit_instruction::CircuitInstruction; use crate::quantum_circuit::intern_context::{BitType, IndexType, InternContext}; use crate::quantum_circuit::py_ext; +use crate::utils::SliceOrInt; use hashbrown::HashMap; use pyo3::exceptions::{PyIndexError, PyKeyError, PyRuntimeError, PyValueError}; use pyo3::prelude::*; @@ -153,16 +154,6 @@ pub struct CircuitData { clbits: Py, } -/// A private enumeration type used to extract arguments to pymethods -/// that may be either an index or a slice. -#[derive(FromPyObject)] -pub enum SliceOrInt<'a> { - // The order here defines the order the variants are tried in the `FromPyObject` derivation. - // `Int` is _much_ more common, so that should be first. - Int(isize), - Slice(&'a PySlice), -} - #[pymethods] impl CircuitData { #[new] diff --git a/crates/accelerate/src/utils.rs b/crates/accelerate/src/utils.rs index 99e338c7024..bc8a66568f9 100644 --- a/crates/accelerate/src/utils.rs +++ b/crates/accelerate/src/utils.rs @@ -11,12 +11,23 @@ // that they have been altered from the originals. use pyo3::prelude::*; +use pyo3::types::PySlice; use faer::prelude::*; use faer::IntoFaerComplex; use num_complex::Complex; use numpy::{IntoPyArray, PyReadonlyArray2}; +/// A private enumeration type used to extract arguments to pymethod +/// that may be either an index or a slice +#[derive(FromPyObject)] +pub enum SliceOrInt<'a> { + // The order here defines the order the variants are tried in the FromPyObject` derivation. + // `Int` is _much_ more common, so that should be first. + Int(isize), + Slice(&'a PySlice), +} + /// Return indices that sort partially ordered data. /// If `data` contains two elements that are incomparable, /// an error will be thrown.