Skip to content

Commit

Permalink
Add test for full_layout with ancillas
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish committed Sep 14, 2023
1 parent 2e1af45 commit 8546928
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/python/transpiler/test_transpile_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,37 @@ def test_full_layout_full_path(self):
res = tqc.layout.full_layout()
self.assertEqual(res, [2, 0, 1])

def test_full_layout_full_path_with_ancilla(self):
qc = QuantumCircuit(3)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
cmap = CouplingMap.from_line(10, bidirectional=False)
tqc = transpile(qc, coupling_map=cmap, initial_layout=[9, 4, 0], seed_transpiler=42)
# tqc:
# q_2 -> 0 ──X─────────────────────────────────────────────────
# │
# ancilla_0 -> 1 ──X───X─────────────────────────────────────────────
# │
# ancilla_1 -> 2 ──────X──X──────────────────────────────────────────
# │ ┌───┐ ┌───┐
# ancilla_2 -> 3 ─────────X─┤ H ├────────────────────────────■──┤ H ├
# ┌───┐ └───┘ ┌───┐ ┌───┐┌─┴─┐├───┤
# q_1 -> 4 ┤ H ├─────────────────────■──┤ H ├─X─┤ H ├┤ X ├┤ H ├
# └───┘ ┌───┐┌─┴─┐├───┤ │ └───┘└───┘└───┘
# ancilla_3 -> 5 ─────────────────X─┤ H ├┤ X ├┤ H ├─X────────────────
# │ └───┘└───┘└───┘
# ancilla_4 -> 6 ─────────────X───X──────────────────────────────────
# │
# ancilla_5 -> 7 ─────────X───X──────────────────────────────────────
# │
# ancilla_6 -> 8 ──────X──X──────────────────────────────────────────
# ┌───┐ │
# q_0 -> 9 ┤ H ├─X─────────────────────────────────────────────
# └───┘
res = tqc.layout.full_layout()
self.assertEqual(res, [4, 5, 3])

def test_permute_sparse_pauli_op(self):
psi = EfficientSU2(4, reps=4, entanglement="circular")
op = SparsePauliOp.from_list([("IIII", 1), ("IZZZ", 2), ("XXXI", 3)])
Expand Down

0 comments on commit 8546928

Please sign in to comment.