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': 100.341
  • 'X': -129.067
  • 'Z': -24.005
Matrix:
  • 0.08 0.18j -0.81 0.55j 0.33 0.92j 0.17 -0.10j

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', 79.58855658027758),
 ('X', 90),
 ('Z', 22.26079950862166),
 ('X', 90),
 ('Z', 3.863045721614313)]

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': -121.294
  • 'X': -116.259
  • 'Z': 51.663
Matrix:
  • -0.26 -0.15j 0.88 -0.37j 0.33 0.89j 0.28 0.08j
(1): Gate(Y, X, ...)
Name:
  • Gate(Y, X, ...)
Generators:
  • 'Y': -160.54
  • 'X': 37.359
  • 'Z': -104.788
Matrix:
  • 0.12 0.53j 0.64 -0.54j -0.81 0.20j -0.36 -0.41j
 
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': 37.385
  • 'X': 74.107
  • 'Z': 92.372
Matrix:
  • 0.54 0.60j 0.57 -0.15j 0.46 0.37j -0.74 0.32j
(1): Gate(Y, X, ...)
Name:
  • Gate(Y, X, ...)
Generators:
  • 'Y': 27.658
  • 'X': -22.209
  • 'Z': -44.033
Matrix:
  • -0.40 -0.87j 0.30 0.02j -0.04 -0.29j -0.90 -0.33j
 
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': 6.604
  • 'X': 28.894
  • 'Z': -134.88
Matrix:
  • 0.86 -0.47j -0.19 0.07j -0.20 -0.02j -0.95 -0.24j
(1): Gate(Y, X, ...)
Name:
  • Gate(Y, X, ...)
Generators:
  • 'Y': 127.755
  • 'X': -2.436
  • 'Z': 123.108
Matrix:
  • -0.68 -0.12j -0.08 0.72j 0.11 -0.71j 0.69 0.07j
 
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': -61.493
  • 'X': -18.753
  • 'Z': 210.802
Matrix:
  • 0.54 -0.80j 0.08 0.26j -0.22 -0.17j -0.93 0.23j
(1): Gate(Y, X, ...)
Name:
  • Gate(Y, X, ...)
Generators:
  • 'Y': 27.753
  • 'X': 73.269
  • 'Z': 177.858
Matrix:
  • 0.73 -0.56j 0.25 -0.31j 0.40 -0.06j -0.85 0.34j

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.