Skip to content

Commit

Permalink
Merge branch 'Qiskit:main' into move-target
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss authored Apr 4, 2024
2 parents 1d50653 + 59bdff9 commit 7135d72
Show file tree
Hide file tree
Showing 57 changed files with 416 additions and 422 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ indexmap.version = "2.2.6"
hashbrown.version = "0.14.0"
# This doesn't set `extension-module` as a shared feature because we need to be able to disable it
# during Rust-only testing (see # https://github.com/PyO3/pyo3/issues/340).
pyo3 = { version = "0.20.3", features = ["abi3-py38"] }
pyo3 = { version = "0.21.0", features = ["abi3-py38"] }

[profile.release]
lto = 'fat'
Expand Down
2 changes: 1 addition & 1 deletion crates/accelerate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension-module = ["pyo3/extension-module"]

[dependencies]
rayon = "1.10"
numpy = "0.20.0"
numpy = "0.21.0"
rand = "0.8"
rand_pcg = "0.3"
rand_distr = "0.4.3"
Expand Down
4 changes: 2 additions & 2 deletions crates/accelerate/src/convert_2q_block_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn blocks_to_matrix(
None => op_matrix.dot(&matrix),
};
}
Ok(matrix.into_pyarray(py).to_owned())
Ok(matrix.into_pyarray_bound(py).unbind())
}

/// Switches the order of qubits in a two qubit operation.
Expand All @@ -75,7 +75,7 @@ pub fn change_basis(matrix: ArrayView2<Complex64>) -> Array2<Complex64> {
}

#[pymodule]
pub fn convert_2q_block_matrix(_py: Python, m: &PyModule) -> PyResult<()> {
pub fn convert_2q_block_matrix(m: &Bound<PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(blocks_to_matrix))?;
Ok(())
}
8 changes: 4 additions & 4 deletions crates/accelerate/src/dense_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ pub fn best_subset(
let cols: Vec<usize> = new_cmap.iter().map(|edge| edge[1]).collect();

Ok((
rows.to_pyarray(py).into(),
cols.to_pyarray(py).into(),
best_map.to_pyarray(py).into(),
rows.to_pyarray_bound(py).into(),
cols.to_pyarray_bound(py).into(),
best_map.to_pyarray_bound(py).into(),
))
}

#[pymodule]
pub fn dense_layout(_py: Python, m: &PyModule) -> PyResult<()> {
pub fn dense_layout(m: &Bound<PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(best_subset))?;
Ok(())
}
2 changes: 1 addition & 1 deletion crates/accelerate/src/edge_collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl EdgeCollection {
/// output array here would be ``[0, 1, 1, 2, 2, 3]``.
#[pyo3(text_signature = "(self, /)")]
pub fn edges(&self, py: Python) -> PyObject {
self.edges.clone().into_pyarray(py).into()
self.edges.clone().into_pyarray_bound(py).into()
}

fn __getstate__(&self) -> Vec<PhysicalQubit> {
Expand Down
2 changes: 1 addition & 1 deletion crates/accelerate/src/error_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl ErrorMap {
}

#[pymodule]
pub fn error_map(_py: Python, m: &PyModule) -> PyResult<()> {
pub fn error_map(m: &Bound<PyModule>) -> PyResult<()> {
m.add_class::<ErrorMap>()?;
Ok(())
}
14 changes: 10 additions & 4 deletions crates/accelerate/src/euler_one_qubit_decomposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use num_complex::{Complex64, ComplexFloat};
use smallvec::{smallvec, SmallVec};
use std::cmp::Ordering;
use std::f64::consts::PI;
use std::ops::Deref;

use pyo3::exceptions::{PyIndexError, PyValueError};
use pyo3::prelude::*;
Expand All @@ -27,6 +28,7 @@ use pyo3::Python;

use ndarray::prelude::*;
use numpy::PyReadonlyArray2;
use pyo3::pybacked::PyBackedStr;

use crate::utils::SliceOrInt;

Expand Down Expand Up @@ -594,7 +596,11 @@ impl EulerBasis {
#[pymethods]
impl EulerBasis {
fn __reduce__(&self, py: Python) -> Py<PyAny> {
(py.get_type::<Self>(), (PyString::new(py, self.as_str()),)).into_py(py)
(
py.get_type_bound::<Self>(),
(PyString::new_bound(py, self.as_str()),),
)
.into_py(py)
}

#[new]
Expand Down Expand Up @@ -700,15 +706,15 @@ pub fn compute_error_list(
#[pyo3(signature = (unitary, target_basis_list, qubit, error_map=None, simplify=true, atol=None))]
pub fn unitary_to_gate_sequence(
unitary: PyReadonlyArray2<Complex64>,
target_basis_list: Vec<&str>,
target_basis_list: Vec<PyBackedStr>,
qubit: usize,
error_map: Option<&OneQubitGateErrorMap>,
simplify: bool,
atol: Option<f64>,
) -> PyResult<Option<OneQubitGateSequence>> {
let mut target_basis_vec: Vec<EulerBasis> = Vec::with_capacity(target_basis_list.len());
for basis in target_basis_list {
let basis_enum = EulerBasis::from_str(basis)?;
let basis_enum = EulerBasis::from_str(basis.deref())?;
target_basis_vec.push(basis_enum)
}
let unitary_mat = unitary.as_array();
Expand Down Expand Up @@ -873,7 +879,7 @@ pub fn params_zxz(unitary: PyReadonlyArray2<Complex64>) -> [f64; 4] {
}

#[pymodule]
pub fn euler_one_qubit_decomposer(_py: Python, m: &PyModule) -> PyResult<()> {
pub fn euler_one_qubit_decomposer(m: &Bound<PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(params_zyz))?;
m.add_wrapped(wrap_pyfunction!(params_xyx))?;
m.add_wrapped(wrap_pyfunction!(params_xzx))?;
Expand Down
3 changes: 1 addition & 2 deletions crates/accelerate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::env;

use pyo3::prelude::*;
use pyo3::wrap_pymodule;
use pyo3::Python;

mod convert_2q_block_matrix;
mod dense_layout;
Expand Down Expand Up @@ -50,7 +49,7 @@ pub fn getenv_use_multiple_threads() -> bool {
}

#[pymodule]
fn _accelerate(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
fn _accelerate(m: &Bound<PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pymodule!(nlayout::nlayout))?;
m.add_wrapped(wrap_pymodule!(stochastic_swap::stochastic_swap))?;
m.add_wrapped(wrap_pymodule!(sabre_swap::sabre_swap))?;
Expand Down
8 changes: 4 additions & 4 deletions crates/accelerate/src/nlayout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ macro_rules! qubit_newtype {
unsafe impl numpy::Element for $id {
const IS_COPY: bool = true;

fn get_dtype(py: Python<'_>) -> &numpy::PyArrayDescr {
u32::get_dtype(py)
fn get_dtype_bound(py: Python<'_>) -> Bound<'_, numpy::PyArrayDescr> {
u32::get_dtype_bound(py)
}
}
};
Expand Down Expand Up @@ -139,7 +139,7 @@ impl NLayout {
///
#[pyo3(text_signature = "(self, /)")]
fn layout_mapping(&self, py: Python<'_>) -> Py<PyList> {
PyList::new(py, self.iter_virtual()).into()
PyList::new_bound(py, self.iter_virtual()).into()
}

/// Get physical bit from virtual bit
Expand Down Expand Up @@ -217,7 +217,7 @@ impl NLayout {
}

#[pymodule]
pub fn nlayout(_py: Python, m: &PyModule) -> PyResult<()> {
pub fn nlayout(m: &Bound<PyModule>) -> PyResult<()> {
m.add_class::<NLayout>()?;
Ok(())
}
3 changes: 1 addition & 2 deletions crates/accelerate/src/optimize_1q_gates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use pyo3::prelude::*;
use pyo3::wrap_pyfunction;
use pyo3::Python;

const PI: f64 = std::f64::consts::PI;

Expand Down Expand Up @@ -92,7 +91,7 @@ pub fn compose_u3_rust(
}

#[pymodule]
pub fn optimize_1q_gates(_py: Python, m: &PyModule) -> PyResult<()> {
pub fn optimize_1q_gates(m: &Bound<PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(compose_u3_rust))?;
Ok(())
}
2 changes: 1 addition & 1 deletion crates/accelerate/src/pauli_exp_val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn density_expval_pauli_with_x(
}

#[pymodule]
pub fn pauli_expval(_py: Python, m: &PyModule) -> PyResult<()> {
pub fn pauli_expval(m: &Bound<PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(expval_pauli_no_x))?;
m.add_wrapped(wrap_pyfunction!(expval_pauli_with_x))?;
m.add_wrapped(wrap_pyfunction!(density_expval_pauli_with_x))?;
Expand Down
Loading

0 comments on commit 7135d72

Please sign in to comment.