Download

Download this file as Jupyter notebook: rc_advanced.ipynb.

Example: Randomized Compilation with different Compilation Options

Randomized Compiling in True-Q™ can be configured in various ways. For example, the Example: 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. Three other important configuration options include:

  1. Measurement randomization through additional Paulis

    An effective way to reduce readout bias is to randomize the measurements by performing a random Pauli operation just before each measurement instruction. This can be added to Randomized Compiling by specifying the compile_paulis argument.

  2. 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.

  3. 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.

[2]:
import numpy as np

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

Measurement Randomization through Additional Paulis

To remove readout bias, we can randomize measurements using the keyword argument compile_paulis of the randomly_compile() function. This argument is set to False by default because it changes the measurement outcomes which can confuse new users. When set to True, a single-qubit cycle of randomly selected Paulis (or Weyls in the case of qudits) will be added right before each measurement operation in a randomly compiled circuit and merged into any preceding single-qubit gate cycle. Take a look at the corresponding compiler pass CompilePaulis for more information.

Let’s walk through a quick example. We begin by creating a simple circuit to play with and generate a randomly compiled version of that circuit:

[3]:
cycle1 = {0: tq.Gate.h}
cycle2 = {(0, 1): tq.Gate.cx}
cycle3 = {2: tq.Gate.h}
cycle4 = {(2, 3): tq.Gate.cx}

circuit = tq.Circuit([cycle1, cycle2, cycle3, cycle4])
circuit.measure_all()
circuit.draw(interactive=False)
[3]:
0 1 2 3 H CX CX H CX CX 1 M M M M
[4]:
rc_circuits = tq.randomly_compile(circuit, compile_paulis=True)

# Select one circuit from the collection
rc_circuit = rc_circuits[0]

rc_circuit.draw(interactive=False)
[4]:
0 1 2 3 13 ID X Y 2 CX CX Y ID H Z 3 CX CX X Y X ID 1 M M M M

When we compare the outcomes of the original circuit and the randomly compiled circuit, we are likely to observe different bitstrings:

[5]:
# instantiate a simulator and run the original and the RC circuit
sim = tq.Simulator()

original_result = sim.sample(circuit, n_shots=np.inf)
rc_result = sim.sample(rc_circuit, n_shots=np.inf)

tq.visualization.plot_results(
    original_result,
    rc_result,
    labels=["Original Circuit", "RC Circuit with compiled Paulis"],
)
../../_images/guides_error_suppression_rc_advanced_7_0.png

The Pauli operators that were added to the RC circuit are stored in the circuit’s key attribute as a Weyls instance:

[6]:
rc_circuit.key
[6]:
Key(compiled_pauli=Weyls('XZYX'), protocol='RC', twirl=Twirl({(0,): 'P', (1,): 'P', (2,): 'P', (3,): 'P'}, dim=2))

To recover the original bitstrings, we can apply the decompiled_results() method to the result with the compiled_pauli key from the circuit:

[7]:
compiled_paulis = rc_circuit.key.compiled_pauli

rc_result_decompiled = rc_result.decompiled_results(compiled_paulis)

tq.visualization.plot_results(
    original_result,
    rc_result_decompiled,
    labels=["Original Result", "RC Result decompiled"],
)
../../_images/guides_error_suppression_rc_advanced_11_0.png

When averaging over the results of multiple RC circuits in a collection, the sum_results() function can automatically decompile the results. This behavior can be adjusted by changing the value of the decompile_paulis argument. By default, it is set to True which in most cases yields the desirable outcome:

[8]:
# run all RC circuits on the simulator
sim.run(rc_circuits)

# average the decompiled results
rc_circuits.sum_results(decompile_paulis=True).normalized()
[8]:
Results({'1111': 0.24933333333333332, '1100': 0.26, '0011': 0.244, '0000': 0.24666666666666665})

As you can see, the averaged results contain only the bitstrings that were in the original set of results, since the result of every RC circuit in the collection has been decompiled.

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|)\)):

[9]:
# define a QFT circuit on 4 qubits
qft_circuit = qft(range(4))
# display the output
qft_circuit.draw()
[9]:
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:

[10]:
rc_circuits = tq.randomly_compile(qft_circuit, entangler=tq.Gate.cx)

# display the first circuit in this collection:
rc_circuits[0].draw()
[10]:
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.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: (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 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: -143.46 X: -143.46 Z: -59.42 -0.27 0.27j 0.65 0.65j -0.65 0.65j -0.27 -0.27j Labels: (1,) Name: Gate.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 -0.71j 0.71 0.71 -0.71j 4 Labels: (2,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: -180.00 -1.00 -1.00 X 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: (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.15 -0.35j -0.35 0.85j 0.85 0.35j 0.35 0.15j Labels: (1,) Name: Gate Generators: X: 143.46 Z: -143.46 Y: -59.42 -0.71 0.71 0.50 -0.50j 0.50 -0.50j 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.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: 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: (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.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 -0.71j 0.71 0.71 -0.71j 4 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.11 0.54j 0.16 -0.82j -0.82 -0.16j -0.54 -0.11j 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 Generators: Z: -85.50 X: 85.50 Y: 57.13 -0.27 0.65j 0.27 -0.65j 0.71 0.71 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: Z: -89.68 Y: 8.83 X: -8.83 0.70 -0.70j 0.07 0.07j 0.07 -0.07j -0.70 -0.70j 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.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (3,) Name: Gate.cliff14 Aliases: Gate.cliff14 Generators: Y: -127.28 Z: -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 Generators: X: 82.04 Y: 43.85 Z: 43.85 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.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: Z: -93.30 X: 93.30 Y: 49.87 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.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (1,) Name: Gate Generators: Y: 143.46 X: -143.46 Z: 59.42 -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: (3,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: 180.00 -0.71 0.71j 0.71 -0.71j 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: -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 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.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 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: Z: -88.74 Y: 17.65 X: -17.65 0.69 0.69j -0.14 0.14j 0.14 0.14j 0.69 -0.69j 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: Y: -127.28 Z: -127.28 0.71j 0.71 -0.71 -0.71j 14 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.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (1,) Name: Gate Generators: Z: -144.66 Y: 144.66 X: 96.66 0.27 0.65j -0.65 0.27j -0.71j -0.71 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: 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.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: Z: 84.92 X: -35.18 Y: -35.18 0.65 -0.65j 0.27 0.27j -0.27 0.27j 0.65 0.65j Labels: (3,) Name: Gate.cliff14 Aliases: Gate.cliff14 Generators: Y: -127.28 Z: -127.28 0.71j 0.71 -0.71 -0.71j 14 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.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z 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 Generators: Y: -143.46 Z: 143.46 X: 59.42 -0.71 -0.71j -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.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: (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.s Aliases: Gate.s Gate.sz Gate.cliff9 Generators: Z: 90.00 0.71 -0.71j 0.71 0.71j S 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.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: (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.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 1.00 -1.00 Z Labels: (3,) Name: Gate.cliff8 Aliases: Gate.cliff8 Generators: Z: -90.00 0.71 -0.71j -0.71 -0.71j 8 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.cliff14 Aliases: Gate.cliff14 Generators: Y: -127.28 Z: -127.28 0.71j 0.71 -0.71 -0.71j 14 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.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 -0.71j 0.71 0.71 -0.71j 4 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 -0.71 0.71j 0.71 -0.71j Y Labels: (1,) 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: (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.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID 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.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID 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.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 -0.71 0.71j 0.71 -0.71j Y 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.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID Labels: (1,) Name: Gate.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 -0.71j 0.71 0.71 -0.71j 4 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.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID

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:

[11]:
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()
[11]:
0 1 2 3 Key: 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: (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.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 0.71 0.71j 0.71j 0.71 4 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.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 0.71 0.71j 0.71j 0.71 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: 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 Z: 35.18 X: 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: X: -121.36 Y: -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.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 0.71 0.71j 0.71j 0.71 4 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: Z: 100.84 X: 100.84 Y: -41.77 0.50 -0.50j 0.50 -0.50j -0.71j 0.71j Labels: (2,) Name: Gate Generators: X: -67.50 0.82 0.16j -0.11 0.54j -0.11 0.54j 0.82 0.16j 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: -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.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 0.71 0.71j 0.71j 0.71 4 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: -123.75 0.45 -0.14j 0.26 0.84j 0.26 0.84j 0.45 -0.14j 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.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 0.71 0.71j 0.71j 0.71 4 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: Z: 100.84 X: 100.84 Y: -41.77 0.50 -0.50j 0.50 -0.50j -0.71j 0.71j Labels: (3,) Name: Gate Generators: X: -67.50 0.82 0.16j -0.11 0.54j -0.11 0.54j 0.82 0.16j 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: 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 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: X: -82.04 Y: -43.85 Z: 43.85 0.59 0.39j -0.39 0.59j -0.71 0.71j Labels: (3,) Name: Gate Generators: X: 135.00 0.15 0.35j 0.85 -0.35j 0.85 -0.35j 0.15 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.71 0.71 -0.71 0.71 6 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 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: X: -127.28 Z: -127.28 0.71j 0.71j 0.71j -0.71j H Labels: (3,) Name: Gate.cliff8 Aliases: Gate.cliff8 Generators: Z: -90.00 0.71 0.71j 0.71 -0.71j 8 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: -85.50 Z: 85.50 X: -57.13 0.65 -0.27j 0.27 0.65j -0.71 0.71j Labels: (2,) Name: Gate Generators: Y: -100.84 Z: 100.84 X: -41.77 0.50 -0.50j 0.50 0.50j -0.71 0.71j 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.71 0.71 -0.71 0.71 6 Labels: (2,) Name: Gate.s Aliases: Gate.s Gate.sz Gate.cliff9 Generators: Z: 90.00 0.71 -0.71j 0.71 0.71j S 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: X: -127.28 Z: -127.28 0.71j 0.71j 0.71j -0.71j H Labels: (2,) Name: Gate.cliff8 Aliases: Gate.cliff8 Generators: Z: -90.00 0.71 0.71j 0.71 -0.71j 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.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 0.71 0.71j 0.71j 0.71 4 Labels: (1,) Name: Gate.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 0.71 0.71j 0.71j 0.71 4 Labels: (2,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: 90.00 -0.71j -0.71 -0.71 -0.71j SX Labels: (3,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: 90.00 -0.71j -0.71 -0.71 -0.71j SX

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 Example: Compilation Basics and Example: 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:

[12]:
rc_circuits = tq.randomly_compile(compiled_qft_circuit)
# display a sample circuit from this collection:
rc_circuits[0].draw()
[12]:
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.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: X: 143.46 Y: -143.46 Z: 59.42 -0.27 -0.27j 0.65 -0.65j -0.65 -0.65j -0.27 0.27j Labels: (1,) Name: Gate.cliff14 Aliases: Gate.cliff14 Generators: Z: -127.28 Y: -127.28 0.71j 0.71 -0.71 -0.71j 14 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 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: 100.84 X: 100.84 Z: -41.77 0.35 0.15j -0.85 -0.35j 0.35 -0.85j 0.15 -0.35j Labels: (1,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 0.71 -0.71j -0.71 0.71j Z 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.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y 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: 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: (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: Y: -127.28 Z: 127.28 -0.71j 0.71 -0.71 0.71j 15 Labels: (3,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y 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: 78.48 Y: -52.44 X: 52.44 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.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (3,) Name: Gate Generators: Z: -143.46 X: 143.46 Y: 59.42 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: 132.58 X: -132.58 Z: 13.06 -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.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (3,) Name: Gate.cliff15 Aliases: Gate.cliff15 Generators: Y: -127.28 Z: 127.28 -0.71j 0.71 -0.71 0.71j 15 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.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y Labels: (1,) Name: Gate Generators: Z: 100.84 X: 100.84 Y: -41.77 0.50 -0.50j 0.50 -0.50j -0.71j 0.71j Labels: (2,) 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 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: 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.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 -0.71j 0.71 0.71 -0.71j 4 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.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 0.71 -0.71j -0.71 0.71j Z Labels: (1,) Name: Gate Generators: Y: 100.84 X: 100.84 Z: -41.77 0.35 0.15j -0.85 -0.35j 0.35 -0.85j 0.15 -0.35j 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 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: 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.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: 90.00 0.71j 0.71 0.71 0.71j 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.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 0.71 -0.71j -0.71 0.71j Z Labels: (2,) Name: Gate Generators: X: -100.84 Z: 100.84 Y: 41.77 0.50 -0.50j -0.50 0.50j 0.71j 0.71j Labels: (3,) Name: Gate Generators: X: -67.50 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.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y Labels: (1,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 0.71 -0.71j -0.71 0.71j 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.cliff15 Aliases: Gate.cliff15 Generators: Y: -127.28 Z: 127.28 -0.71j 0.71 -0.71 0.71j 15 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.39 0.59j 0.59 0.39j -0.71j 0.71 Labels: (1,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y Labels: (2,) Name: Gate.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 0.71 -0.71j -0.71 0.71j Z 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.cliff6 Aliases: Gate.cliff6 Generators: Y: 270.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: (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.cliff8 Aliases: Gate.cliff8 Generators: Z: 270.00 -0.71 -0.71j -0.71 0.71j 8 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.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: (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 0.71 -0.71j -0.71 0.71j Z Labels: (3,) Name: Gate.cliff11 Aliases: Gate.cliff11 Generators: Y: -127.28 X: 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.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 Y: -52.44 Z: -52.44 0.65 -0.27j -0.27 -0.65j -0.71 -0.71j Labels: (2,) Name: Gate Generators: Y: 100.84 Z: 100.84 X: 41.77 0.50 -0.50j -0.50 -0.50j 0.71 0.71j Labels: (3,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y 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.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 0.71 -0.71j -0.71 0.71j Z Labels: (1,) Name: Gate.cliff13 Aliases: Gate.cliff13 Generators: X: -127.28 Z: 127.28 0.71 -0.71 -0.71 -0.71 13 Labels: (2,) Name: Gate.s Aliases: Gate.s Gate.sz Gate.cliff9 Generators: Z: 90.00 0.71 -0.71j 0.71 0.71j S Labels: (3,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X 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.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X Labels: (1,) 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: (2,) Name: Gate.s Aliases: Gate.s Gate.sz Gate.cliff9 Generators: Z: 90.00 0.71 -0.71j 0.71 0.71j S Labels: (3,) Name: Gate.id Aliases: Gate.id Gate.i Gate.cliff0 Locally Equivalent: Identity Generators: I: 0.00 1.00 1.00 ID 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: 90.00 0.71j 0.71 0.71 0.71j SX 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.cliff4 Aliases: Gate.cliff4 Generators: X: -90.00 -0.71j 0.71 0.71 -0.71j 4 Labels: (3,) Name: Gate.sx Aliases: Gate.sx Gate.cliff5 Generators: X: 90.00 0.71j 0.71 0.71 0.71j SX

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:

[13]:
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()
[13]:
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):

[14]:
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()
[14]:
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.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y 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.sy Aliases: Gate.sy Gate.cliff7 Generators: Y: 90.00 0.71 -0.71 0.71 0.71 SY 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.x Aliases: Gate.x Gate.cliff1 Generators: X: -180.00 -1.00 -1.00 X 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.z Aliases: Gate.z Gate.cliff3 Generators: Z: -180.00 1.00 -1.00 Z Labels: (2,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: -180.00 -1.00 -1.00 X Labels: (3,) Name: Gate.x Aliases: Gate.x Gate.cliff1 Generators: X: -180.00 -1.00 -1.00 X 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.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y Labels: (1,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y 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

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:

[15]:
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()
[15]:
0 1 2 3 Key: protocol: RC twirling_group: P Labels: (0,) Name: Gate.sy Aliases: Gate.sy Gate.cliff7 Generators: Y: 90.00 0.71 -0.71 0.71 0.71 SY 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.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.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X 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.x Aliases: Gate.x Gate.cliff1 Generators: X: 180.00 1.00 1.00 X 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 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.z Aliases: Gate.z Gate.cliff3 Generators: Z: 180.00 -1.00 1.00 Z Labels: (3,) Name: Gate.y Aliases: Gate.y Gate.cliff2 Generators: Y: -180.00 1.00 -1.00 Y

Download

Download this file as Jupyter notebook: rc_advanced.ipynb.