Note
Click here to download the full example code
Randomized Compiling 2¶
In this example, two cycles have been marked with non-default markers. Note that the circuit depth increases in this instance because the random gates cannot be compiled into the adjacent cycles due to the mismatch in markers.
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
If the cycles in the circuit are all marked with 0
, then cycles containing
multi-qubit gates will automatically be uniquely marked by default. Randomized
compiling will not attempt to compile new gates into cycles with marker 0
. All
new cycles inserted with randomized compilation will have default markers.
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, and where the middle cycle with an X gate is marked:
cycle1 = tq.Cycle({(0,): tq.Gate.x})
cycle2 = tq.Cycle({(0, 1): tq.Gate.cz}, marker=3)
cycle3 = tq.Cycle({(0,): tq.Gate.x}, marker=5)
circuit = tq.Circuit([cycle1, cycle2, cycle3, cycle2, cycle1])
Display the original circuit:
circuit
Circuit
|
|
|
(0):
Gate.x
|
3
|
(0, 1):
Gate.cz
|
5
|
(0):
Gate.x
|
3
|
(0, 1):
Gate.cz
|
|
(0):
Gate.x
|
Call randomized compiling on the circuit:
compiled_circuit = tq.randomly_compile(circuit)
Display one of the randomly compiled circuits:
compiled_circuit[0]
Circuit
|
||
|
(0):
Gate.y
|
(1):
Gate.z
|
3
|
(0, 1):
Gate.cz
|
  |
|
(0):
Gate.y
|
(1):
Gate.x
|
5
|
(0):
Gate.x
|
  |
|
(0):
Gate.z
|
(1):
Gate.z
|
3
|
(0, 1):
Gate.cz
|
  |
|
(0):
Gate.id
|
(1):
Gate.y
|
Total running time of the script: ( 0 minutes 0.038 seconds)