Download

Download this file as Jupyter notebook: synthesis.ipynb.

Example: 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.

[2]:
import trueq as tq

# create a Haar random SU(2) gate and print its matrix representation
U = tq.Gate.random(2)
U
[2]:
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(Y, X, ...)
Generators:
  • 'Y': 86.208
  • 'X': 21.93
  • 'Z': -160.518
Matrix:
  • 0.81 0.34j -0.28 0.40j 0.05 -0.48j -0.83 -0.28j

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.

[3]:
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
[3]:
[('Z', -257.7385690112652),
 ('X', 90),
 ('Z', 122.042638725902),
 ('X', 90),
 ('Z', -106.283141468562)]

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.

[4]:
# 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
[4]:
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(Y, X, ...)
Name:
  • Gate(Y, X, ...)
Generators:
  • 'Y': -30.76
  • 'X': 167.589
  • 'Z': 74.986
Matrix:
  • -0.18 -0.36j -0.14 -0.90j -0.46 -0.79j 0.08 0.40j
(1): Gate(Y, X, ...)
Name:
  • Gate(Y, X, ...)
Generators:
  • 'Y': -81.07
  • 'X': 50.75
  • 'Z': -33.329
Matrix:
  • 0.51 -0.46j -0.08 -0.73j -0.62 0.39j 0.05 -0.68j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0, 1): Gate.iswap
Name:
  • Gate.iswap
Aliases:
  • Gate.iswap
Likeness:
  • iSWAP
Generators:
  • 'YY': -90.0
  • 'XX': -90.0
Matrix:
  • 1.00 1.00j 1.00j 1.00
 
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): Gate(Y, X, ...)
Name:
  • Gate(Y, X, ...)
Generators:
  • 'Y': 67.651
  • 'X': 34.193
  • 'Z': 33.037
Matrix:
  • -0.60 -0.53j 0.02 0.61j -0.50 -0.34j -0.13 -0.78j
(1): Gate(Y, X, ...)
Name:
  • Gate(Y, X, ...)
Generators:
  • 'Y': 0.889
  • 'X': 43.484
  • 'Z': -83.916
Matrix:
  • 0.17 -0.93j -0.28 0.19j -0.29 0.18j -0.92 -0.21j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0, 1): Gate.iswap
Name:
  • Gate.iswap
Aliases:
  • Gate.iswap
Likeness:
  • iSWAP
Generators:
  • 'YY': -90.0
  • 'XX': -90.0
Matrix:
  • 1.00 1.00j 1.00j 1.00
 
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): Gate(Y, X, ...)
Name:
  • Gate(Y, X, ...)
Generators:
  • 'Y': 18.218
  • 'X': 96.185
  • 'Z': -139.688
Matrix:
  • -0.81 0.10j 0.56 -0.12j 0.56 0.10j 0.82 0.07j
(1): Gate(Y, X, ...)
Name:
  • Gate(Y, X, ...)
Generators:
  • 'Y': -139.535
  • 'X': -64.795
  • 'Z': 30.824
Matrix:
  • 0.04 -0.27j 0.94 -0.21j -0.44 0.85j 0.28 0.03j
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0, 1): Gate.iswap
Name:
  • Gate.iswap
Aliases:
  • Gate.iswap
Likeness:
  • iSWAP
Generators:
  • 'YY': -90.0
  • 'XX': -90.0
Matrix:
  • 1.00 1.00j 1.00j 1.00
 
 
Marker 0
Compilation tools may only recompile cycles with equal markers.
(0): Gate(Y, X, ...)
Name:
  • Gate(Y, X, ...)
Generators:
  • 'Y': -135.41
  • 'X': 56.091
  • 'Z': -64.089
Matrix:
  • 0.39 0.18j 0.39 -0.81j -0.85 0.30j -0.13 -0.41j
(1): Gate(Y, X, ...)
Name:
  • Gate(Y, X, ...)
Generators:
  • 'Y': -39.749
  • 'X': -23.555
  • 'Z': 0.606
Matrix:
  • -0.28 0.87j -0.30 0.26j -0.08 -0.38j -0.29 0.87j

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

[5]:
matrix = tq.Simulator().operator(two_qubit_synthesized_gate).mat()

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

Download

Download this file as Jupyter notebook: synthesis.ipynb.