Customizing Randomized Compiling with different Compilation Options

Randomized Compiling in True-Q™ can be configured in various ways. For example, the Customizing Randomized Compiling with Cycle Markers example shows how the user can specify which cycles in a circuit are hard cycles and thus subject to the random twirls that the randomly_compile() inserts around those hard cycles. Two other important configuration options include:

  1. Randomized Compiling for non-Clifford entangling gates

    Randomized Compiling can be used for circuits that contain hard cycles with gates which are not from the Clifford group by specifying the entangler argument.

  2. Specifying the action on idle qubits

    In systems with large single-qubit errors it might be desirable to not introduce any additional single-qubit gates on what would otherwise be idle qubits. This compilation option can be specified through the Compiler passes: RCCycle and RCLocal.

The following examples show how these configuration options work in practice.

Note

Randomized Compiling produces a new circuit collection after each call, so the output of this example will be different if it’s executed again.

Randomized Compiling for non-Clifford Entangling Gates

The trueq.randomly_compile() function by default assumes that all hard cycles in the input circuit consist purely of Clifford gates. This is because under the standard Pauli twirl, the correction gates for the twirl gate can always be expressed as single-qubit gates which can be compiled into neighboring easy cycles such that the overall circuit depth is maintained [11].

It is possible to twirl a cycle that has non-Clifford gates in two ways. One solution is to customize the set of twirling gates. The other approach, as shown here, is to use True-Q™'s built-in Compiler to convert the cycle into a Clifford-based representation. This can be done either implicitly by specifying the entangler argument of the trueq.randomly_compile() function, or explicitly through defining a custom Compiler. Let’s take a look at both options.

As a concrete example, consider the Quantum Fourier Transform (QFT) circuit, that is commonly expressed in terms of the \(CROT\) gate (where \(CROT(\phi):=\exp(i \phi |11 \rangle \langle 11|)\)):

import trueq as tq
import trueq.compilation as tqc
from trueq.algorithms import qft

define a QFT circuit on 4 qubits

qft_circuit = qft(range(4))
# display the output
qft_circuit.draw()
0 1 2 3 Key: Labels: (0,) 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: (0, 1) Name: Gate Locally Equivalent: Non-Clifford Generators: ZZ: -45.00 ZI: 45.00 IZ: 45.00 1.00 1.00 1.00 1.00j Labels: (0, 2) Name: Gate Locally Equivalent: Non-Clifford Generators: ZZ: -22.50 ZI: 22.50 IZ: 22.50 1.00 1.00 1.00 0.71 0.71j Labels: (0, 3) Name: Gate Locally Equivalent: Non-Clifford Generators: ZZ: -11.25 ZI: 11.25 IZ: 11.25 1.00 1.00 1.00 0.92 0.38j Labels: (1,) 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: (1, 2) Name: Gate Locally Equivalent: Non-Clifford Generators: ZZ: -45.00 ZI: 45.00 IZ: 45.00 1.00 1.00 1.00 1.00j Labels: (1, 3) Name: Gate Locally Equivalent: Non-Clifford Generators: ZZ: -22.50 ZI: 22.50 IZ: 22.50 1.00 1.00 1.00 0.71 0.71j Labels: (2,) 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: (2, 3) Name: Gate Locally Equivalent: Non-Clifford Generators: ZZ: -45.00 ZI: 45.00 IZ: 45.00 1.00 1.00 1.00 1.00j Labels: (3,) 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: (0, 3) 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: (1, 2) 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


In order to produce randomly compiled versions of this circuit, we need to replace these non-Clifford entangling gates with a Clifford gate, such as the \(CX\) gate. To tell the trueq.randomly_compile() function to use \(CX\) gates for the compilation, we specify the entangler argument in the function call as follows:

rc_circuits = tq.randomly_compile(qft_circuit, entangler=tq.Gate.cx)

# display the first circuit in this collection:
rc_circuits[0].draw()
0 1 2 3 Key: twirl: Paulis on [0, 1, 2, 3] protocol: RC Labels: (0,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 0.71 0.71j -0.71 -0.71j Y Labels: (1,) Name: Gate.h Aliases: Gate.h Gate.f Gate.cliff12 Generators: Z: -127.28 X: -127.28 0.50 0.50j 0.50 0.50j 0.50 0.50j -0.50 -0.50j H Labels: (2,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (3,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID 1 Labels: (0, 1) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Z: 225.71 X: -93.49 Y: 93.49 -0.65 -0.65j -0.27 0.27j 0.27 0.27j -0.65 0.65j Labels: (1,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: 90.00 0.71j 0.71 0.71 0.71j SX Labels: (2,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (3,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X 2 Labels: (0, 1) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Y: 143.46 X: 143.46 Z: 59.42 0.15 -0.35j 0.35 -0.85j 0.85 0.35j -0.35 -0.15j Labels: (1,) Name: Gate Generators: Z: 143.46 X: -143.46 Y: -59.42 0.50 -0.50j -0.50 0.50j -0.71 -0.71 Labels: (2,) Name: Gate.sy Aliases: Gate.sy Gate.cliff7 Generators: Y: 90.00 0.50 0.50j -0.50 -0.50j 0.50 0.50j 0.50 0.50j SY Labels: (3,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X 3 Labels: (0, 2) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: X: 114.93 Y: 114.93 Z: 22.86 0.14 -0.14j -0.69 -0.69j 0.69 -0.69j 0.14 0.14j Labels: (1,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: -180.00 -1.00 1.00 Z Labels: (2,) Name: Gate.cliff15 Aliases: Gate.cliff15 Generators: Z: 127.28 Y: -127.28 0.71 0.71j -0.71j -0.71 15 Labels: (3,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID 4 Labels: (0, 2) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Z: 183.18 Y: 122.39 X: 122.39 -0.82 -0.16j -0.54 -0.11j 0.11 -0.54j -0.16 0.82j Labels: (1,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (2,) Name: Gate Generators: Z: 144.66 X: 144.66 Y: 96.66 0.27 -0.65j 0.27 -0.65j 0.71 -0.71 Labels: (3,) Name: Gate Generators: Z: -100.84 X: 100.84 Y: -41.77 0.50 0.50j -0.71j -0.50 -0.50j -0.71j 5 Labels: (0, 3) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Y: -121.36 X: 121.36 Z: -11.95 0.07 0.07j 0.70 -0.70j -0.70 -0.70j 0.07 -0.07j Labels: (1,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (2,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (3,) Name: Gate.cliff14 Aliases: Gate.cliff14 Generators: Z: 127.28 Y: 127.28 0.71 -0.71j 0.71j -0.71 14 6 Labels: (0, 3) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Y: 93.30 Z: 93.30 X: 49.87 -0.71j -0.71 0.39 -0.59j 0.59 0.39j Labels: (1,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 0.71 0.71j -0.71 -0.71j Y Labels: (2,) Name: Gate.cliff6 Aliases: Gate.cliff6 Generators: Y: -90.00 0.50 0.50j 0.50 0.50j -0.50 -0.50j 0.50 0.50j 6 Labels: (3,) Name: Gate Generators: Y: -82.04 Z: 43.85 X: 43.85 0.71 0.71 -0.39 -0.59j 0.39 0.59j 7 Labels: (1, 2) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y Labels: (1,) Name: Gate Generators: Y: 100.84 X: -100.84 Z: -41.77 -0.27 0.27j -0.65 -0.65j -0.65 0.65j 0.27 0.27j Labels: (2,) Name: Gate.cliff14 Aliases: Gate.cliff14 Generators: Y: -127.28 Z: -127.28 0.71j 0.71 -0.71 -0.71j 14 Labels: (3,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: -180.00 -1.00 -1.00 X 8 Labels: (1, 2) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: 180.00 -1.00 1.00 Y Labels: (1,) Name: Gate Generators: Z: 225.71 X: 93.49 Y: 93.49 -0.85 -0.35j -0.35 -0.15j 0.15 -0.35j -0.35 0.85j Labels: (2,) Name: Gate Generators: Y: -225.71 X: -93.49 Z: 93.49 -0.71 0.71 -0.50 0.50j -0.50 0.50j Labels: (3,) Name: Gate.sy Aliases: Gate.sy Gate.cliff7 Generators: Y: -270.00 -0.50 -0.50j 0.50 0.50j -0.50 -0.50j -0.50 -0.50j SY 9 Labels: (1, 3) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (1,) Name: Gate Generators: Y: 137.14 X: -137.14 Z: 27.28 -0.14 -0.14j -0.69 0.69j 0.69 0.69j -0.14 0.14j Labels: (2,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: -180.00 -1.00 -1.00 X Labels: (3,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: -270.00 -0.71 0.71j 0.71j -0.71 SX 10 Labels: (1, 3) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 -1.00 -1.00 ID Labels: (1,) Name: Gate Generators: Y: -144.66 Z: 144.66 X: 96.66 -0.71j 0.71 -0.27 -0.65j -0.65 0.27j Labels: (2,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 0.71 0.71j -0.71 -0.71j Y Labels: (3,) Name: Gate Generators: X: -112.50 -0.11 0.54j -0.82 -0.16j -0.82 -0.16j -0.11 0.54j 11 Labels: (2, 3) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (1,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (2,) Name: Gate Generators: Z: -225.71 X: -93.49 Y: -93.49 -0.65 0.65j 0.27 0.27j -0.27 0.27j -0.65 -0.65j Labels: (3,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: -270.00 -0.71 0.71j 0.71j -0.71 SX 12 Labels: (2, 3) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 -1.00j -1.00j X Labels: (1,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y Labels: (2,) Name: Gate Generators: X: -84.92 Z: 35.18 Y: -35.18 -0.71j 0.71 0.50 0.50j 0.50 -0.50j Labels: (3,) Name: Gate Generators: X: 45.00 0.85 -0.35j -0.15 -0.35j -0.15 -0.35j 0.85 -0.35j 13 Labels: (0, 3) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.h Aliases: Gate.h Gate.f Gate.cliff12 Generators: Z: -127.28 X: -127.28 0.71j 0.71j 0.71j -0.71j H Labels: (1,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 -1.00 -1.00 ID Labels: (2,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 -1.00 -1.00 ID Labels: (3,) Name: Gate.cliff10 Aliases: Gate.cliff10 Generators: Y: 127.28 X: 127.28 -0.71 0.71j -0.71 -0.71j 10 14 Labels: (0, 3) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.cliff6 Aliases: Gate.cliff6 Generators: Y: -90.00 0.71 0.71 -0.71 0.71 6 Labels: (1,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (2,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: -180.00 -1.00 1.00 Z Labels: (3,) Name: Gate.cliff11 Aliases: Gate.cliff11 Generators: X: -127.28 Y: 127.28 -0.71 -0.71j -0.71 0.71j 11 15 Labels: (0, 3) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.cliff4 Aliases: Gate.cliff4 Generators: X: 270.00 -0.71 -0.71j -0.71j -0.71 4 Labels: (1,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 -1.00j -1.00j X Labels: (2,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (3,) Name: Gate.cliff15 Aliases: Gate.cliff15 Generators: Z: -127.28 Y: 127.28 -0.71 -0.71j 0.71j 0.71 15 16 Labels: (1, 2) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (1,) Name: Gate.cliff6 Aliases: Gate.cliff6 Generators: Y: -90.00 -0.71j -0.71j 0.71j -0.71j 6 Labels: (2,) Name: Gate.cliff11 Aliases: Gate.cliff11 Generators: Y: -127.28 X: 127.28 0.71 0.71j 0.71 -0.71j 11 Labels: (3,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y 17 Labels: (1, 2) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: 180.00 -1.00 1.00 Y Labels: (1,) Name: Gate.cliff13 Aliases: Gate.cliff13 Generators: Z: 127.28 X: -127.28 0.71 -0.71 -0.71 -0.71 13 Labels: (2,) Name: Gate.cliff11 Aliases: Gate.cliff11 Generators: Y: -127.28 X: 127.28 0.71 -0.71j -0.71 -0.71j 11 Labels: (3,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X 18 Labels: (1, 2) Name: cx Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (1,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: -270.00 -0.71 0.71j 0.71j -0.71 SX Labels: (2,) Name: Gate.cliff14 Aliases: Gate.cliff14 Generators: Y: 127.28 Z: 127.28 0.71 -0.71j 0.71j -0.71 14 Labels: (3,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X


Note that this circuit (and all other circuits in this collection) now consists purely of Clifford gates, and the entangling gates are all \(CX\) gates, while implementing the same logical operation as the original circuit.

When the entangler argument is specified, the trueq.randomly_compile() function will first create a new circuit that only uses the specified entangling gate, and then generate randomly compiled versions of that circuit. This happens implicitly in the background. If desired however, it can also be done explicitly through creating a custom Compiler:

entangler = tq.Gate.cx
# Define a pass for the compiler that specifies which two-qubit gates to use
entangler_pass = tqc.Native2Q([tq.config.GateFactory.from_matrix("CX", entangler.mat)])
# define the compiler
compiler = tqc.Compiler(passes=[entangler_pass, tqc.Merge()])

# compile the QFT circuit
compiled_qft_circuit = compiler.compile(qft_circuit)
# display the resulting circuit
compiled_qft_circuit.draw()
0 1 2 3 Key: Labels: (0,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: -180.00 0.71 0.71j 0.71 0.71j X Labels: (1,) Name: Gate.sy Aliases: Gate.sy Gate.cliff7 Generators: Y: 90.00 0.50 0.50j -0.50 -0.50j 0.50 0.50j 0.50 0.50j SY Labels: (0, 1) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: X: 100.84 Y: -100.84 Z: -41.77 0.27 0.27j 0.65 -0.65j -0.65 -0.65j 0.27 -0.27j Labels: (1,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: 90.00 0.71j 0.71 0.71 0.71j SX Labels: (0, 1) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Y: -143.46 X: 143.46 Z: -59.42 -0.35 -0.15j 0.85 0.35j 0.35 -0.85j 0.15 -0.35j Labels: (2,) Name: Gate.sy Aliases: Gate.sy Gate.cliff7 Generators: Y: 90.00 0.50 0.50j -0.50 -0.50j 0.50 0.50j 0.50 0.50j SY Labels: (0, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Y: -114.93 X: 114.93 Z: -22.86 0.14 0.14j 0.69 -0.69j -0.69 -0.69j 0.14 -0.14j Labels: (2,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: 90.00 0.71j 0.71 0.71 0.71j SX Labels: (0, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: X: 144.66 Y: -144.66 Z: -96.66 -0.54 -0.11j 0.82 0.16j 0.16 -0.82j 0.11 -0.54j Labels: (3,) Name: Gate Generators: Y: 84.92 X: 35.18 Z: 35.18 0.50 0.50j -0.71j 0.50 0.50j 0.71j Labels: (0, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Y: -121.36 X: 121.36 Z: -11.95 0.07 0.07j 0.70 -0.70j -0.70 -0.70j 0.07 -0.07j Labels: (3,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: 90.00 0.71j 0.71 0.71 0.71j SX Labels: (0, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (1,) Name: Gate Generators: Y: 84.92 X: -35.18 Z: 35.18 0.71 -0.71 0.50 0.50j 0.50 0.50j Labels: (2,) Name: Gate Generators: X: 112.50 -0.11 0.54j 0.82 0.16j 0.82 0.16j -0.11 0.54j Labels: (1, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (1,) Name: Gate Generators: X: 100.84 Y: -100.84 Z: -41.77 0.27 0.27j 0.65 -0.65j -0.65 -0.65j 0.27 -0.27j Labels: (2,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: 90.00 0.71j 0.71 0.71 0.71j SX Labels: (1, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (1,) Name: Gate Generators: Y: -143.46 X: 143.46 Z: -59.42 -0.35 -0.15j 0.85 0.35j 0.35 -0.85j 0.15 -0.35j Labels: (3,) Name: Gate Generators: X: 56.25 0.26 0.84j 0.45 -0.14j 0.45 -0.14j 0.26 0.84j Labels: (1, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (1,) Name: Gate Generators: Y: -114.93 X: 114.93 Z: -22.86 0.14 0.14j 0.69 -0.69j -0.69 -0.69j 0.14 -0.14j Labels: (3,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: 90.00 0.71j 0.71 0.71 0.71j SX Labels: (1, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (2,) Name: Gate Generators: Y: 84.92 X: -35.18 Z: 35.18 0.71 -0.71 0.50 0.50j 0.50 0.50j Labels: (3,) Name: Gate Generators: X: 112.50 -0.11 0.54j 0.82 0.16j 0.82 0.16j -0.11 0.54j Labels: (2, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (2,) Name: Gate Generators: X: 100.84 Y: -100.84 Z: -41.77 0.27 0.27j 0.65 -0.65j -0.65 -0.65j 0.27 -0.27j Labels: (3,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: 90.00 0.71j 0.71 0.71 0.71j SX Labels: (2, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Y: 93.30 Z: 93.30 X: 49.87 0.71 -0.71j 0.59 0.39j -0.39 0.59j Labels: (3,) Name: Gate Generators: X: -45.00 0.85 -0.35j 0.15 0.35j 0.15 0.35j 0.85 -0.35j Labels: (0, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.cliff6 Aliases: Gate.cliff6 Generators: Y: -90.00 0.71j 0.71j -0.71j 0.71j 6 Labels: (3,) Name: Gate.cliff10 Aliases: Gate.cliff10 Generators: Y: -127.28 X: -127.28 0.71 -0.71j 0.71 0.71j 10 Labels: (0, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) 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: (3,) Name: Gate.cliff11 Aliases: Gate.cliff11 Generators: X: 127.28 Y: -127.28 0.71 0.71j 0.71 -0.71j 11 Labels: (0, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (1,) Name: Gate Generators: X: 78.48 Y: 52.44 Z: 52.44 0.71 -0.71j 0.65 -0.27j 0.27 0.65j Labels: (2,) Name: Gate Generators: X: 225.71 Y: -93.49 Z: 93.49 -0.50 -0.50j 0.50 -0.50j -0.71j -0.71 Labels: (1, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (1,) Name: Gate.cliff6 Aliases: Gate.cliff6 Generators: Y: -90.00 0.71j 0.71j -0.71j 0.71j 6 Labels: (2,) Name: Gate.cliff10 Aliases: Gate.cliff10 Generators: Y: -127.28 X: -127.28 0.71 -0.71j 0.71 0.71j 10 Labels: (1, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (1,) 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: (2,) Name: Gate.cliff11 Aliases: Gate.cliff11 Generators: X: 127.28 Y: -127.28 0.71 0.71j 0.71 -0.71j 11 Labels: (1, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.cliff15 Aliases: Gate.cliff15 Generators: Z: 127.28 Y: -127.28 -0.71 -0.71j 0.71j 0.71 15 Labels: (1,) Name: Gate.cliff15 Aliases: Gate.cliff15 Generators: Z: 127.28 Y: -127.28 -0.71 -0.71j 0.71j 0.71 15 Labels: (2,) Name: Gate.cliff15 Aliases: Gate.cliff15 Generators: Z: 127.28 Y: -127.28 -0.71 -0.71j 0.71j 0.71 15 Labels: (3,) Name: Gate.cliff15 Aliases: Gate.cliff15 Generators: Z: 127.28 Y: -127.28 -0.71 -0.71j 0.71j 0.71 15


This circuit implements the same operation as the original QFT circuit but all its entangling gates have been replaced by a combination of single-qubit gates and two-qubit \(CX\) gates.

Note

For more information on the usage of True-Q™'s Compiler take a look at the Compilation Basics and Defining Custom Compilers examples.

Since this compiled circuit consists purely of Clifford gates, we can call the trueq.randomly_compile() function on it without any further arguments:

rc_circuits = tq.randomly_compile(compiled_qft_circuit)
# display a sample circuit from this collection:
rc_circuits[0].draw()
0 1 2 3 Key: twirl: Paulis on [0, 1, 2, 3] protocol: RC Labels: (0,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: -180.00 0.71 0.71j -0.71 -0.71j Z Labels: (1,) Name: Gate.sy Aliases: Gate.sy Gate.cliff7 Generators: Y: 90.00 0.50 0.50j -0.50 -0.50j 0.50 0.50j 0.50 0.50j SY Labels: (2,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y Labels: (3,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X 1 Labels: (0, 1) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Y: 100.84 X: -100.84 Z: -41.77 -0.27 0.27j -0.65 -0.65j -0.65 0.65j 0.27 0.27j Labels: (1,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: 90.00 0.71j 0.71 0.71 0.71j SX Labels: (2,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 -1.00 -1.00 ID Labels: (3,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z 2 Labels: (0, 1) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Z: 84.92 Y: 35.18 X: -35.18 0.85 0.35j -0.35 -0.15j -0.15 0.35j -0.35 0.85j Labels: (1,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (2,) Name: Gate.cliff13 Aliases: Gate.cliff13 Generators: X: -127.28 Z: 127.28 -0.50 -0.50j 0.50 0.50j 0.50 0.50j 0.50 0.50j 13 Labels: (3,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 -1.00 -1.00 ID 3 Labels: (0, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: X: -114.93 Y: 114.93 Z: -22.86 0.14 0.14j -0.69 0.69j 0.69 0.69j 0.14 -0.14j Labels: (1,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (2,) Name: Gate.cliff15 Aliases: Gate.cliff15 Generators: Z: 127.28 Y: -127.28 0.71 0.71j -0.71j -0.71 15 Labels: (3,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 -1.00 -1.00 ID 4 Labels: (0, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Y: -144.66 X: -144.66 Z: 96.66 -0.54 -0.11j 0.82 0.16j -0.16 0.82j -0.11 0.54j Labels: (1,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (2,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (3,) Name: Gate Generators: X: -100.84 Z: 100.84 Y: -41.77 -0.71j 0.50 0.50j 0.71j 0.50 0.50j 5 Labels: (0, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Y: -121.36 X: -121.36 Z: 11.95 0.07 0.07j -0.70 0.70j -0.70 -0.70j -0.07 0.07j Labels: (1,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (2,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (3,) Name: Gate.cliff14 Aliases: Gate.cliff14 Generators: Z: -127.28 Y: -127.28 0.71j 0.71 -0.71 -0.71j 14 6 Labels: (0, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: -180.00 -1.00 -1.00 X Labels: (1,) Name: Gate Generators: Y: -84.92 Z: 35.18 X: 35.18 0.71 0.71 -0.50 -0.50j 0.50 0.50j Labels: (2,) Name: Gate Generators: Y: 149.66 Z: -100.00 -0.11 0.54j -0.82 -0.16j 0.82 0.16j 0.11 -0.54j Labels: (3,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y 7 Labels: (1, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 -1.00 -1.00 ID Labels: (1,) Name: Gate Generators: Z: 225.71 X: 93.49 Y: -93.49 -0.65 -0.65j 0.27 -0.27j -0.27 -0.27j -0.65 0.65j Labels: (2,) Name: Gate.cliff15 Aliases: Gate.cliff15 Generators: Z: 127.28 Y: -127.28 0.71 0.71j -0.71j -0.71 15 Labels: (3,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y 8 Labels: (1, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 -1.00 -1.00 ID Labels: (1,) Name: Gate Generators: Y: -100.84 X: 100.84 Z: 41.77 0.15 -0.35j 0.35 -0.85j -0.85 -0.35j 0.35 0.15j Labels: (2,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: -180.00 -1.00 -1.00 X Labels: (3,) Name: Gate Generators: Y: -158.75 Z: -84.85 -0.45 0.14j 0.26 0.84j -0.26 -0.84j 0.45 -0.14j 9 Labels: (1, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 -1.00 -1.00 ID Labels: (1,) Name: Gate Generators: Z: -257.81 Y: -51.28 X: -51.28 -0.69 0.69j 0.14 0.14j -0.14 0.14j -0.69 -0.69j Labels: (2,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y Labels: (3,) Name: Gate.cliff15 Aliases: Gate.cliff15 Generators: Z: 127.28 Y: -127.28 0.71 0.71j -0.71j -0.71 15 10 Labels: (1, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (1,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (2,) Name: Gate Generators: X: 100.84 Z: -100.84 Y: 41.77 0.71 -0.71 -0.50 -0.50j -0.50 -0.50j Labels: (3,) Name: Gate Generators: Z: -149.66 Y: -100.00 0.82 0.16j 0.11 -0.54j -0.11 0.54j -0.82 -0.16j 11 Labels: (2, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (1,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (2,) Name: Gate Generators: Y: -100.84 X: -100.84 Z: 41.77 0.27 0.27j -0.65 0.65j -0.65 -0.65j -0.27 0.27j Labels: (3,) Name: Gate.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 0.71 0.71j 0.71j 0.71 4 12 Labels: (2, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate Generators: Y: -93.30 Z: -93.30 X: 49.87 0.59 0.39j 0.39 -0.59j -0.71 -0.71j Labels: (1,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: -180.00 -1.00 -1.00 X Labels: (2,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (3,) Name: Gate Generators: X: 135.00 0.15 0.35j 0.85 -0.35j 0.85 -0.35j 0.15 0.35j 13 Labels: (0, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.cliff13 Aliases: Gate.cliff13 Generators: X: -127.28 Z: 127.28 -0.71j 0.71j 0.71j 0.71j 13 Labels: (1,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (2,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (3,) Name: Gate.cliff10 Aliases: Gate.cliff10 Generators: Y: -127.28 X: -127.28 0.71 -0.71j 0.71 0.71j 10 14 Labels: (0, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.cliff6 Aliases: Gate.cliff6 Generators: Y: -90.00 0.71 0.71 -0.71 0.71 6 Labels: (1,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (2,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (3,) Name: Gate.s Aliases: Gate.s Gate.sz Gate.cliff9 Generators: Z: 90.00 0.71 -0.71j 0.71 0.71j S 15 Labels: (0, 3) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 -1.00 -1.00 ID Labels: (1,) Name: Gate Generators: X: -78.48 Z: -52.44 Y: 52.44 0.65 -0.27j 0.27 0.65j 0.71 -0.71j Labels: (2,) Name: Gate Generators: Z: 100.84 Y: 100.84 X: 41.77 0.50 -0.50j -0.50 -0.50j 0.71 0.71j Labels: (3,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z 16 Labels: (1, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y Labels: (1,) Name: Gate.cliff13 Aliases: Gate.cliff13 Generators: X: -127.28 Z: 127.28 -0.71j 0.71j 0.71j 0.71j 13 Labels: (2,) Name: Gate.cliff10 Aliases: Gate.cliff10 Generators: X: -127.28 Y: -127.28 0.71 0.71j -0.71 0.71j 10 Labels: (3,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y 17 Labels: (1, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (1,) 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: (2,) Name: Gate.cliff8 Aliases: Gate.cliff8 Generators: Z: -90.00 0.71 0.71j 0.71 -0.71j 8 Labels: (3,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z 18 Labels: (1, 2) Name: CX Aliases: Gate.cx Gate.cnot Parameters: Locally Equivalent: CNOT Generators: ZX: -90.00 IX: 90.00 ZI: 90.00 1.00 1.00 1.00 1.00 CX CX Labels: (0,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: -270.00 -0.71 0.71j 0.71j -0.71 SX Labels: (1,) Name: Gate.cliff14 Aliases: Gate.cliff14 Generators: Y: 127.28 Z: 127.28 -0.71j -0.71 0.71 0.71j 14 Labels: (2,) Name: Gate.cliff14 Aliases: Gate.cliff14 Generators: Y: 127.28 Z: 127.28 -0.71j -0.71 0.71 0.71j 14 Labels: (3,) Name: Gate.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 0.71j -0.71 -0.71 0.71j 4


Both methods, i.e. using the entangler argument and compiling the circuit explicitly, yield the same result and allow for the generation of randomly compiled circuits of an input circuit with non-Clifford entangling gates.

Specifying the Action on Idle Qubits

By default, the trueq.randomly_compile() function will insert a single-qubit twirling and a matching compensation gate around every hard cycle in the circuit. There are however applications in which only a subset of the qubits is involved in the algorithm in a given cycle while the other qubits remain idle. If, in addition to that, the computation is performed on a system with non-negligible single-qubit errors, it might be desirable to not apply any extra gates to those qubits which would otherwise be idle.

This can be achieved through performing the compilation of the input circuit explicitly by defining a custom :py:class`~trueq.compilation.Compiler` and specifying the Randomized Compiling Pass manually. There are two options:

  1. RCCycle: this is the default Pass that performs Randomized Compiling on a set of input cycles by inserting single-qubit gates on either side of the cycles.

  2. RCLocal: this Pass also performs Randomized Compiling on a set of input cycles, however the single-qubit gates are only added to qubits that the cycles they surround act on; idling qubits are left alone.

Let’s take a look at a concrete example. Consider the follwing circuit of stacked \(CX\) gates that has two idling qubits in each cycle:

circuit = tq.Circuit(
    [
        {0: tq.Gate.h, 3: tq.Gate.h},
        {(0, 1): tq.Gate.cx},
        {(1, 2): tq.Gate.cx},
        {(2, 3): tq.Gate.cx},
    ]
)
circuit.draw()
0 1 2 3 Key: Labels: (0,) 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: (3,) 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: (0, 1) 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: (1, 2) 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: (2, 3) 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


We can apply our default Randomized Compiling to this circuit through the following Compiler configuration (and the tq.randomly_compile() would produce the same result):

rc_cycle_compiler = tqc.Compiler(
    passes=[
        # specify a pass to mark hard cycles:
        tqc.MarkCycles(),
        # specify the main RC pass:
        tqc.RCCycle(),
        # merge single-qubit cycles together:
        tqc.Merge(),
    ]
)
# generate one randomly compiled circuit using this compiler:
rc_cycle_circuit = rc_cycle_compiler.compile(circuit)
rc_cycle_circuit.draw()
0 1 2 3 Key: twirl: Paulis on [0, 1, 2, 3] protocol: RC Labels: (0,) Name: Gate.cliff13 Aliases: Gate.cliff13 Generators: Z: 127.28 X: -127.28 0.71 -0.71 -0.71 -0.71 13 Labels: (1,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (2,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (3,) 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 1 Labels: (0, 1) 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: (0,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: -180.00 -1.00 1.00 Z Labels: (1,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (2,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: -180.00 -1.00 1.00 Z Labels: (3,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID 2 Labels: (1, 2) 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: (0,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (1,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (2,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y Labels: (3,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y 3 Labels: (2, 3) 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: (0,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (1,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (2,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (3,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y


Note that with the RCCycle pass, every hard cycle is now fully surrounded by single-qubit gates.

In contrast, when we apply the RCLocal pass, single-qubit gates are only applied to qubits that the hard cycles act on:

rc_local_compiler = tqc.Compiler(
    passes=[
        # specify a pass to mark hard cycles:
        tqc.MarkCycles(),
        # specify the main RC pass:
        tqc.RCLocal(),
        # merge single-qubit cycles together:
        tqc.Merge(),
    ]
)
# generate one randomly compiled circuit using this compiler:
rc_local_circuit = rc_local_compiler.compile(circuit)
rc_local_circuit.draw()
0 1 2 3 Key: protocol: RC twirling_group: P Labels: (0,) Name: Gate.cliff6 Aliases: Gate.cliff6 Generators: Y: -90.00 0.71 0.71 -0.71 0.71 6 Labels: (1,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (3,) 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 1 Labels: (0, 1) 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: (0,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (1,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (2,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID 2 Labels: (1, 2) 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: (1,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (2,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (3,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID 3 Labels: (2, 3) 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: (2,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (3,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID


Total running time of the script: ( 0 minutes 0.668 seconds)

Gallery generated by Sphinx-Gallery