Skip to content

Commit

Permalink
Avoid extra bind in _legacy_format.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhartman committed Apr 3, 2024
1 parent ef16ba5 commit 1c6132d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions crates/accelerate/src/quantum_circuit/circuit_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl CircuitInstruction {
// the interface to behave exactly like the old 3-tuple `(inst, qargs, cargs)` if it's treated
// like that via unpacking or similar. That means that the `parameters` field is completely
// absent, and the qubits and clbits must be converted to lists.
pub fn _legacy_format(&self, py: Python<'_>) -> PyObject {
pub fn _legacy_format<'py>(&self, py: Python<'py>) -> Bound<'py, PyTuple> {
PyTuple::new_bound(
py,
[
Expand All @@ -185,15 +185,14 @@ impl CircuitInstruction {
&self.clbits.bind(py).to_list(),
],
)
.into_py(py)
}

pub fn __getitem__(&self, py: Python<'_>, key: &Bound<PyAny>) -> PyResult<PyObject> {
Ok(self._legacy_format(py).bind(py).get_item(key)?.into_py(py))
Ok(self._legacy_format(py).as_any().get_item(key)?.into_py(py))
}

pub fn __iter__(&self, py: Python<'_>) -> PyResult<PyObject> {
Ok(self._legacy_format(py).bind(py).iter()?.into_py(py))
Ok(self._legacy_format(py).as_any().iter()?.into_py(py))
}

pub fn __len__(&self) -> usize {
Expand Down Expand Up @@ -229,7 +228,7 @@ impl CircuitInstruction {
}

if other.is_instance_of::<PyTuple>() {
return Ok(Some(self_._legacy_format(py).bind(py).eq(other)?));
return Ok(Some(self_._legacy_format(py).eq(other)?));
}

Ok(None)
Expand Down

0 comments on commit 1c6132d

Please sign in to comment.