Skip to content

Commit 73fb2b1

Browse files
cosenalCopilot
andauthored
Treat graph edges symmetrically in mirror circuit benchmark (#671)
* Treat graph edges symmetrically in mirror circuits * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent fde1245 commit 73fb2b1

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

metriq_gym/benchmarks/mirror_circuits.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,18 @@ def random_cliffords(
315315
qc = QuantumCircuit(num_qubits)
316316

317317
two_qubit_gate = CXGate() if gate_type == TwoQubitGateType.CNOT else CZGate()
318-
for edge in connectivity_graph.edge_list():
319-
qc.append(two_qubit_gate, [edge[0], edge[1]])
318+
319+
for u, v in connectivity_graph.edge_list():
320+
if random_state.choice([True, False]):
321+
control, target = u, v
322+
else:
323+
control, target = v, u
324+
qc.append(two_qubit_gate, [control, target])
320325

321326
nodes_with_edges = set()
322-
for edge in connectivity_graph.edge_list():
323-
nodes_with_edges.add(edge[0])
324-
nodes_with_edges.add(edge[1])
327+
for u, v in connectivity_graph.edge_list():
328+
nodes_with_edges.add(u)
329+
nodes_with_edges.add(v)
325330

326331
isolated_qubits = [
327332
node for node in connectivity_graph.node_indices() if node not in nodes_with_edges
@@ -348,7 +353,9 @@ def pauli_from_layer(pauli_layer: QuantumCircuit) -> Pauli:
348353
n = pauli_layer.num_qubits
349354
per_qubit = ["I"] * n # default all identity
350355

351-
for instr, qargs, _ in pauli_layer.data:
356+
for instruction in pauli_layer.data:
357+
instr = instruction.operation
358+
qargs = instruction.qubits
352359
name = instr.name.lower()
353360
if name in ("barrier", "delay", "measure"):
354361
continue # middle layer shouldn't have these, but be permissive

0 commit comments

Comments
 (0)