From 19a2170abc15dd1e0febaa5bc1cf957f61335756 Mon Sep 17 00:00:00 2001 From: Kevin Hartman Date: Mon, 13 Nov 2023 15:13:23 -0500 Subject: [PATCH] Refactor replace_bits. --- .../src/quantum_circuit/circuit_data.rs | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/crates/accelerate/src/quantum_circuit/circuit_data.rs b/crates/accelerate/src/quantum_circuit/circuit_data.rs index 1de1db523d26..cdca7fb938b1 100644 --- a/crates/accelerate/src/quantum_circuit/circuit_data.rs +++ b/crates/accelerate/src/quantum_circuit/circuit_data.rs @@ -376,21 +376,8 @@ impl CircuitData { qubits: Option<&PyAny>, clbits: Option<&PyAny>, ) -> PyResult<()> { - // TODO: refactor - let mut temp = CircuitData { - data: vec![], - intern_context: Default::default(), - qubits: PyList::empty(py).into_py(py), - clbits: PyList::empty(py).into_py(py), - qubits_native: vec![], - clbits_native: vec![], - qubit_indices_native: Default::default(), - clbit_indices_native: Default::default(), - }; - if let Some(qubits) = qubits { - for bit in qubits.iter()? { - temp.add_qubit(py, bit?)?; - } + let mut temp = CircuitData::new(py, qubits, clbits, None, 0)?; + if qubits.is_some() { std::mem::swap(&mut temp.qubits, &mut self.qubits); std::mem::swap(&mut temp.qubits_native, &mut self.qubits_native); std::mem::swap( @@ -398,10 +385,7 @@ impl CircuitData { &mut self.qubit_indices_native, ); } - if let Some(clbits) = clbits { - for bit in clbits.iter()? { - temp.add_clbit(py, bit?)?; - } + if clbits.is_some() { std::mem::swap(&mut temp.clbits, &mut self.clbits); std::mem::swap(&mut temp.clbits_native, &mut self.clbits_native); std::mem::swap(