Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transforms.py: Avoid setting the barrier to be a uuid object (backport #625) #627

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -237,7 +237,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 @@ -259,13 +259,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