This module implements many common types of quantum gates (and some other useful linear maps). The returned gates are represented as sparse lmap instances. The data type is float unless complex entries are actually needed.
dist(A, B) | Distance between two unitary lmaps. |
id(dim) | Identity gate. |
phase(theta[, dim]) | Diagonal phase shift gate. |
qft(*args) | Quantum Fourier transform gate. |
swap(d1, d2) | Swap gate. |
walsh(n) | Walsh-Hadamard gate. |
mod_inc(x, dim[, N]) | Modular incrementation gate. |
mod_mul(x, dim[, N]) | Modular multiplication gate. |
mod_add(dim1, dim2[, N]) | Modular adder gate. |
controlled(U[, ctrl, dim]) | Controlled gate. |
single(L, t, d_in) | Single-qudit operator. |
two(B, t, d_in) | Two-qudit operator. |
Distance between two unitary lmaps.
Returns
Identity gate.
Returns the identity gate I for the specified system. dim is a tuple of subsystem dimensions.
Diagonal phase shift gate.
Returns the (diagonal) phase shift gate U = diag(exp(i*theta)).
Quantum Fourier transform gate.
Returns the quantum Fourier transform gate for the specified system. dim is a vector of subsystem dimensions. The returned lmap is dense.
Swap gate.
Returns the swap gate which swaps the order of two subsystems with dimensions [d1, d2].
Walsh-Hadamard gate.
Returns the Walsh-Hadamard gate for n qubits. The returned lmap is dense.
Modular adder gate.
Returns the gate U, which, operating on the computational state , produces . dim1 and dim2 are the control and target register dimension vectors.
By default N == prod(dim2). If N is explicitly given we must have N <= prod(dim2), and U will act trivially on target states >= N.
Notes: The modular subtractor gate can be obtained by taking the Hermitian conjugate of mod_add. mod_add(2, 2) is equal to CNOT.
Modular incrementation gate.
U = mod_inc(x, dim) N == prod(dim) U = mod_inc(x, dim, N) gate dimension prod(dim) must be >= N
Returns the gate U, which, operating on the computational state , increments it by x (mod N): .
If N is given, U will act trivially on computational states >= N.
Modular multiplication gate.
U = mod_mul(x, dim) N == prod(dim) U = mod_mul(x, dim, N) gate dimension prod(dim) must be >= N
Returns the gate U, which, operating on the computational state , multiplies it by x (mod N): . x and N must be coprime for the operation to be reversible.
If N is given, U will act trivially on computational states >= N.
Controlled gate.
Returns the (t+1)-qudit controlled-U gate, where t == length(ctrl). U has to be a square matrix.
ctrl is an integer vector defining the control nodes. It has one entry k per control qudit, denoting the required computational basis state for that particular qudit. Value k == -1 denotes no control.
dim is the dimensions vector for the control qudits. If not given, all controls are assumed to be qubits.
Examples:
controlled(NOT, [1]) gives the standard CNOT gate.
controlled(NOT, [1, 1]) gives the Toffoli gate.
Single-qudit operator.
Returns the operator U corresponding to the local operator L applied to subsystem t (and identity applied to the remaining subsystems).
d_in is the input dimension vector for U.
Two-qudit operator.
Returns the operator U corresponding to the bipartite operator B applied to subsystems t == [t1, t2] (and identity applied to the remaining subsystems).
d_in is the input dimension vector for U.