Download

Download this file as Jupyter notebook: topology.ipynb.

Example: Topological Compilation

This example demonstrates how the built-in compiler can be used to ensure that circuits obey the qudit connectivity of a system.

Connectivity Graphs

Connectivity graphs for our system can be declared through Graph. We can instantiate custom connectivity arrangements or use pre-configured systems.

[2]:
import trueq as tq
import trueq.compilation as tqc
import trueq.visualization as tqv

# create an instance of the Regetti Aspen-11 chip.
graph = tqv.Graph.aspen_11(show_labels=True)
graph.plot()
../../_images/guides_compilation_topology_2_0.png

Allocating Labels

We can begin by relabeling our circuit so that their labels match that of our connectivity graphs using AllocateLabels.

[3]:
circ = tq.Circuit(
    [
        {(0, 1): tq.Gate.cx},
        {(0, 2): tq.Gate.random(4)},
        {(0, 3): tq.Gate.cx},
        {(0, 4): tq.Gate.random(4)},
    ]
)

alloc = tqc.AllocateLabels(graph)
circ = tq.Compiler([alloc]).compile(circ)
circ.draw()
[3]:
10 11 25 26 27 Key: relabeling: ((0, 1, 2, 3, 4), (26, 11, 25, 27, 10)) Labels: (26, 11) Name: Gate.cx Aliases: Gate.cx Gate.cnot Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (26, 25) Name: Gate Locally Equivalent: Non-Clifford Generators: YX: -84.44 YI: 77.57 XZ: -65.09 IX: 47.11 XX: 43.89 IY: 37.02 YY: -36.00 ... -0.17 -0.38j 0.02 -0.47j -0.30 0.27j 0.57 -0.34j 0.44 0.16j 0.64 -0.08j 0.02 0.18j -0.24 -0.52j 0.43 0.44j -0.30 -0.39j 0.39 -0.26j 0.39 -0.07j -0.34 -0.34j 0.34 0.09j 0.59 -0.48j 0.15 -0.21j Labels: (26, 27) Name: Gate.cx Aliases: Gate.cx Gate.cnot Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (26, 10) Name: Gate Locally Equivalent: Non-Clifford Generators: YX: -108.61 IZ: 108.24 IX: 87.27 ZX: -73.30 ZI: 53.41 XZ: 47.09 ZZ: -39.20 ... 0.32 -0.65j 0.39 0.18j -0.43 -0.31j -0.06 -0.05j -0.11 -0.18j 0.40 0.01j 0.56 0.06j 0.24 -0.65j -0.47 0.10j -0.30 0.26j -0.37 -0.43j 0.43 -0.33j -0.38 -0.24j -0.10 0.69j 0.28 0.05j -0.44 0.17j

We see that labels 0, 1, 2, 3, 4 of our input circuit got respectively mapped to labels 26, 11, 25, 27, 10. AllocateLabels's remapping attempts to maximize the number of two-qudit gates that act on valid connections on the targeted graph. In the above example (26, 11), (26, 25), and (26, 27) are all connected on the graph. However, since no qudit in the Aspen-11 chip contains more than three connections, we cannot make this circuit obey the couplings through relabeling alone. Therefore the final CNOT gate of (26, 10) is not valid connection. To ensure that all gates obey the connectivity we need to also use DeferredSwapper.

Deferred Swapper

The DeferredSwapper is used to compile circuits so that every gate obeys the topology of our graph. After relabeling the circuit to match that of our graph, the Deferred Swapper will insert swaps in order to ensure that all two-qudit gates are only between labels that can be coupled by the system.

[4]:

swapper = tqc.DeferredSwapper(graph) circ = tq.Compiler([swapper]).compile(circ) circ.draw()
[4]:
10 11 25 26 27 Key: relabeling: ((0, 1, 2, 3, 4), (26, 11, 25, 27, 10)) Labels: (26, 11) Name: Gate.cx Aliases: Gate.cx Gate.cnot Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (26, 25) Name: Gate Locally Equivalent: Non-Clifford Generators: YX: -84.44 YI: 77.57 XZ: -65.09 IX: 47.11 XX: 43.89 IY: 37.02 YY: -36.00 ... -0.17 -0.38j 0.02 -0.47j -0.30 0.27j 0.57 -0.34j 0.44 0.16j 0.64 -0.08j 0.02 0.18j -0.24 -0.52j 0.43 0.44j -0.30 -0.39j 0.39 -0.26j 0.39 -0.07j -0.34 -0.34j 0.34 0.09j 0.59 -0.48j 0.15 -0.21j Labels: (26, 27) Name: Gate.cx Aliases: Gate.cx Gate.cnot Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (10, 11) Name: Gate.swap Aliases: Gate.swap Locally Equivalent: SWAP Generators: YY: 90.00 XX: 90.00 ZZ: 90.00 1.00 1.00 1.00 1.00 SW SW Labels: (26, 11) Name: Gate Locally Equivalent: Non-Clifford Generators: YX: -108.61 IZ: 108.24 IX: 87.27 ZX: -73.30 ZI: 53.41 XZ: 47.09 ZZ: -39.20 ... 0.32 -0.65j 0.39 0.18j -0.43 -0.31j -0.06 -0.05j -0.11 -0.18j 0.40 0.01j 0.56 0.06j 0.24 -0.65j -0.47 0.10j -0.30 0.26j -0.37 -0.43j 0.43 -0.33j -0.38 -0.24j -0.10 0.69j 0.28 0.05j -0.44 0.17j Labels: (11, 10) Name: Gate.swap Aliases: Gate.swap Locally Equivalent: SWAP Generators: YY: 90.00 XX: 90.00 ZZ: 90.00 1.00 1.00 1.00 1.00 SW SW

Here the Deferred Swapper inserted swaps before the final Cycle in order to make the two-qubit gate on (26, 10) valid. Additionally, this swapping algorithm will combine gates into swap sections where its optimal to do so. For example:

[5]:

circ = tq.Circuit([{(26, 10): tq.Gate.random(4)}, {(10, 26): tq.Gate.random(4)}]) circ = tq.Compiler([swapper]).compile(circ) circ.draw()
[5]:
10 11 26 Key: Labels: (10, 11) Name: Gate.swap Aliases: Gate.swap Locally Equivalent: SWAP Generators: YY: 90.00 XX: 90.00 ZZ: 90.00 1.00 1.00 1.00 1.00 SW SW Labels: (26, 11) Name: Gate Locally Equivalent: Non-Clifford Generators: IZ: 117.66 XI: -95.75 ZI: 65.12 YX: 62.67 XZ: 57.70 ZZ: -47.84 IY: 25.13 ... 0.45 -0.76j -0.03 0.00j 0.04 0.39j -0.14 -0.23j -0.06 0.18j 0.42 -0.20j -0.34 0.37j -0.67 0.22j 0.36 0.05j 0.53 -0.06j 0.60 -0.43j -0.22 -0.02j 0.17 0.17j -0.71 0.08j 0.16 -0.18j -0.62 -0.02j Labels: (11, 26) Name: Gate Locally Equivalent: Non-Clifford Generators: ZX: -88.28 ZZ: -73.33 XX: 65.36 YX: 65.04 YI: 58.92 IZ: -58.18 ZI: -50.82 ... -0.41 0.50j -0.48 0.07j -0.16 -0.09j 0.26 -0.50j -0.40 0.44j 0.28 -0.31j -0.40 -0.01j -0.42 0.36j 0.24 0.16j 0.34 -0.68j 0.24 -0.03j -0.02 -0.53j 0.39 -0.04j 0.11 -0.02j -0.63 -0.59j 0.29 -0.01j Labels: (11, 10) Name: Gate.swap Aliases: Gate.swap Locally Equivalent: SWAP Generators: YY: 90.00 XX: 90.00 ZZ: 90.00 1.00 1.00 1.00 1.00 SW SW

Here both of the two-qudit gates get placed in the same opening and closing pair of swap gates.

Clifford Decomposition

When the Deferred Swapper encounters a Clifford gate, it may perform a Clifford decomposition when it sees that it is optimal to do so.

[6]:
circ = tq.Circuit([{(26, 10): tq.Gate.cx}])
circ = tq.Compiler([swapper]).compile(circ)
circ.draw()
[6]:
10 11 26 Key: Labels: (11, 10) Name: Gate.cz Aliases: Gate.cz Locally Equivalent: CNOT Generators: ZZ: -90.00 ZI: 90.00 IZ: 90.00 1.00 1.00 1.00 -1.00 CZ CZ Labels: (10,) Name: Gate.h Aliases: Gate.h Gate.f Gate.cliff12 Generators: Z: 127.28 X: 127.28 0.71 0.71 0.71 -0.71 H Labels: (11,) Name: Gate.h Aliases: Gate.h Gate.f Gate.cliff12 Generators: Z: 127.28 X: 127.28 0.71 0.71 0.71 -0.71 H Labels: (11, 10) Name: Gate.cz Aliases: Gate.cz Locally Equivalent: CNOT Generators: ZZ: -90.00 ZI: 90.00 IZ: 90.00 1.00 1.00 1.00 -1.00 CZ CZ Labels: (11,) Name: Gate.h Aliases: Gate.h Gate.f Gate.cliff12 Generators: Z: 127.28 X: 127.28 0.71 0.71 0.71 -0.71 H Labels: (26, 11) Name: Gate.cz Aliases: Gate.cz Locally Equivalent: CNOT Generators: ZZ: -90.00 ZI: 90.00 IZ: 90.00 1.00 1.00 1.00 -1.00 CZ CZ Labels: (11,) Name: Gate.h Aliases: Gate.h Gate.f Gate.cliff12 Generators: Z: 127.28 X: 127.28 0.71 0.71 0.71 -0.71 H Labels: (11, 10) Name: Gate.cz Aliases: Gate.cz Locally Equivalent: CNOT Generators: ZZ: -90.00 ZI: 90.00 IZ: 90.00 1.00 1.00 1.00 -1.00 CZ CZ Labels: (10,) Name: Gate.h Aliases: Gate.h Gate.f Gate.cliff12 Generators: Z: 127.28 X: 127.28 0.71 0.71 0.71 -0.71 H Labels: (11,) Name: Gate.h Aliases: Gate.h Gate.f Gate.cliff12 Generators: Z: 127.28 X: 127.28 0.71 0.71 0.71 -0.71 H Labels: (11, 10) Name: Gate.cz Aliases: Gate.cz Locally Equivalent: CNOT Generators: ZZ: -90.00 ZI: 90.00 IZ: 90.00 1.00 1.00 1.00 -1.00 CZ CZ

Here, the Deferred Swapper determines that tq.Gate.cx is a Clifford gate and chooses to decompose it as such. The output is a series of one- and two-qubit Cliffords gates that obey our graph topology.

Additionally, this Clifford decomposition algorithm can be ran directly by using decompose_clifford.


Download

Download this file as Jupyter notebook: topology.ipynb.