Skip to content

Commit

Permalink
Fix issue with BlueprintCircuit.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhartman committed Sep 25, 2023
1 parent 92e3d08 commit afecc5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
17 changes: 17 additions & 0 deletions crates/accelerate/src/quantum_circuit/intern_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ impl InternContext {
slot_lookup: HashMap::new(),
}
}

pub fn __str__(&self, py: Python<'_>) -> PyObject {
let mut str = String::new();
str.push_str("InternContext\n");
str.push_str(" slots:\n");
for (idx, s) in self.slots.iter().enumerate() {
if let Some(occupied) = s {
str.push_str(&*format!(
" Slot(idx={idx}, use_count={:?}, operands={:?})\n",
occupied.use_count, occupied.operands
));
}
}
str.push_str(" free_slots:\n");
str.push_str(&*format!(" {:?}", self.free_slots));
str.into_py(py)
}
}

impl Default for InternContext {
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/blueprintcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _build(self) -> None:

def _invalidate(self) -> None:
"""Invalidate the current circuit build."""
self._data = []
self._data = super()._new_data()
self._parameter_table = ParameterTable()
self.global_phase = 0
self._is_built = False
Expand Down
9 changes: 7 additions & 2 deletions qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,13 @@ def __init__(
"qiskit.circuit.controlflow.builder.ControlFlowBuilderBlock"
] = []

self.qregs: list[QuantumRegister] = []
self.cregs: list[ClassicalRegister] = []
# Skip initialization if a subclass (e.g. BlueprintCircuit) is overriding
# these via properties.
if not hasattr(type(self), "qregs"):
self.qregs: list[QuantumRegister] = []
if not hasattr(type(self), "cregs"):
self.cregs: list[ClassicalRegister] = []

self._qubits: list[Qubit] = []
self._clbits: list[Clbit] = []

Expand Down

0 comments on commit afecc5d

Please sign in to comment.