ApplyUnitary operation
Warning
This documentation refers to the Classic QDK, which has been replaced by the Modern QDK.
Please see https://aka.ms/qdk.api for the API documentation for the Modern QDK.
Namespace: Microsoft.Quantum.Synthesis
Package: Microsoft.Quantum.Standard
Applies gate defined by a 2ⁿ × 2ⁿ unitary matrix.
Fails if matrix is not unitary, or has wrong size.
operation ApplyUnitary (unitary : Microsoft.Quantum.Math.Complex[][], qubits : Microsoft.Quantum.Arithmetic.LittleEndian) : Unit is Adj + Ctl
Input
unitary : Complex[][]
A $2^n \times 2^n$ unitary matrix describing the operation. If the matrix is not unitary or not of suitable size, throws an exception.
qubits : LittleEndian
Qubits to which apply the operation - a little-endian register of length n.
Output : Unit
Example
The following operation will be equivalent to applying the Hadamard gate to the given qubit:
open Microsoft.Quantum.Arithmetic;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Synthesis;
operation ApplyH (register : LittleEndian) : Unit is Adj + Ctl {
let matrix = [[Complex(Sqrt(0.5), 0.0), Complex(Sqrt(0.5), 0.0)],
[Complex(Sqrt(0.5), 0.0), Complex(-Sqrt(0.5), 0.0)]];
ApplyUnitary(matrix, register);
}
Note that this way of applying the Hadamard gate is more expensive than calling the gate directly. We recommend to use this operation only for unitaries that are not implemented as primitive gates.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for