tket
tket copied to clipboard
FullPeepholeOptimise does not preserve Connectivity although allow_swaps=False
Hi,
I think I may found a case (using pytket v1.11.1) where the FullPeepholeOptimise
compilation pass did not preserve the connectivity although allow_swaps=False
is set.
Here is the code leading to valid_connectivity(...)
returning False
:
from pytket import architecture, OpType
from qiskit.providers.fake_provider import FakeMontreal
from pytket.passes import (
RoutingPass,
auto_rebase_pass,
PlacementPass,
FullPeepholeOptimise
)
from pytket.placement import LinePlacement
from pytket.qasm import circuit_from_qasm_str
cmap = FakeMontreal().configuration().coupling_map
arch = architecture.Architecture(cmap)
native_gate_set_rebase = auto_rebase_pass({OpType.Rz, OpType.SX, OpType.X, OpType.CX, OpType.Measure})
qc_tket = circuit_from_qasm_str('OPENQASM 2.0;\ninclude "qelib1.inc";\n\nqreg q[11];\ncreg meas[11];\ncx q[4],q[3];\ncx q[4],q[3];\ncx q[3],q[2];\ncx q[4],q[2];\ncx q[3],q[2];\ncx q[4],q[2];\ncx q[2],q[1];\ncx q[3],q[1];\ncx q[2],q[1];\ncx q[4],q[1];\ncx q[2],q[1];\ncx q[3],q[1];\ncx q[2],q[1];\ncx q[4],q[1];\ncx q[1],q[0];\ncx q[2],q[0];\ncx q[1],q[0];\ncx q[3],q[0];\ncx q[1],q[0];\ncx q[2],q[0];\ncx q[1],q[0];\ncx q[4],q[0];\ncx q[1],q[0];\ncx q[2],q[0];\ncx q[1],q[0];\ncx q[3],q[0];\ncx q[1],q[0];\ncx q[2],q[0];\ncx q[1],q[0];\ncx q[4],q[0];\nccx q[1],q[7],q[8];\nccx q[2],q[8],q[9];\nccx q[3],q[9],q[10];\nccx q[4],q[10],q[6];\nccx q[3],q[9],q[10];\ncx q[6],q[5];\nccx q[2],q[8],q[9];\ncx q[6],q[5];\nccx q[1],q[7],q[8];\ncx q[6],q[5];\ncx q[6],q[5];\nccx q[6],q[0],q[5];\ncx q[6],q[5];\ncx q[6],q[5];\nccx q[6],q[0],q[5];\ncx q[6],q[5];\ncx q[6],q[5];\nccx q[6],q[1],q[5];\ncx q[6],q[5];\ncx q[6],q[5];\nccx q[6],q[1],q[5];\nccx q[1],q[7],q[8];\ncx q[6],q[5];\ncx q[6],q[5];\nccx q[6],q[2],q[5];\ncx q[6],q[5];\ncx q[6],q[5];\nccx q[6],q[2],q[5];\nccx q[2],q[8],q[9];\ncx q[6],q[5];\ncx q[6],q[5];\nccx q[6],q[3],q[5];\ncx q[6],q[5];\ncx q[6],q[5];\nccx q[6],q[3],q[5];\nccx q[3],q[9],q[10];\ncx q[6],q[5];\ncx q[6],q[5];\nccx q[6],q[4],q[5];\ncx q[6],q[5];\ncx q[6],q[5];\nccx q[6],q[4],q[5];\nccx q[4],q[10],q[6];\nccx q[3],q[9],q[10];\nccx q[2],q[8],q[9];\nccx q[1],q[7],q[8];\n')
native_gate_set_rebase.apply(qc_tket)
placer = LinePlacement(arch)
PlacementPass(placer).apply(qc_tket)
RoutingPass(arch).apply(qc_tket)
native_gate_set_rebase.apply(qc_tket)
FullPeepholeOptimise(target_2qb_gate=OpType.TK2, allow_swaps=False).apply(qc_tket)
print(qc_tket.valid_connectivity(arch, directed=True))
In this case, three invalid operations were inserted:
for com in qc_tket:
if len(com.args)>1:
if not ((com.args[0], com.args[1]) in arch.coupling):
print(com.args[0], com.args[1])
node[1] node[3]
node[8] node[3]
node[19] node[14]
If the FullPeepholeOptimise
pass is not used, everything works as expected.