Dela via


ApplyUnitary operation

Fully qualified name: Std.Intrinsic.ApplyUnitary

operation ApplyUnitary(matrix : Complex[][], qubits : Qubit[]) : Unit

Summary

Applies the given unitary matrix to the given qubits. The matrix is checked at runtime to ensure it's shape is square and that the matrix dimensions are 2 ^ Length(qubits). This operation is simulator-only and is not supported on hardware.

Input

matrix

The unitary matrix to apply.

qubits

The qubits to which the unitary matrix should be applied.

Example

This performs a two qubit CNOT using the unitary matrix representation:

import Std.Math.Complex;
use qs = Qubit[2];
let one = new Complex { Real = 1.0, Imag = 0.0 };
let zero = new Complex { Real = 0.0, Imag = 0.0 };
ApplyUnitary(
    [
        [one, zero, zero, zero],
        [zero, one, zero, zero],
        [zero, zero, zero, one],
        [zero, zero, one, zero]
    ],
    qs
);