Skip to content

Commit

Permalink
Switch return type to a proper array
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Jan 22, 2024
1 parent e144580 commit 17d0a26
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 4 deletions.
80 changes: 80 additions & 0 deletions crate/Cargo.lock

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

2 changes: 2 additions & 0 deletions crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ndarray = "0.15.6"
numpy = "0.20.0"
pyo3 = { version = "0.20.2", features = ["auto-initialize"] }

[dev-dependencies]
Expand Down
11 changes: 7 additions & 4 deletions crate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
use ndarray::Array2;
use numpy::PyArray2;
use pyo3::prelude::*;
use pyo3::types::PyDict;

pub fn execute_qasm(circuit: String, platform: String, nshots: u32) -> PyResult<Vec<u32>> {
pub fn execute_qasm(circuit: String, platform: String, nshots: u32) -> PyResult<Array2<i32>> {
Python::with_gil(|py| {
let kwargs = PyDict::new(py);
kwargs.set_item("circuit", circuit)?;
kwargs.set_item("platform", platform)?;
kwargs.set_item("nshots", nshots)?;

let qibolab = PyModule::import(py, "qibolab")?;
qibolab
let pyarray: &PyArray2<i32> = qibolab
.getattr("execute_qasm")?
.call((), Some(kwargs))?
.call_method0("samples")?
.call_method0("ravel")?
.extract()
.extract()?;

Ok(pyarray.to_owned_array())
})
}

0 comments on commit 17d0a26

Please sign in to comment.