# Unitary Gate¶

Given a $$2^{n}\times2^{n}$$ unitary matrix, the unitary-gate function constructs an equivalent unitary gate which acts on $$n$$ qubits accordingly. For $$n>2$$, the synthesis process implementation is based on [1].

## Syntax¶

Function: UnitaryGate

Parameters:

• data: DataArray
{
"function": "UnitaryGate",
"function_params": {
"data": [
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, "-1j", 0],
[0, 0, 0, "1j"]
]
}
}


## Example¶

The following example shows a $$2$$-qubit unitary gate generated from a series of arbitrary $$2$$-rotations in the formed $$4$$ dimensional space. The SDK code includes the construction of the matrix using NumPy functions, while the textual model is created by feeding the explicit numerical values.

{
"logic_flow": [
{
"function": "UnitaryGate",
"function_params": {
"data": [
[
"(-0.437588928003977-0.22742705999986979j)",
"(0.5162471759231342+0.5412974930115615j)",
"(-0.0257562186040025-0.09612351644098814j)",
"(0.11352149651283158+0.41771820225920475j)"
],
[
"(-0.4657883653698742-0.4426774493996494j)",
"(-0.3564263367893152-0.37953725275954014j)",
"(-2.7383934913210134e-17+0.447213595499958j)",
"(0.24082111067114909+0.2408211106711492j)"
],
[
"(0.276003031585611-0.227055039284318j)",
"(0.24522446154306524-0.17374499218631134j)",
"(0.8720020339202011+0j)",
"(0.08819092511956897+0.11739161131796567j)"
],
[
"(0.08990251208306779-0.4561322296873242j)",
"(0.1573622060431408+0.23305019820160192j)",
"(-0.08618198713953264+0.14927158042291808j)",
"(0.38451638587720915-0.7261015617334183j)"
]
]
}
}
]
}

import numpy as np
from classiq import ModelDesigner
from classiq.builtin_functions import UnitaryGate

num_gate_qubits = 2
thetas = [np.pi / 3, np.pi / 7, np.arccos(3 / 5), 0.2, np.pi / 4, np.pi / 2]
phis = [np.pi / 4, np.pi / 3, np.pi / 2, np.pi / 5, np.pi / 4, np.pi / 3]
pairs = [[0, 3], [3, 2], [1, 2], [0, 1], [1, 3], [0, 1]]
gate_matrix = np.identity(2**num_gate_qubits, dtype=complex)
for theta, phi, index in zip(thetas, phis, pairs):
data_next = np.identity(2**num_gate_qubits, dtype=complex)
data_next[index[0], index[0]] = 0
data_next[index[1], index[1]] = 0
data_next[np.ix_(index, index)] = [
[
np.exp(-1j * phi) * np.cos(theta / 2),
-np.exp(-1j * phi) * np.sin(theta / 2),
],
[np.sin(theta / 2), np.cos(theta / 2)],
]
gate_matrix = np.dot(gate_matrix, data_next)
gate_matrix = gate_matrix.tolist()

model_designer = ModelDesigner()
unitary_gate_params = UnitaryGate(data=gate_matrix)
model_designer.UnitaryGate(unitary_gate_params)

circuit = model_designer.synthesize()
circuit.show_interactive()


The figure below shows the constituents of the gate.

## References¶

[1] R. Iten et al, Quantum Circuits for Isometries ,Phys. Rev. A 93 (2016). https://link.aps.org/doi/10.1103/PhysRevA.93.032318