Skip to content

Unitary Function

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

Function: unitary


  • elements: CArray[CArray[CReal]] - A 2d array of complex numbers representing the unitary matrix.
  • target: QArray[QBit] - The quantum state to apply the unitary on. Should be of corresponding size.


This example shows a \(2\)-qubit unitary function application in the formed \(4\)-dimensional space.

from classiq import Output, QArray, QBit, allocate, create_model, qfunc, unitary

UNITARY = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, -1j, 0], [0, 0, 0, 1j]]

def main(x: Output[QArray[QBit]]):
    allocate(2, x)
    unitary(UNITARY, x)

qmod = create_model(main)
from classiq import synthesize, write_qmod

write_qmod(qmod, "unitary")
qprog = synthesize(qmod)


[1] R. Iten et al, Quantum Circuits for Isometries, Phys. Rev. A 93 (2016).