From bd2c2b64ef23f64d3cb07f599dabe6bce5081225 Mon Sep 17 00:00:00 2001 From: Ed Younis Date: Thu, 9 Nov 2023 10:59:37 -0500 Subject: [PATCH 1/2] Fixed barrier issue in pam --- bqskit/passes/mapping/pam.py | 8 ++++++++ bqskit/passes/mapping/sabre.py | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/bqskit/passes/mapping/pam.py b/bqskit/passes/mapping/pam.py index e2cda3802..549ab2b6b 100644 --- a/bqskit/passes/mapping/pam.py +++ b/bqskit/passes/mapping/pam.py @@ -13,6 +13,7 @@ import numpy as np from bqskit.ir.circuit import Circuit +from bqskit.ir.gates.barrier import BarrierPlaceholder from bqskit.ir.gates.constant.swap import SwapGate from bqskit.ir.point import CircuitPoint from bqskit.passes.mapping.sabre import GeneralizedSabreAlgorithm @@ -175,6 +176,13 @@ def forward_pass( # type: ignore E = self._calc_extended_set(circuit, F) for n in execute_list: op = circuit[n] + + if isinstance(op.gate, BarrierPlaceholder): + if modify_circuit: + physical_location = [pi[q] for q in op.location] + mapped_circuit.append_gate(op.gate, op.location) + continue + p1, circ, p2 = self._get_best_perm( circuit, perm_data[n], diff --git a/bqskit/passes/mapping/sabre.py b/bqskit/passes/mapping/sabre.py index 1f9ca67d1..b80227445 100644 --- a/bqskit/passes/mapping/sabre.py +++ b/bqskit/passes/mapping/sabre.py @@ -9,6 +9,7 @@ import numpy as np from bqskit.ir.circuit import Circuit +from bqskit.ir.gates.barrier import BarrierPlaceholder from bqskit.ir.gates.circuitgate import CircuitGate from bqskit.ir.gates.constant.swap import SwapGate from bqskit.ir.operation import Operation @@ -330,6 +331,9 @@ def backward_pass( def _can_exe(self, op: Operation, pi: list[int], cg: CouplingGraph) -> bool: """Return true if `op` is executable given the current mapping `pi`.""" + if isinstance(op.gate, BarrierPlaceholder): + return True + if isinstance(op.gate, CircuitGate): if all(g.num_qudits == 1 for g in op.gate._circuit.gate_set): return True From e96a69fd49fec458c9988c4de1914b82baeeab14 Mon Sep 17 00:00:00 2001 From: Ed Younis Date: Thu, 9 Nov 2023 11:00:18 -0500 Subject: [PATCH 2/2] Pre-commit --- bqskit/passes/mapping/sabre.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bqskit/passes/mapping/sabre.py b/bqskit/passes/mapping/sabre.py index b80227445..b257fda84 100644 --- a/bqskit/passes/mapping/sabre.py +++ b/bqskit/passes/mapping/sabre.py @@ -333,7 +333,7 @@ def _can_exe(self, op: Operation, pi: list[int], cg: CouplingGraph) -> bool: """Return true if `op` is executable given the current mapping `pi`.""" if isinstance(op.gate, BarrierPlaceholder): return True - + if isinstance(op.gate, CircuitGate): if all(g.num_qudits == 1 for g in op.gate._circuit.gate_set): return True