Skip to content

Commit

Permalink
Make add_clbits() signature the same as add_qubits()
Browse files Browse the repository at this point in the history
At some point during the development of this PR the function signatures
between `add_qubits()` and `add_clbits()` diverged between taking a
`Vec<Bound<PyAny>>` and `&Bound<PySequence>`. In general they're are
comprable but since we are going to be working with a `Vec<>` in the
function body this is a better choice to let PyO3 worry about the
conversion for us. Additionally, this is a more natural signature for
rust consumption. This commit just updates `add_clbits()` to use a Vec
too.
  • Loading branch information
mtreinish committed Aug 22, 2024
1 parent 32f5762 commit 415e9b7
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions crates/circuit/src/dag_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,8 @@ def _format(operand):
}

/// Add individual qubit wires.
fn add_clbits(&mut self, py: Python, clbits: &Bound<PySequence>) -> PyResult<()> {
let bits: Vec<Bound<PyAny>> = clbits.extract()?;
for bit in bits.iter() {
fn add_clbits(&mut self, py: Python, clbits: Vec<Bound<PyAny>>) -> PyResult<()> {
for bit in clbits.iter() {
if !bit.is_instance(imports::CLBIT.get_bound(py))? {
return Err(DAGCircuitError::new_err("not a Clbit instance."));
}
Expand All @@ -979,7 +978,7 @@ def _format(operand):
}
}

for bit in bits.iter() {
for bit in clbits.iter() {
self.add_clbit_unchecked(py, bit)?;
}
Ok(())
Expand Down

0 comments on commit 415e9b7

Please sign in to comment.