Skip to content

Commit bd6d5b9

Browse files
garrisonmergify[bot]
authored andcommitted
transforms.py: Avoid setting the barrier to be a uuid object (#625)
* transforms.py: Convert the barrier uuid label into a string More info at Qiskit/qiskit#12581 * Fix `isinstance(label, UUID)` check (cherry picked from commit 654f02f)
1 parent 7c60206 commit bd6d5b9

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

circuit_knitting/utils/transforms.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"""
2828
from __future__ import annotations
2929

30-
from uuid import uuid4, UUID
30+
from uuid import uuid4
3131
from collections import defaultdict
3232
from collections.abc import Sequence, Iterable, Hashable, MutableMapping
3333
from typing import NamedTuple, Callable
@@ -237,7 +237,7 @@ def _split_barriers(circuit: QuantumCircuit):
237237
num_qubits = len(inst.qubits)
238238
if num_qubits == 1 or inst.operation.name != "barrier":
239239
continue
240-
barrier_uuid = uuid4()
240+
barrier_uuid = f"_uuid={uuid4()}"
241241

242242
# Replace the N-qubit barrier with a single-qubit barrier
243243
circuit.data[i] = CircuitInstruction(
@@ -259,13 +259,13 @@ def _combine_barriers(circuit: QuantumCircuit):
259259
uuid_map = defaultdict(list)
260260
for i, inst in enumerate(circuit):
261261
if (
262-
inst.operation.name != "barrier"
263-
or len(inst.qubits) != 1
264-
or not isinstance(inst.operation.label, UUID)
262+
inst.operation.name == "barrier"
263+
and len(inst.qubits) == 1
264+
and inst.operation.label is not None
265+
and inst.operation.label.startswith("_uuid=")
265266
):
266-
continue
267-
barrier_uuid = inst.operation.label
268-
uuid_map[barrier_uuid].append(i)
267+
barrier_uuid = inst.operation.label
268+
uuid_map[barrier_uuid].append(i)
269269

270270
# Replace the first single-qubit barrier in each group with the full-sized barrier
271271
cleanup_inst = []

0 commit comments

Comments
 (0)