Randomized Compiling 1

This example will take a circuit and generate 30 randomly compiled circuits that implement the same unitary as the original circuit.

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.

Note

Cycles containing multi-qubit gates are assigned to be immutable by default, while single-qubit gates are mutable by default. Randomized compiling will not attempt to compile new gates into immutable cycles.

Import True-Q:

import trueq as tq

Define a circuit which applies alternating cycles, with an X gate on qubit 0 in one cycle and a controlled-Z gate on qubits 0 and 1 in the other cycle:

cycle1 = tq.Cycle({(0,): tq.Gate.x})
cycle2 = tq.Cycle({(0, 1): tq.Gate.cz})
circuit = tq.Circuit([cycle1, cycle2, cycle1, cycle2, cycle1])

Display the original circuit:

circuit
Circuit
Key:
No key present in circuit.
 
 
(0): Gate.x
Name:
  • Gate.x
Aliases:
  • Gate.x
  • Gate.cliff1
Generators:
  • 'X': 180.0
Matrix:
  • 1.00 1.00
imm
(0, 1): Gate.cz
Name:
  • Gate.cz
Aliases:
  • Gate.cz
Likeness:
  • CNOT
Generators:
  • 'IZ': 90.0
  • 'ZI': 90.0
  • 'ZZ': -90.0
Matrix:
  • 1.00 1.00 1.00 -1.00
 
(0): Gate.x
Name:
  • Gate.x
Aliases:
  • Gate.x
  • Gate.cliff1
Generators:
  • 'X': 180.0
Matrix:
  • 1.00 1.00
imm
(0, 1): Gate.cz
Name:
  • Gate.cz
Aliases:
  • Gate.cz
Likeness:
  • CNOT
Generators:
  • 'IZ': 90.0
  • 'ZI': 90.0
  • 'ZZ': -90.0
Matrix:
  • 1.00 1.00 1.00 -1.00
 
(0): Gate.x
Name:
  • Gate.x
Aliases:
  • Gate.x
  • Gate.cliff1
Generators:
  • 'X': 180.0
Matrix:
  • 1.00 1.00


Call randomized compiling on the circuit:

compiled_circuit = tq.randomly_compile(circuit)

Display one of the randomly compiled circuits:

compiled_circuit[0]
Circuit
Key:
  • n_random_cycles: 2
  • protocol: RC
  • twirl: (('P', 0), ('P', 1))
   
 
(0): Gate.x
Name:
  • Gate.x
Aliases:
  • Gate.x
  • Gate.cliff1
Generators:
  • 'X': 180.0
Matrix:
  • 1.00 1.00
(1): Gate.x
Name:
  • Gate.x
Aliases:
  • Gate.x
  • Gate.cliff1
Generators:
  • 'X': 180.0
Matrix:
  • 1.00 1.00
imm
(0, 1): Gate.cz
Name:
  • Gate.cz
Aliases:
  • Gate.cz
Likeness:
  • CNOT
Generators:
  • 'IZ': 90.0
  • 'ZI': 90.0
  • 'ZZ': -90.0
Matrix:
  • 1.00 1.00 1.00 -1.00
 
 
(0): Gate.z
Name:
  • Gate.z
Aliases:
  • Gate.z
  • Gate.cliff3
Generators:
  • 'Z': 180.0
Matrix:
  • 1.00 -1.00
(1): Gate.id
Name:
  • Gate.id
Aliases:
  • Gate.id
  • Gate.i
  • Gate.cliff0
Likeness:
  • Identity
Generators:
  • 'I': 0
Matrix:
  • 1.00 1.00
imm
(0, 1): Gate.cz
Name:
  • Gate.cz
Aliases:
  • Gate.cz
Likeness:
  • CNOT
Generators:
  • 'IZ': 90.0
  • 'ZI': 90.0
  • 'ZZ': -90.0
Matrix:
  • 1.00 1.00 1.00 -1.00
 
 
(0): Gate.z
Name:
  • Gate.z
Aliases:
  • Gate.z
  • Gate.cliff3
Generators:
  • 'Z': 180.0
Matrix:
  • 1.00 -1.00
(1): Gate.y
Name:
  • Gate.y
Aliases:
  • Gate.y
  • Gate.cliff2
Generators:
  • 'Y': 180.0
Matrix:
  • -1.00 1.00


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

Gallery generated by Sphinx-Gallery