Skip to content

Commit

Permalink
transforms.py: Avoid setting the barrier to be a uuid object (#625)
Browse files Browse the repository at this point in the history
* transforms.py: Convert the barrier uuid label into a string

More info at Qiskit/qiskit#12581

* Fix `isinstance(label, UUID)` check
  • Loading branch information
garrison authored Jun 15, 2024
1 parent d6a8654 commit 654f02f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions circuit_knitting/utils/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"""
from __future__ import annotations

from uuid import uuid4, UUID
from uuid import uuid4
from collections import defaultdict
from collections.abc import Sequence, Iterable, Hashable, MutableMapping
from typing import NamedTuple, Callable
Expand Down Expand Up @@ -276,7 +276,7 @@ def _split_barriers(circuit: QuantumCircuit):
num_qubits = len(inst.qubits)
if num_qubits == 1 or inst.operation.name != "barrier":
continue
barrier_uuid = uuid4()
barrier_uuid = f"_uuid={uuid4()}"

# Replace the N-qubit barrier with a single-qubit barrier
circuit.data[i] = CircuitInstruction(
Expand All @@ -298,13 +298,13 @@ def _combine_barriers(circuit: QuantumCircuit):
uuid_map = defaultdict(list)
for i, inst in enumerate(circuit):
if (
inst.operation.name != "barrier"
or len(inst.qubits) != 1
or not isinstance(inst.operation.label, UUID)
inst.operation.name == "barrier"
and len(inst.qubits) == 1
and inst.operation.label is not None
and inst.operation.label.startswith("_uuid=")
):
continue
barrier_uuid = inst.operation.label
uuid_map[barrier_uuid].append(i)
barrier_uuid = inst.operation.label
uuid_map[barrier_uuid].append(i)

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

0 comments on commit 654f02f

Please sign in to comment.