Skip to content
Merged
Show file tree
Hide file tree
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: 16 additions & 21 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ license = "Apache-2.0"
bytemuck = "1.24"
bitfield-struct = "0.12.1"
indexmap.version = "2.10.0"
hashbrown.version = "0.15.2"
hashbrown.version = "0.15.5"
num-bigint = "0.4"
num-complex = "0.4"
nalgebra = "0.33"
numpy = "0.26"
numpy = "0.27"
ndarray = "0.16"
smallvec = "1.15"
thiserror = "2.0"
Expand All @@ -44,7 +44,7 @@ uuid = { version = "1.18", features = ["v4", "fast-rng"], default-features = fal
# distributions). We only activate that feature when building the C extension module; we still need
# it disabled for Rust-only tests to avoid linker errors with it not being loaded. See
# https://pyo3.rs/main/features#extension-module for more.
pyo3 = { version = "0.26", features = ["abi3-py39"] }
pyo3 = { version = "0.27", features = ["abi3-py39"] }

# These are our own crates.
qiskit-accelerate = { path = "crates/accelerate" }
Expand Down
36 changes: 23 additions & 13 deletions crates/circuit/src/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,28 @@ where
self.index as usize,
self.registers
.into_pyobject(py)?
.downcast_into::<PyList>()?
.cast_into::<PyList>()?
.unbind(),
)
.into_pyobject(py)
}
}

impl<'py, R> FromPyObject<'py> for BitLocations<R>
impl<'a, 'py, R> FromPyObject<'a, 'py> for BitLocations<R>
where
R: Debug + Clone + Register + for<'a> IntoPyObject<'a> + for<'a> FromPyObject<'a>,
R: Debug
+ Clone
+ Register
+ IntoPyObject<'py>
+ for<'b> FromPyObject<'b, 'py, Error: Into<PyErr>>,
{
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
let ob_down = ob.downcast::<PyBitLocations>()?.borrow();
type Error = PyErr;

fn extract(ob: Borrowed<'a, 'py, PyAny>) -> Result<Self, PyErr> {
let ob_down = ob.cast::<PyBitLocations>()?.borrow();
Ok(Self {
index: ob_down.index as u32,
registers: ob_down.registers.extract(ob.py())?,
registers: ob_down.registers.bind(ob.py()).extract()?,
})
}
}
Expand Down Expand Up @@ -509,9 +515,11 @@ macro_rules! create_bit_object {
}
}

impl<'py> FromPyObject<'py> for $bit_struct {
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
Ok(ob.downcast::<$pybit_struct>()?.borrow().0.clone())
impl<'a, 'py> FromPyObject<'a, 'py> for $bit_struct {
type Error = ::pyo3::CastError<'a, 'py>;

fn extract(ob: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error> {
ob.cast::<$pybit_struct>().map(|ob| ob.borrow().0.clone())
}
}
// The owning impl of `IntoPyObject` needs to be done manually, to better handle
Expand Down Expand Up @@ -629,9 +637,11 @@ macro_rules! create_bit_object {
}
}

impl<'py> FromPyObject<'py> for $reg_struct {
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
Ok(ob.downcast::<$pyreg_struct>()?.borrow().0.clone())
impl<'a, 'py> FromPyObject<'a, 'py> for $reg_struct {
type Error = ::pyo3::CastError<'a, 'py>;

fn extract(ob: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error> {
ob.cast::<$pyreg_struct>().map(|ob| ob.borrow().0.clone())
}
}
// The owning impl of `IntoPyObject` needs to be done manually, to better handle
Expand Down Expand Up @@ -761,7 +771,7 @@ macro_rules! create_bit_object {
Ok(PyList::new(ob.py(), s.into_iter().map(get_inner))?.into_any())
}
}
} else if let Ok(list) = ob.downcast::<PyList>() {
} else if let Ok(list) = ob.cast::<PyList>() {
let out = PyList::empty(ob.py());
for item in list.iter() {
out.append(get_inner(PySequenceIndex::convert_idx(
Expand Down
14 changes: 11 additions & 3 deletions crates/circuit/src/bit_locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@ where

impl<B, R> BitLocator<B, R>
where
B: Debug + Clone + Hash + Eq + for<'py> IntoPyObject<'py> + for<'py> FromPyObject<'py>,
R: Register + Debug + Clone + for<'py> IntoPyObject<'py> + for<'py> FromPyObject<'py>,
B: Debug
+ Clone
+ Hash
+ Eq
+ for<'py> IntoPyObject<'py>
+ for<'a, 'py> FromPyObject<'a, 'py, Error: Into<PyErr>>,
R: Register + Debug + Clone + for<'py> IntoPyObject<'py> + for<'a, 'py> FromPyObject<'a, 'py>,
{
/// Get or create the cached Python dictionary that represents this.
pub fn cached(&self, py: Python) -> &Py<PyDict> {
Expand All @@ -121,7 +126,10 @@ where
pub fn from_py_dict(dict: &Bound<PyDict>) -> PyResult<Self> {
let mut locator = Self::new();
for (key, value) in dict {
locator.insert(key.extract()?, value.extract()?);
locator.insert(
key.extract().map_err(Into::<PyErr>::into)?,
value.extract()?,
);
}
Ok(locator)
}
Expand Down
Loading