From 198e8fcc290ef3b0ff095586d2d9941d8979e2e0 Mon Sep 17 00:00:00 2001 From: raunakkumarsingh Date: Thu, 18 Jul 2024 09:59:32 +0530 Subject: [PATCH] added test for barrier ignored --- test/utils/test_transforms.py | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/utils/test_transforms.py b/test/utils/test_transforms.py index 181a7b27f..d67ee54ce 100644 --- a/test/utils/test_transforms.py +++ b/test/utils/test_transforms.py @@ -261,7 +261,49 @@ def test_separate_circuit(self): self.assertEqual( [("A", 0), ("B", 0), ("C", 0)], separated_circuits.qubit_map ) + + with self.subTest("barriers are ignored"): + qreg = QuantumRegister(3) + circuit = QuantumCircuit(qreg) + circuit.h(0) + circuit.x(0) + circuit.barrier(0) + circuit.x(1) + circuit.h(1) + circuit.y(2) + circuit.h(2) + + separated_circuits = separate_circuit(circuit, partition_labels="ABC") + + compare1 = QuantumCircuit(1) + compare1.h(0) + compare1.x(0) + compare2 = QuantumCircuit(1) + compare2.x(0) + compare2.h(0) + compare3 = QuantumCircuit(1) + compare3.y(0) + compare3.h(0) + for i, operation in enumerate(compare1.data): + self.assertEqual( + operation.operation.name, + separated_circuits.subcircuits["A"].data[i].operation.name, + ) + for i, operation in enumerate(compare2.data): + self.assertEqual( + operation.operation.name, + separated_circuits.subcircuits["B"].data[i].operation.name, + ) + for i, operation in enumerate(compare3.data): + self.assertEqual( + operation.operation.name, + separated_circuits.subcircuits["C"].data[i].operation.name, + ) + self.assertEqual( + [("A", 0), ("B", 0), ("C", 0)], separated_circuits.qubit_map + ) + with self.subTest("Test bit mapping with partition labels"): # Prepare a HWEA and add some measurements to clbits in a random order circuit = prepare_hwea()