Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose internal rust interface to DenseLayout #12104

Merged
merged 4 commits into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions crates/accelerate/src/dense_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use ahash::RandomState;
use hashbrown::{HashMap, HashSet};
use indexmap::IndexSet;
use ndarray::prelude::*;
use numpy::IntoPyArray;
use numpy::PyReadonlyArray2;
use numpy::ToPyArray;
use rayon::prelude::*;

use pyo3::prelude::*;
Expand Down Expand Up @@ -108,10 +108,35 @@ pub fn best_subset(
use_error: bool,
symmetric_coupling_map: bool,
error_matrix: PyReadonlyArray2<f64>,
) -> PyResult<(PyObject, PyObject, PyObject)> {
) -> (PyObject, PyObject, PyObject) {
let coupling_adj_mat = coupling_adjacency.as_array();
let coupling_shape = coupling_adj_mat.shape();
let err = error_matrix.as_array();
let [rows, cols, best_map] = best_subset_inner(
num_qubits,
coupling_adj_mat,
num_meas,
num_cx,
use_error,
symmetric_coupling_map,
err,
);
(
rows.into_pyarray_bound(py).into(),
cols.into_pyarray_bound(py).into(),
best_map.into_pyarray_bound(py).into(),
)
}

pub fn best_subset_inner(
num_qubits: usize,
coupling_adj_mat: ArrayView2<f64>,
num_meas: usize,
num_cx: usize,
use_error: bool,
symmetric_coupling_map: bool,
err: ArrayView2<f64>,
) -> [Vec<usize>; 3] {
let coupling_shape = coupling_adj_mat.shape();
let avg_meas_err = err.diag().mean().unwrap();

let map_fn = |k| -> SubsetResult {
Expand Down Expand Up @@ -216,11 +241,7 @@ pub fn best_subset(
let rows: Vec<usize> = new_cmap.iter().map(|edge| edge[0]).collect();
let cols: Vec<usize> = new_cmap.iter().map(|edge| edge[1]).collect();

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

#[pymodule]
Expand Down
Loading