1

There is a simple circuit with one CNOT like the following:

  • Topology 0 → 1 (directed connection)
  • CNOT 1 → 0

Note that CNOT is placed opposite to the connection.

If this is transpiled correctly, it should look like the following circuit.

  1. HH
  2. CNOT 0 → 1
  3. HH

What is the proper Tket transpilation pass(es) required to perform this transpilation?

I wrote the following code but did not get the desired result.

from pytket import Circuit
from pytket.circuit import Node
from pytket.architecture import Architecture
from pytket.placement import place_with_map
from pytket.passes import RoutingPass

nodes = [Node("node" + str(i), i) for i in range(2)] arch = Architecture([(nodes[1], nodes[0])])

circuit = Circuit(2) circuit.CX(0, 1) # needs transpilation here

initial_mapping = {circuit.qubits[i]: nodes[i] for i in range(len(nodes))} place_with_map(circuit, initial_mapping)

transpile

RoutingPass(arch).apply(circuit)

FDGod
  • 2,901
  • 2
  • 6
  • 31
yasuhito
  • 91
  • 4

1 Answers1

2

DecomposeSwapsToCXs looks like it does the trick.

from pytket import Circuit
from pytket.circuit import Node
from pytket.architecture import Architecture
from pytket.placement import place_with_map
from pytket.passes import DecomposeSwapsToCXs
from pytket.circuit.display import render_circuit_jupyter

circuit = Circuit(2) circuit.CX(0, 1) # needs transpilation here print("Original circuit:") render_circuit_jupyter(circuit)

nodes = [Node("node" + str(i), i) for i in range(circuit.n_qubits)] arch = Architecture([(nodes[1], nodes[0])])

initial_mapping = {circuit.qubits[i]: nodes[i] for i in range(circuit.n_qubits)} place_with_map(circuit, initial_mapping)

DecomposeSwapsToCXs(arch, True).apply(circuit) print("\nTranspiled circuit after applying DecomposeSwapsToCXs:") render_circuit_jupyter(circuit)

FDGod
  • 2,901
  • 2
  • 6
  • 31
yasuhito
  • 91
  • 4