Skip to content

Commit

Permalink
Refactor replace_bits.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhartman committed Nov 13, 2023
1 parent 11fb49b commit 19a2170
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions crates/accelerate/src/quantum_circuit/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,32 +376,16 @@ 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(
&mut temp.qubit_indices_native,
&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(
Expand Down

0 comments on commit 19a2170

Please sign in to comment.