Defining Custom Compilers

A Compiler instance contains a list of Pass instances. During compilation of a circuit, each of these passes are executed, in order, to mutate a copy of the circuit. See the compiler API page for a complete list of built-in passes and their documentation.

Predefined Pass Lists

Several useful combinations of pass classes are provided as members of the compiler class: HARDWARE_PASSES, SIMPLIFY_PASSES, RC_PASSES, and NATIVE2Q_PASSES. See their documentation for further details.

Note that these pass classes need to be instantiated before they can be given to the compiler constructor. For certain types of advanced usage, directly invoking the constructor may be the preferred method. However, the compiler also has two static covenience methods to automate pass instantiation: from_config() and basic(). The first of these uses a Config object to pass relevant gate factories to each pass, and the second is a further specialization that auto-instantiates these factories based on a desired entangling gate and mode (which may not be relevant to all passes).

import trueq as tq

# a compiler to simplify circuits
compiler1 = tq.Compiler.basic(passes=tq.Compiler.SIMPLIFY_PASSES)

# a compiler that does randomized compiling
compiler2 = tq.Compiler.basic(passes=tq.Compiler.RC_PASSES)

# a compiler that decomposes two-qubit gates into the specified entangling gate,
# then randomly compiles, and then converts all gates into hardware compatable gates.
# for this example, we use the maximally entangling cross-resonance gate.
passes = (
    tq.Compiler.NATIVE2Q_PASSES + tq.Compiler.RC_PASSES + tq.Compiler.HARDWARE_PASSES
)
compiler3 = tq.Compiler.basic(entangler=tq.Gate.rp("ZX", 90), passes=passes)

We demonstrate the last of these compilers by defining the following circuit:

circuit = tq.Circuit(
    [{range(4): tq.Gate.h}, {(0, 1): tq.Gate.rp("ZZ", 22), (2, 3): tq.Gate.cz}]
).measure_all()
circuit
True-Q formatting will not be loaded without trusting this notebook or rerunning the affected cells. Notebooks can be marked as trusted by clicking "File -> Trust Notebook".
Circuit
Key:
No key present in circuit.
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): Gate.h
Name:
  • Gate.h
Aliases:
  • Gate.h
  • Gate.cliff12
Generators:
  • 'X': 127.279
  • 'Z': 127.279
Matrix:
  • 0.71 0.71 0.71 -0.71
(1): Gate.h
Name:
  • Gate.h
Aliases:
  • Gate.h
  • Gate.cliff12
Generators:
  • 'X': 127.279
  • 'Z': 127.279
Matrix:
  • 0.71 0.71 0.71 -0.71
(2): Gate.h
Name:
  • Gate.h
Aliases:
  • Gate.h
  • Gate.cliff12
Generators:
  • 'X': 127.279
  • 'Z': 127.279
Matrix:
  • 0.71 0.71 0.71 -0.71
(3): Gate.h
Name:
  • Gate.h
Aliases:
  • Gate.h
  • Gate.cliff12
Generators:
  • 'X': 127.279
  • 'Z': 127.279
Matrix:
  • 0.71 0.71 0.71 -0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0, 1): Gate(ZZ)
Name:
  • Gate(ZZ)
Likeness:
  • Non-Clifford
Generators:
  • 'ZZ': 22.0
Matrix:
  • 0.98 -0.19j 0.98 0.19j 0.98 0.19j 0.98 -0.19j
(2, 3): 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
 
1
Marker 1
Compilation tools may only recompile cycles with equal markers.
(0): Meas()
Name:
  • Meas()
(1): Meas()
Name:
  • Meas()
(2): Meas()
Name:
  • Meas()
(3): Meas()
Name:
  • Meas()


We see that the compiled circuit contains only CNOT gates, Z rotations, and X90 rotations. Adjacent single qubit gates have been merged together on each qubit.

compiler3.compile(circuit)
True-Q formatting will not be loaded without trusting this notebook or rerunning the affected cells. Notebooks can be marked as trusted by clicking "File -> Trust Notebook".
Circuit
Key:
  • compiled_pauli: IIIY
  • protocol: RC
  • twirl: Paulis on [0, 1, 2, 3]
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.cliff8
Parameters:
  • phi = -90.0
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
(1): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.cliff8
Parameters:
  • phi = -90.0
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
(2): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.cliff8
Parameters:
  • phi = -90.0
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
(3): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.cliff8
Parameters:
  • phi = -90.0
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(1): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(2): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(3): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = 90.0
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
(1): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = 90.0
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
(2): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.id
  • Gate.i
  • Gate.cliff0
Likeness:
  • Identity
Parameters:
  • phi = 0.0
Generators:
  • 'I': 0
Matrix:
  • 1.00 1.00
(3): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.id
  • Gate.i
  • Gate.cliff0
Likeness:
  • Identity
Parameters:
  • phi = 0.0
Generators:
  • 'I': 0
Matrix:
  • 1.00 1.00
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(1): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(2): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(3): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = -270.0
Generators:
  • 'Z': -270.0
Matrix:
  • -0.71 0.71j -0.71 -0.71j
(1): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = -270.0
Generators:
  • 'Z': -270.0
Matrix:
  • -0.71 0.71j -0.71 -0.71j
(2): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = 90.0
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
(3): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = 90.0
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
2
Marker 2
Compilation tools may only recompile cycles with equal markers.
(0, 1): entangler()
Name:
  • entangler()
Likeness:
  • CNOT
Generators:
  • 'ZX': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71 0.71 0.71j 0.71j 0.71
 
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.z
  • Gate.cliff3
Parameters:
  • phi = -180.0
Generators:
  • 'Z': -180.0
Matrix:
  • 1.00j -1.00j
(1): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.cliff8
Parameters:
  • phi = -90.0
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
(2): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.id
  • Gate.i
  • Gate.cliff0
Likeness:
  • Identity
Parameters:
  • phi = 0.0
Generators:
  • 'I': 0
Matrix:
  • 1.00 1.00
(3): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = 90.0
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(1): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(2): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(3): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 158.0
Generators:
  • 'Z': 158.0
Matrix:
  • 0.19 -0.98j 0.19 0.98j
(1): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.z
  • Gate.cliff3
Parameters:
  • phi = 180.0
Generators:
  • 'Z': 180.0
Matrix:
  • -1.00j 1.00j
(2): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = 90.0
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
(3): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = 90.0
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(1): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(2): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(3): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.z
  • Gate.cliff3
Parameters:
  • phi = -180.0
Generators:
  • 'Z': -180.0
Matrix:
  • 1.00j -1.00j
(1): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = -270.0
Generators:
  • 'Z': -270.0
Matrix:
  • -0.71 0.71j -0.71 -0.71j
(2): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = -270.0
Generators:
  • 'Z': -270.0
Matrix:
  • -0.71 0.71j -0.71 -0.71j
(3): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.cliff8
Parameters:
  • phi = -90.0
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
3
Marker 3
Compilation tools may only recompile cycles with equal markers.
(0, 1): entangler()
Name:
  • entangler()
Likeness:
  • CNOT
Generators:
  • 'ZX': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71 0.71 0.71j 0.71j 0.71
(2, 3): entangler()
Name:
  • entangler()
Likeness:
  • CNOT
Generators:
  • 'ZX': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71 0.71 0.71j 0.71j 0.71
 
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.id
  • Gate.i
  • Gate.cliff0
Likeness:
  • Identity
Parameters:
  • phi = 0.0
Generators:
  • 'I': 0
Matrix:
  • 1.00 1.00
(1): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.id
  • Gate.i
  • Gate.cliff0
Likeness:
  • Identity
Parameters:
  • phi = 0.0
Generators:
  • 'I': 0
Matrix:
  • 1.00 1.00
(2): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.cliff8
Parameters:
  • phi = -90.0
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
(3): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.z
  • Gate.cliff3
Parameters:
  • phi = -180.0
Generators:
  • 'Z': -180.0
Matrix:
  • 1.00j -1.00j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(1): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(2): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(3): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = 90.0
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
(1): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = 90.0
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
(2): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.id
  • Gate.i
  • Gate.cliff0
Likeness:
  • Identity
Parameters:
  • phi = 0.0
Generators:
  • 'I': 0
Matrix:
  • 1.00 1.00
(3): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = 90.0
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(1): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(2): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(3): sx()
Name:
  • sx()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.cliff8
Parameters:
  • phi = -90.0
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
(1): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.cliff8
Parameters:
  • phi = -90.0
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
(2): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.cliff8
Parameters:
  • phi = -90.0
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
(3): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.id
  • Gate.i
  • Gate.cliff0
Likeness:
  • Identity
Parameters:
  • phi = 0.0
Generators:
  • 'I': 0
Matrix:
  • 1.00 1.00
1
Marker 1
Compilation tools may only recompile cycles with equal markers.
(0): Meas()
Name:
  • Meas()
(1): Meas()
Name:
  • Meas()
(2): Meas()
Name:
  • Meas()
(3): Meas()
Name:
  • Meas()


Custom Pass Lists

Custom lists of passes can be used if none of the predifined lists have the desired behaviour. We can pass lists of these classes to from_config() or basic(), as discussed above, or we can use the compiler constructor directly, as in the following example.

First, we define a device configuration. Here, we use the Berkeley gate as the entangling operation.

b = tq.Gate.from_generators("XX", 90, "YY", 45)
config = tq.Config(
    factories=[
        tq.config.GateFactory.from_matrix("B", b),
        tq.config.GateFactory.from_hamiltonian("x90", [["X", 90]]),
        tq.config.GateFactory.from_hamiltonian("z", [["Z", "phi"]]),
    ],
    mode="ZXZXZ",
)

Next, we define a compiler. Unlike, HARDWARE_PASSES, this compiler starts by merging adjacent two-qubit gates. Also, we know that any two qubit gate can be decomposed into two Berkeley gates interleaved with single qubit gates. We use tq.compilation.NativeDecomp fixed at depth=2 to force every two-qubit gate to decompose into two Berkeley gates, even if only one is required.

decomposer = tq.compilation.NativeDecomp(depth=2, factories=config.factories)
compiler = tq.Compiler(
    [
        tq.compilation.Merge(n_labels=2),
        tq.compilation.Parallel(decomposer),
        tq.compilation.Merge(),
        tq.compilation.Native1Q(config.factories),
        tq.compilation.RemoveEmptyCycle(),
    ]
)

Next, we define a circuit to test this compiler on.

circuit = tq.Circuit(
    [
        {range(4): tq.Gate.h},
        {(0, 1): tq.Gate.rp("ZZ", 22)},
        {(0, 1): tq.Gate.cnot, (2, 3): tq.Gate.swap},
    ]
).measure_all()
circuit
True-Q formatting will not be loaded without trusting this notebook or rerunning the affected cells. Notebooks can be marked as trusted by clicking "File -> Trust Notebook".
Circuit
Key:
No key present in circuit.
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): Gate.h
Name:
  • Gate.h
Aliases:
  • Gate.h
  • Gate.cliff12
Generators:
  • 'X': 127.279
  • 'Z': 127.279
Matrix:
  • 0.71 0.71 0.71 -0.71
(1): Gate.h
Name:
  • Gate.h
Aliases:
  • Gate.h
  • Gate.cliff12
Generators:
  • 'X': 127.279
  • 'Z': 127.279
Matrix:
  • 0.71 0.71 0.71 -0.71
(2): Gate.h
Name:
  • Gate.h
Aliases:
  • Gate.h
  • Gate.cliff12
Generators:
  • 'X': 127.279
  • 'Z': 127.279
Matrix:
  • 0.71 0.71 0.71 -0.71
(3): Gate.h
Name:
  • Gate.h
Aliases:
  • Gate.h
  • Gate.cliff12
Generators:
  • 'X': 127.279
  • 'Z': 127.279
Matrix:
  • 0.71 0.71 0.71 -0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0, 1): Gate(ZZ)
Name:
  • Gate(ZZ)
Likeness:
  • Non-Clifford
Generators:
  • 'ZZ': 22.0
Matrix:
  • 0.98 -0.19j 0.98 0.19j 0.98 0.19j 0.98 -0.19j
 
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0, 1): Gate.cx
Name:
  • Gate.cx
Aliases:
  • Gate.cx
  • Gate.cnot
Likeness:
  • CNOT
Generators:
  • 'IX': 90.0
  • 'ZI': 90.0
  • 'ZX': -90.0
Matrix:
  • 1.00 1.00 1.00 1.00
(2, 3): Gate.swap
Name:
  • Gate.swap
Aliases:
  • Gate.swap
Likeness:
  • SWAP
Generators:
  • 'XX': 90.0
  • 'YY': 90.0
  • 'ZZ': 90.0
Matrix:
  • 1.00 1.00 1.00 1.00
 
1
Marker 1
Compilation tools may only recompile cycles with equal markers.
(0): Meas()
Name:
  • Meas()
(1): Meas()
Name:
  • Meas()
(2): Meas()
Name:
  • Meas()
(3): Meas()
Name:
  • Meas()


The resulting compiled circuit is as follows.

compiler.compile(circuit)
True-Q formatting will not be loaded without trusting this notebook or rerunning the affected cells. Notebooks can be marked as trusted by clicking "File -> Trust Notebook".
Circuit
Key:
No key present in circuit.
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -120.926153
Generators:
  • 'Z': -120.926
Matrix:
  • 0.49 0.87j 0.49 -0.87j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 85.620356
Generators:
  • 'Z': 85.62
Matrix:
  • 0.73 -0.68j 0.73 0.68j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -86.659944
Generators:
  • 'Z': -86.66
Matrix:
  • 0.73 0.69j 0.73 -0.69j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -53.538878
Generators:
  • 'Z': -53.539
Matrix:
  • 0.89 0.45j 0.89 -0.45j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(1): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(2): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(3): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 92.588362
Generators:
  • 'Z': 92.588
Matrix:
  • 0.69 -0.72j 0.69 0.72j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 89.999979
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 22.522543
Generators:
  • 'Z': 22.523
Matrix:
  • 0.98 -0.20j 0.98 0.20j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 73.145918
Generators:
  • 'Z': 73.146
Matrix:
  • 0.80 -0.60j 0.80 0.60j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(1): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(2): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(3): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -141.703558
Generators:
  • 'Z': -141.704
Matrix:
  • 0.33 0.94j 0.33 -0.94j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -90.000161
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -99.949451
Generators:
  • 'Z': -99.949
Matrix:
  • 0.64 0.77j 0.64 -0.77j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -101.776661
Generators:
  • 'Z': -101.777
Matrix:
  • 0.63 0.78j 0.63 -0.78j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0, 1): B()
Name:
  • B()
Likeness:
  • Non-Clifford
Generators:
  • 'XX': 90.0
  • 'YY': 45.0
Matrix:
  • 0.92 -0.38j 0.38 -0.92j -0.92j 0.38 -0.38j 0.92
(2, 3): B()
Name:
  • B()
Likeness:
  • Non-Clifford
Generators:
  • 'XX': 90.0
  • 'YY': 45.0
Matrix:
  • 0.92 -0.38j 0.38 -0.92j -0.92j 0.38 -0.38j 0.92
 
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -269.999865
Generators:
  • 'Z': -270.0
Matrix:
  • -0.71 0.71j -0.71 -0.71j
(1): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.cliff8
Parameters:
  • phi = -90.0
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -180.00008
Generators:
  • 'Z': -180.0
Matrix:
  • 1.00j -1.00j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -9.2e-05
Generators:
  • 'Z': -0.0
Matrix:
  • 1.00 1.00
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(1): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(2): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(3): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 133.442125
Generators:
  • 'Z': 133.442
Matrix:
  • 0.40 -0.92j 0.40 0.92j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 179.999968
Generators:
  • 'Z': 180.0
Matrix:
  • -1.00j 1.00j
(2): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = 90.0
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
(3): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Parameters:
  • phi = 90.0
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(1): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(2): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(3): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -269.999865
Generators:
  • 'Z': -270.0
Matrix:
  • -0.71 0.71j -0.71 -0.71j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -136.557875
Generators:
  • 'Z': -136.558
Matrix:
  • 0.37 0.93j 0.37 -0.93j
(2): z(phi)
Name:
  • z(phi)
Aliases:
  • Gate.id
  • Gate.i
  • Gate.cliff0
Parameters:
  • phi = -0.0
Generators:
  • 'Z': -0.0
Matrix:
  • 1.00 1.00
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -180.000001
Generators:
  • 'Z': -180.0
Matrix:
  • 1.00j -1.00j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0, 1): B()
Name:
  • B()
Likeness:
  • Non-Clifford
Generators:
  • 'XX': 90.0
  • 'YY': 45.0
Matrix:
  • 0.92 -0.38j 0.38 -0.92j -0.92j 0.38 -0.38j 0.92
(2, 3): B()
Name:
  • B()
Likeness:
  • Non-Clifford
Generators:
  • 'XX': 90.0
  • 'YY': 45.0
Matrix:
  • 0.92 -0.38j 0.38 -0.92j -0.92j 0.38 -0.38j 0.92
 
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -53.25336
Generators:
  • 'Z': -53.253
Matrix:
  • 0.89 0.45j 0.89 -0.45j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -179.999865
Generators:
  • 'Z': -180.0
Matrix:
  • 1.00j -1.00j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -30.335437
Generators:
  • 'Z': -30.335
Matrix:
  • 0.97 0.26j 0.97 -0.26j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -95.652094
Generators:
  • 'Z': -95.652
Matrix:
  • 0.67 0.74j 0.67 -0.74j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(1): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(2): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(3): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 59.108862
Generators:
  • 'Z': 59.109
Matrix:
  • 0.87 -0.49j 0.87 0.49j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 175.620356
Generators:
  • 'Z': 175.62
Matrix:
  • 0.04 -1.00j 0.04 1.00j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 138.778216
Generators:
  • 'Z': 138.778
Matrix:
  • 0.35 -0.94j 0.35 0.94j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 13.096829
Generators:
  • 'Z': 13.097
Matrix:
  • 0.99 -0.11j 0.99 0.11j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(1): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(2): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(3): x90()
Name:
  • x90()
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 23.990098
Generators:
  • 'Z': 23.99
Matrix:
  • 0.98 -0.21j 0.98 0.21j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -68.000327
Generators:
  • 'Z': -68.0
Matrix:
  • 0.83 0.56j 0.83 -0.56j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -252.75748
Generators:
  • 'Z': -252.757
Matrix:
  • -0.59 0.81j -0.59 -0.81j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -73.017893
Generators:
  • 'Z': -73.018
Matrix:
  • 0.80 0.59j 0.80 -0.59j
1
Marker 1
Compilation tools may only recompile cycles with equal markers.
(0): Meas()
Name:
  • Meas()
(1): Meas()
Name:
  • Meas()
(2): Meas()
Name:
  • Meas()
(3): Meas()
Name:
  • Meas()


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

Gallery generated by Sphinx-Gallery