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': -60.796
  • 'Y': -93.612
  • 'Z': -85.714
Matrix:
  • 0.64 0.17j 0.73 -0.16j -0.15 0.73j -0.17 -0.64j


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', -26.640003407051253), ('X', 90), ('Z', 83.33316115122174), ('X', 90), ('Z', 87.35654315874936)]

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_su4(
    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.
   
 
(0): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': -8.84
  • 'Y': -43.98
  • 'Z': 244.873
Matrix:
  • -0.67 -0.73j 0.15 0.01j -0.14 0.05j -0.46 0.88j
(1): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': -48.891
  • 'Y': 21.343
  • 'Z': -74.887
Matrix:
  • 0.91 -0.04j 0.13 0.39j 0.38 0.17j 0.12 -0.90j
imm
(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
 
 
(0): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': -73.115
  • 'Y': -131.157
  • 'Z': 33.295
Matrix:
  • 0.31 -0.03j 0.38 0.87j -0.94 -0.14j 0.05 0.31j
(1): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': -16.65
  • 'Y': 152.174
  • 'Z': -58.631
Matrix:
  • -0.23 0.30j -0.56 -0.74j 0.39 0.84j 0.38 -0.06j
imm
(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
 
 
(0): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': -221.838
  • 'Y': 13.629
  • 'Z': -15.376
Matrix:
  • -0.21 0.30j 0.62 0.70j 0.70 0.61j -0.30 0.21j
(1): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': 78.269
  • 'Y': 58.722
  • 'Z': -20.691
Matrix:
  • 0.39 0.54j 0.04 -0.75j 0.73 -0.17j 0.59 0.29j
imm
(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
 
 
(0): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': -78.695
  • 'Y': -12.14
  • 'Z': 134.743
Matrix:
  • 0.54 -0.68j -0.14 0.48j -0.28 0.41j -0.17 0.85j
(1): Gate(X, Y, ...)
Name:
  • Gate(X, Y, ...)
Generators:
  • 'X': -122.744
  • 'Y': -61.534
  • 'Z': -18.42
Matrix:
  • 0.30 0.22j 0.16 0.91j -0.64 0.67j 0.37 -0.02j


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.070 seconds)

Gallery generated by Sphinx-Gallery