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: IIZZ
  • 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 = 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.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.z
  • Gate.cliff3
Parameters:
  • phi = -180.0
Generators:
  • 'Z': -180.0
Matrix:
  • 1.00j -1.00j
(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 = 22.0
Generators:
  • 'Z': 22.0
Matrix:
  • 0.98 -0.19j 0.98 0.19j
(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 = 90.0
Generators:
  • 'Z': 90.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.z
  • Gate.cliff3
Parameters:
  • phi = -180.0
Generators:
  • 'Z': -180.0
Matrix:
  • 1.00j -1.00j
(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
 
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.z
  • Gate.cliff3
Parameters:
  • phi = 180.0
Generators:
  • 'Z': 180.0
Matrix:
  • -1.00j 1.00j
(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.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.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.z
  • Gate.cliff3
Parameters:
  • phi = -180.0
Generators:
  • 'Z': -180.0
Matrix:
  • 1.00j -1.00j
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.Native2QFastDecomp 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.Native2QFastDecomp(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(),
    ]
)

Out:

Warning: Native2QFastDecomp() was deprecated in version 2.9.0 and will be removed no earlier than version 2.10.0. The more general `NativeDecomp` pass can be used as a drop in replacement.
         (/home/user/jenkins/workspace/release trueq/trueq/utils.py:153)

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 = 15.615353
Generators:
  • 'Z': 15.615
Matrix:
  • 0.99 -0.14j 0.99 0.14j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -219.110608
Generators:
  • 'Z': -219.111
Matrix:
  • -0.33 0.94j -0.33 -0.94j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -257.828488
Generators:
  • 'Z': -257.828
Matrix:
  • -0.63 0.78j -0.63 -0.78j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -7.848134
Generators:
  • 'Z': -7.848
Matrix:
  • 1.00 0.07j 1.00 -0.07j
 
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 = 43.696965
Generators:
  • 'Z': 43.697
Matrix:
  • 0.93 -0.37j 0.93 0.37j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 89.999917
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 158.389675
Generators:
  • 'Z': 158.39
Matrix:
  • 0.19 -0.98j 0.19 0.98j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 47.873475
Generators:
  • 'Z': 47.873
Matrix:
  • 0.91 -0.41j 0.91 0.41j
 
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 = -131.894809
Generators:
  • 'Z': -131.895
Matrix:
  • 0.41 0.91j 0.41 -0.91j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -89.999994
Generators:
  • 'Z': -90.0
Matrix:
  • 0.71 0.71j 0.71 -0.71j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -76.626333
Generators:
  • 'Z': -76.626
Matrix:
  • 0.78 0.62j 0.78 -0.62j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 2.556621
Generators:
  • 'Z': 2.557
Matrix:
  • 1.00 -0.02j 1.00 0.02j
 
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 = 89.999993
Generators:
  • 'Z': 90.0
Matrix:
  • 0.71 -0.71j 0.71 0.71j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -234.89495
Generators:
  • 'Z': -234.895
Matrix:
  • -0.46 0.89j -0.46 -0.89j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -180.000062
Generators:
  • 'Z': -180.0
Matrix:
  • 1.00j -1.00j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 5.9e-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 = 70.2101
Generators:
  • 'Z': 70.21
Matrix:
  • 0.82 -0.58j 0.82 0.58j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 179.999856
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.999993
Generators:
  • 'Z': -270.0
Matrix:
  • -0.71 0.71j -0.71 -0.71j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -54.894949
Generators:
  • 'Z': -54.895
Matrix:
  • 0.89 0.46j 0.89 -0.46j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 1.5e-05
Generators:
  • 'Z': 0.0
Matrix:
  • 1.00 1.00
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -179.99997
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 = -153.029976
Generators:
  • 'Z': -153.03
Matrix:
  • 0.23 0.97j 0.23 -0.97j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -179.999908
Generators:
  • 'Z': -180.0
Matrix:
  • 1.00j -1.00j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 12.7353
Generators:
  • 'Z': 12.735
Matrix:
  • 0.99 -0.11j 0.99 0.11j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -79.446867
Generators:
  • 'Z': -79.447
Matrix:
  • 0.77 0.64j 0.77 -0.64j
 
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 = 131.708828
Generators:
  • 'Z': 131.709
Matrix:
  • 0.41 -0.91j 0.41 0.91j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 50.889392
Generators:
  • 'Z': 50.889
Matrix:
  • 0.90 -0.43j 0.90 0.43j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 131.127362
Generators:
  • 'Z': 131.127
Matrix:
  • 0.41 -0.91j 0.41 0.91j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = 154.914088
Generators:
  • 'Z': 154.914
Matrix:
  • 0.22 -0.98j 0.22 0.98j
 
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 = -51.833425
Generators:
  • 'Z': -51.833
Matrix:
  • 0.90 0.44j 0.90 -0.44j
(1): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -67.999839
Generators:
  • 'Z': -68.0
Matrix:
  • 0.83 0.56j 0.83 -0.56j
(2): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -10.37782
Generators:
  • 'Z': -10.378
Matrix:
  • 1.00 0.09j 1.00 -0.09j
(3): z(phi)
Name:
  • z(phi)
Parameters:
  • phi = -258.409084
Generators:
  • 'Z': -258.409
Matrix:
  • -0.63 0.77j -0.63 -0.77j
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.145 seconds)

Gallery generated by Sphinx-Gallery