Gate synthesis

import trueq as tq
import scipy as sp

# Create a random SU(2) gate and print its matrix representation.
U = tq.Gate(sp.stats.unitary_group.rvs(2))
U
  • Name:

    • Gate(X, Y, ...)
  • Generators:

    • 'X': -123.052
    • 'Y': 57.519
    • 'Z': -191.035
  • Matrix:



# Load config file and store the mode.
config = tq.Config("config.yaml")
config_mode = config.mode

# Perform synthesis.
synthesized_gate = tq.math.decomposition.QubitMode[config.mode].decompose(U)

# Print the synthesized gate as a list of single qubit rotations about Z and X.
print(synthesized_gate)

Out:

[('Z', -7.18354461946025), ('X', 90), ('Z', 117.9524503860201), ('X', 90), ('Z', -57.29001599556931)]
# Additionally, two qubit gates can be converted from one to another.
# Here we decompose a random SU(4) operation so that it can be implemented
# using iswap gates.
two_qubit_synthesized_gate = tq.math.decompose_su4(
    target_gate=tq.Gate(sp.stats.unitary_group.rvs(4)), given_gate=tq.Gate.iswap
)

# Print the two-qubit synthesized gate.
print(two_qubit_synthesized_gate)

Out:

trueq.Circuit
     (0,): Gate(X, Y, ...)                     (1,): Gate(X, Y, ...)
Imm  (0, 1): Gate.iswap
     (0,): Gate(X, Y, ...)                     (1,): Gate(X, Y, ...)
Imm  (0, 1): Gate.iswap
     (0,): Gate(X, Y, ...)                     (1,): Gate(X, Y, ...)
Imm  (0, 1): Gate.iswap
     (0,): Gate(X, Y, ...)                     (1,): Gate(X, Y, ...)

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

Gallery generated by Sphinx-Gallery