From bb27b704b70594b498aa8991c363e8cbe585007a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Thu, 5 Sep 2024 11:32:29 +0200 Subject: [PATCH] Add qubits and clbits to dag in DAGCircuit::with_capacity --- crates/circuit/src/dag_circuit.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/circuit/src/dag_circuit.rs b/crates/circuit/src/dag_circuit.rs index fdaa81e3b4ca..228907b1398e 100644 --- a/crates/circuit/src/dag_circuit.rs +++ b/crates/circuit/src/dag_circuit.rs @@ -6195,7 +6195,7 @@ impl DAGCircuit { num_vars * 2 + // One input + output node per variable num_ops; - Ok(Self { + let mut new_dag = Self { name: None, metadata: Some(PyDict::new_bound(py).unbind().into()), calibrations: HashMap::default(), @@ -6223,7 +6223,24 @@ impl DAGCircuit { PySet::empty_bound(py)?.unbind(), PySet::empty_bound(py)?.unbind(), ], - }) + }; + + if num_qubits > 0 { + let qubit_cls = imports::QUBIT.get_bound(py); + for _i in 0..num_qubits { + let bit = qubit_cls.call0()?; + new_dag.add_qubit_unchecked(py, &bit)?; + } + } + + if num_clbits > 0 { + let clbit_cls = imports::CLBIT.get_bound(py); + for _i in 0..num_clbits { + let bit = clbit_cls.call0()?; + new_dag.add_clbit_unchecked(py, &bit)?; + } + } + Ok(new_dag) } /// Get qargs from an intern index