Gate synthesis

This example demonstrates how the built-in compiler can be used to perform gate synthesis.

Synthesizing Single-Qubit Gates

We begin by generating a random gate in \(SU(2)\); we will synthesize this gate later.

import trueq as tq

# create a Haar random SU(2) gate and print its matrix representation
U = tq.Gate.random(2)
U
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".
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': -63.034
  • 'Y': 97.594
  • 'Z': -57.02
Matrix:
  • -0.54 0.22j -0.12 -0.80j -0.68 0.44j 0.19 0.55j


We can perform single qubit gate decomposition into a number of possible “modes”. Here we decompose the gate U into a ZXZXZ decomposition, which is short hand for \(Z(\theta)X(90)Z(\phi)X(90)Z(\gamma)\). See QubitMode for a complete list of all available single qubit decompositions.

synthesized_gate = tq.math.QubitMode.ZXZXZ.decompose(U)

# print the synthesized gate as a list of single-qubit rotations about Z and X
synthesized_gate

Out:

[('Z', -255.85556169048886), ('X', 90), ('Z', 71.48170671058352), ('X', 90), ('Z', -10.140729289456758)]

Synthesizing Two-Qubit Gates

In the event that we want to express a two-qubit gate in terms of a different two-qubit gate, we can use the compiler to synthesize the desired gate. Here we decompose a random \(SU(4)\) operation so that it can be implemented using iSWAP gates.

# define the gate to be synthesized
gate_to_be_synthesized = tq.Gate.random(4)

# re-express the gate using an iswap gate as the two-qubit gate
two_qubit_synthesized_gate = tq.math.decompose_unitary(
    target_gate=gate_to_be_synthesized, given_gate=tq.Gate.iswap
)

# print the synthesized gate
two_qubit_synthesized_gate
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(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': 5.583
  • 'Y': -193.978
  • 'Z': -118.539
Matrix:
  • -0.42 0.46j 0.78 0.01j -0.78 -0.06j -0.38 -0.50j
(1): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': -63.256
  • 'Y': -120.704
  • 'Z': 21.562
Matrix:
  • 0.23 -0.31j 0.92 -0.05j -0.48 0.79j 0.38 -0.06j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0, 1): Gate.iswap
Name:
  • Gate.iswap
Aliases:
  • Gate.iswap
Likeness:
  • iSWAP
Generators:
  • 'XX': -90.0
  • 'YY': -90.0
Matrix:
  • 1.00 1.00j 1.00j 1.00
 
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': -113.722
  • 'Y': 108.264
  • 'Z': -62.821
Matrix:
  • -0.18 0.34j -0.92 0.07j 0.02 0.92j 0.32 -0.21j
(1): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': -59.313
  • 'Y': -138.8
  • 'Z': 240.36
Matrix:
  • -0.46 -0.83j 0.21 0.25j -0.33 -0.02j -0.94 0.10j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0, 1): Gate.iswap
Name:
  • Gate.iswap
Aliases:
  • Gate.iswap
Likeness:
  • iSWAP
Generators:
  • 'XX': -90.0
  • 'YY': -90.0
Matrix:
  • 1.00 1.00j 1.00j 1.00
 
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': 176.879
  • 'Y': 79.649
  • 'Z': -73.893
Matrix:
  • 0.42j -0.78 -0.47j -0.16 -0.89j -0.39 -0.15j
(1): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': 84.818
  • 'Y': 64.317
  • 'Z': 85.686
Matrix:
  • -0.49 -0.48j -0.66 0.31j -0.47 -0.55j 0.65 -0.24j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0, 1): Gate.iswap
Name:
  • Gate.iswap
Aliases:
  • Gate.iswap
Likeness:
  • iSWAP
Generators:
  • 'XX': -90.0
  • 'YY': -90.0
Matrix:
  • 1.00 1.00j 1.00j 1.00
 
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': -31.316
  • 'Y': 62.945
  • 'Z': 183.173
Matrix:
  • -0.62 -0.70j -0.18 0.31j 0.35 -0.04j 0.38 0.85j
(1): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': 141.807
  • 'Y': 69.823
  • 'Z': 145.879
Matrix:
  • -0.63 -0.33j -0.63 -0.31j -0.13 -0.69j 0.15 0.70j


This circuit can be verified to reproduce the original random unitary using an ideal simulator:

matrix = tq.Simulator().operator(two_qubit_synthesized_gate).mat()

# This will result in an identity gate up to a global complex phase.
tq.visualization.plot_mat(matrix @ gate_to_be_synthesized.adj.mat)
synthesis

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

Gallery generated by Sphinx-Gallery