Operators

Usage

The examples of this page use qubits on a six site system, that is

using TensorMixedStates, .Qubits, .Circuits

n = 6
j = 1.0
h = 0.5

There are two kinds of operators: generic (like X) and indexed (like X(3)). Indexed operators are applied to specific site numbers.

Operators define Hamiltonians, for example

hamiltonian = - j * sum(X(i)X(i+1) + Y(i)Y(i+1) for i in 1:n-1) - h * sum(Z(i) for i in 1:n)
-X(1)*X(2)-Y(1)*Y(2)-X(2)*X(3)-Y(2)*Y(3)-X(3)*X(4)-Y(3)*Y(4)-X(4)*X(5)-Y(4)*Y(5)-X(5)*X(6)-Y(5)*Y(6)-0.5Z(1)-0.5Z(2)-0.5Z(3)-0.5Z(4)-0.5Z(5)-0.5Z(6)

or Lindbladian dissipators like

dissipators = sum(Dissipator(Sp)(i) for i in 1:n)
Dissipator(Sp)(1)+Dissipator(Sp)(2)+Dissipator(Sp)(3)+Dissipator(Sp)(4)+Dissipator(Sp)(5)+Dissipator(Sp)(6)

to build a Lindbladian

lindbladian = -im * hamiltonian + dissipators
Evolver(im*X(1)*X(2)+im*Y(1)*Y(2)+im*X(2)*X(3)+im*Y(2)*Y(3)+im*X(3)*X(4)+im*Y(3)*Y(4)+im*X(4)*X(5)+im*Y(4)*Y(5)+im*X(5)*X(6)+im*Y(5)*Y(6)+0.5im*Z(1)+0.5im*Z(2)+0.5im*Z(3)+0.5im*Z(4)+0.5im*Z(5)+0.5im*Z(6))+Dissipator(Sp)(1)+Dissipator(Sp)(2)+Dissipator(Sp)(3)+Dissipator(Sp)(4)+Dissipator(Sp)(5)+Dissipator(Sp)(6)

Note the factor -im for the Hamiltonian.

They define quantum gates, the module Circuits giving H, the rotations and the controlled gates, like

gates = H(1)Swap(1, 2)H(1)
H(1)*Swap(1,2)*H(1)

Noisy gates can be defined using the Gate constructor, for example

noisygate = 0.7Gate(Id) + 0.1Gate(X) + 0.1Gate(Y) + 0.1Gate(Z)
0.7Gate(Id)+0.1Gate(X)+0.1Gate(Y)+0.1Gate(Z)

The reset of sites of any type to a state is the channel reset_channel, and its Lindblad generator, for an evolver, reset_dissipator; to the fully mixed state, it is the depolarization, depolarizing_channel and depolarizing_dissipator. The dephasing channel and its generator are dephasing_channel and dephasing_dissipator, built on Dephase, and the decay of the excitations an operator destroys, amplitude_damping_channel and amplitude_damping_dissipator.

Two conventions differ from one text to another. depolarizing_channel(p) replaces the state of a site by the fully mixed one with probability p, $(1 - p)\rho + p\,I/d$: on a qubit, the channel $(1 - p)\rho + \frac{p}{3}(X \rho X + Y \rho Y + Z \rho Z)$, which applies each Pauli operator with probability $p/3$, is depolarizing_channel(4p/3). On a qubit, "Up" is $|0\rangle$ and "Dn" is $|1\rangle$, the excitation that N counts and that Sp destroys: amplitude_damping_channel and amplitude_damping_dissipator take "Dn" to "Up".

And they define observables

obs = X(1)X(2)Z(3)
X(1)*X(2)*Z(3)

Reference

Complex operators can be built from a rich set of functions, for example

Rxy(t) = exp(-im * t * (X⊗X + Y⊗Y) / 4)
Rxy (generic function with 1 method)
Rxy(0.2)(2, 5)
exp(-0.05im*X⊗X-0.05im*Y⊗Y)(2,5)

Operators can be added and multiplied using usual operators (+, -, *, /, ^).

TensorMixedStates.Operator — Type
Operator{N}(name, def = nothing)

a named operator of N sites. def defines it: a matrix, a function of the sites, an expression of other operators, or nothing for an operator each site type declares with @def_operators. To define an operator of one's own, see named.

Examples

Operator{1}("Z", [1 0 ; 0 -1])
Operator{2}("Swap", [1 0 0 0 ; 0 0 1 0 ; 0 1 0 0 ; 0 0 0 1])
source
TensorMixedStates.:⊗ — Method
op1 ⊗ op2
tensor(op1, op2, ...)

the tensor product of generic operators, or of channels, acting on the sites of op1 followed by those of op2: (A ⊗ B)(i, j) is A(i) * B(j). ⊗ is typed \otimes, and tensor is the same function under a name in ASCII.

Examples

Rxy(t) = exp(-im * t * (X ⊗ X + Y ⊗ Y) / 4)
source
TensorMixedStates.Proj — Type
Proj(state)
Proj(A => λ)

the projector $|s\rangle\langle s|$ on a local pure state of one site, given as State takes it, or the projector on the eigenspace of eigenvalue λ of the Hermitian operator A, of one site or several.

Examples

Proj("Up")
Proj(Level => 1)       # the second basis state
Proj(Sz => 0)          # on a Spin(1), the state of Sz = 0
Proj(Swap => -1)       # the antisymmetric part of two sites, the singlet of two qubits
source
TensorMixedStates.Level — Constant
Level

the operator numbering the basis states of a site, $\mathrm{diag}(0, 1, \dots, d - 1)$, defined on every site type.

Examples

State{Pure}(System(3, Qudit(4)), Level .=> [0, 3, 1])
Proj(Level => 2)
source
TensorMixedStates.Swap — Constant
Swap

the exchange of the states of two sites of one type, $|a, b\rangle \mapsto (-1)^{p_a p_b} |b, a\rangle$, the sign coming between two odd states, see fermion_parities.

Examples

Swap(1, 2)
Proj(Swap => -1)       # the antisymmetric part of two sites
source
TensorMixedStates.controlled — Function
controlled(op; name)

the gate leaving the following sites as they are when the first one is in its first basis state, Level => 0, and applying op to them otherwise: on a qubit, op when the first is in "Dn", "1". Its name is "C" followed by the name of a named operator, CZ for controlled(Z), and "controlled(op)" otherwise.

Examples

CZ = controlled(Z)
Toffoli = controlled(controlled(X))
CZ(1, 2)
source
TensorMixedStates.Dissipator — Type
Dissipator(L)
Dissipator(Φ)

the Lindblad dissipator of the jump operator L, generic or placed on sites, $\rho \mapsto L\rho L^\dagger - \frac{1}{2}\{L^\dagger L, \rho\}$, or that of the channel Φ, the sum of those of its Kraus operators, $\Phi - \mathrm{id}$ for Φ preserving the trace. Dissipator(c * L) is abs2(c) * Dissipator(L), and Dissipator(Sm(1)) is Dissipator(Sm)(1).

Examples

Dissipator(Sm)(1)
Dissipator(Sm(1) + Sm(2))           # a collective decay
0.1 * Dissipator(Reset("Up"))(3)
source
TensorMixedStates.Gate — Type
Gate(A)

the channel $\rho \mapsto A\rho A^\dagger$ of the operator A, generic or placed on sites: Gate(X(1)) is Gate(X)(1), Gate(c * A) is abs2(c) * Gate(A), and the gate of a product is the product of the gates. Channels combine with weights of zero or above, which is how a noisy gate is written. An operator multiplied by a channel, or in a tensor product with one, becomes its gate.

Examples

0.9 * Gate(Id) + 0.1 * Gate(X)      # X with probability 0.1
Gate(X(1) + X(2))
source
TensorMixedStates.Reset — Type
Reset(state)

the channel resetting a site to the local state state, given as State takes it, $\rho \mapsto \sigma \otimes \mathrm{tr}_i \rho$, $\sigma$ the density matrix of state and $\mathrm{tr}_i$ the trace over the site. A vector or a matrix is taken as it is, without normalization. On a fermionic site this holds on states of definite parity: on the others, an odd operator O of the other sites takes the value of $\langle F\rangle_\sigma F_i O$, $F_i$ the parity of the site.

Examples

Reset("Up")(3)
Reset(Level => 0)(3)
Reset([0.3 0. ; 0. 0.7])(3)
source
TensorMixedStates.Dephase — Type
Dephase(A)

the channel dephasing in the eigenbasis of the Hermitian operator A, of one site or several, $\rho \mapsto \sum_\lambda P_\lambda \rho P_\lambda$, $P_\lambda$ the projector on the eigenspace of A of eigenvalue $\lambda$: the measurement of A whose result is not read. It erases the coherences between eigenspaces and keeps those within one.

Examples

Dephase(Level)(3)       # in the basis of the site
Dephase(Ntot)(2)        # on an Electron, keeps the coherence of Up and Dn
Dephase(Z ⊗ Z)(1, 2)    # the parity of two qubits, not read
source
TensorMixedStates.reset_channel — Function
reset_channel(p, state)
reset_channel(p, n, state)
reset_channel(p, [state1, state2, ...])

the channel resetting a site, n sites, or as many sites as states, with probability p to state, or to a state per site, the sites being reset together: $(1 - p)\,\rho + p\,\sigma \otimes \mathrm{tr}_S\rho$.

Examples

reset_channel(0.1, "Up")(3)
reset_channel(0.1, ["Up", "Dn"])(1, 2)
source
TensorMixedStates.reset_dissipator — Function
reset_dissipator(γ, state)
reset_dissipator(γ, n, state)
reset_dissipator(γ, [state1, state2, ...])

the generator resetting a site, n sites, or as many sites as states, at rate γ to state, or to a state per site, the sites being reset together: γ * Dissipator(Reset(state)), $\gamma\,(\sigma \otimes \mathrm{tr}_S\rho - \rho)$. A state is given as for Reset, and a vector of numbers is the amplitudes of a single state. Evolving under it for a time t is reset_channel(1 - exp(-γt), ...).

Examples

-im * H + sum(reset_dissipator(0.1, "Up")(i) for i in 1:10)
source
TensorMixedStates.depolarizing_channel — Function
depolarizing_channel(p, n = 1)

the channel depolarizing n sites together with probability p, reset_channel(p, n, "FullyMixed"), $(1 - p)\,\rho + p\,\mathrm{tr}_S\rho \otimes I/d^n$: on a qubit, (1 - 3p/4) * Gate(Id) + p/4 * (Gate(X) + Gate(Y) + Gate(Z)). Two sites depolarized together are not two sites depolarized each on its own, depolarizing_channel(p) ⊗ depolarizing_channel(p).

Examples

prod(depolarizing_channel(0.01)(i) for i in 1:10)
depolarizing_channel(0.02, 2)(1, 2) * controlled(Z)(1, 2)
source
TensorMixedStates.depolarizing_dissipator — Function
depolarizing_dissipator(γ, n = 1)

the generator depolarizing n sites together at rate γ, reset_dissipator(γ, n, "FullyMixed"), $\gamma\,(\mathrm{tr}_S\rho \otimes I/d^n - \rho)$. Evolving under it for a time t is depolarizing_channel(1 - exp(-γt), n).

Examples

-im * H + sum(depolarizing_dissipator(0.1)(i) for i in 1:10)
source
TensorMixedStates.dephasing_channel — Function
dephasing_channel(p, A = Level)

the channel dephasing with probability p in the eigenbasis of A, by default the basis of the site, $(1 - p)\,\rho + p\,\Delta(\rho)$, Δ being Dephase(A).

Examples

prod(dephasing_channel(0.01)(i) for i in 1:10)
dephasing_channel(0.1, Z ⊗ Z)(1, 2)      # the parity of two qubits
source
TensorMixedStates.dephasing_dissipator — Function
dephasing_dissipator(γ, A = Level)

the generator dephasing at rate γ in the eigenbasis of A, by default the basis of the site, γ * Dissipator(Dephase(A)), $\gamma\,(\Delta(\rho) - \rho)$, Δ being Dephase(A). Every coherence between two eigenspaces decays at the same rate γ, where Dissipator(A) damps it at $(\lambda_a - \lambda_b)^2 / 2$, faster for distant eigenvalues: the two agree when A has two eigenvalues, Dissipator(Z) being dephasing_dissipator(2, Z). Evolving under it for a time t is dephasing_channel(1 - exp(-γt), A).

Examples

-im * H + sum(dephasing_dissipator(0.1)(i) for i in 1:10)
dephasing_dissipator(0.1, Z ⊗ Z)(1, 2)      # the parity of two qubits
source
TensorMixedStates.amplitude_damping_channel — Function
amplitude_damping_channel(p, L = Sp)

the channel of amplitude_damping_dissipator(γ, L) over a time t, p = 1 - exp(-γt) being the probability that an excitation of a Qubit, a Fermion or a Boson decays. On a qubit, its Kraus operators are Id - (1 - sqrt(1 - p)) * N and sqrt(p) * Sp. For p = 1, an infinite time, it is the reset to the state the decay ends in, refused when there is none.

Examples

prod(amplitude_damping_channel(0.01)(i) for i in 1:10)
amplitude_damping_channel(0.1, A)(3)           # each photon lost with probability 0.1
source
TensorMixedStates.amplitude_damping_dissipator — Function
amplitude_damping_dissipator(γ, L = Sp)

the generator of the decay at rate γ of the excitations the operator L of one site destroys, γ * Dissipator(L): Sp on a Qubit, from "Dn" to "Up", C on a Fermion, A on a Boson. Evolving under it for a time t is amplitude_damping_channel(1 - exp(-γt), L).

Examples

-im * H + sum(amplitude_damping_dissipator(0.1)(i) for i in 1:10)
amplitude_damping_dissipator(0.1, A)(3)     # the loss of photons
source
TensorMixedStates.Evolver — Type
Evolver(K)

the generator $\rho \mapsto K\rho + \rho K^\dagger$ of the operator K, generic or placed on sites, $d\psi/dt = K\psi$ on a pure state: for K = -im * H, the Hamiltonian part $-i[H, \rho]$ of a generator. An operator added to a generator becomes its Evolver. A real coefficient comes out of it, a complex one stays inside.

Examples

-im * H + Dissipator(Sm)(1)         # Evolver(-im * H) + Dissipator(Sm)(1)
source
TensorMixedStates.named — Function
named(def, name)

the operator name defined by def: an expression of operators, a matrix, or a function of the sites returning a matrix. A matrix or a function acts on one site, an expression on as many as it does. Sites conserving operators of the same name share one charge, so renaming keeps two quantities apart.

Examples

named([1 1 ; 1 -1] / √2, "MyH")
Fermion(conserve = named(N, "Nf"))
source
TensorMixedStates.parity — Function
parity(A)

the operator $(-1)^A$, mod(A, 2): conserved, a charge of $\mathbb{Z}_2$.

Examples

Fermion(conserve = parity(N))
source
Base.mod — Method
mod(A, m)

the operator $e^{2i\pi A/m}$. Conserved, conserve = mod(N, 3) gives the charges $n \bmod 3$, added modulo 3 over the sites.

source
ITensors.dag — Method
dag(op)
op'

the adjoint of an operator on pure states, generic or placed on sites, a placed one having its coefficients conjugated and its products reversed.

Examples

dag(C) * C
h = sum(C'(i) * C(i + 1) for i in 1:9); H = -(h + h')
source
Base.exp — Method
exp(::GenericOp)

the exponential of a generic operator, or of a generic generator, the channel of the evolution it generates.

Examples

exp(-im * t * (X ⊗ X + Y ⊗ Y) / 4)
exp(t * (-im * (X ⊗ X) + Dissipator(Sm ⊗ Sm)))
source
Base.sqrt — Method
sqrt(::GenericOp)

the principal square root of a generic operator, op^0.5

source
NDTensors.matrix — Function
matrix(op, site, sites...)

the matrix of the generic operator op on the given sites, a single one standing for several identical ones, the last site varying fastest. A tensor product of fermionic factors holds the Jordan-Wigner strings between them: the matrix of C ⊗ dag(C) is that of C(1) * dag(C)(2). A channel or a generator acts on the density matrices ρ of the sites: its matrix is that of the map of vec(ρ), the last site varying fastest and, on each site, the ket faster than the bra.

Examples

matrix(X, Qubit())
matrix(X ⊗ A, Qubit(), Boson(2))
matrix(Gate(X), Qubit())
source
matrix(op, system)

the matrix of the operator op, placed on sites, on all the sites of system, the Jordan-Wigner strings of its fermionic operators laid, on the basis of the product states ordered as kron orders them, the first site varying the slowest, as dense_state and Vector order them: the matrix an exact diagonalization of a small system checks a result against. It is refused beyond the dimension dense_max, 4096.

Examples

eigvals(Hermitian(matrix(hamiltonian, System(10, Qubit()))))
source
TensorMixedStates.tensor — Function
op1 ⊗ op2
tensor(op1, op2, ...)

the tensor product of generic operators, or of channels, acting on the sites of op1 followed by those of op2: (A ⊗ B)(i, j) is A(i) * B(j). ⊗ is typed \otimes, and tensor is the same function under a name in ASCII.

Examples

Rxy(t) = exp(-im * t * (X ⊗ X + Y ⊗ Y) / 4)
source
::System ⊗ ::System
tensor(::System, ::System)

the system of the sites of the first followed by those of the second.

source
a ⊗ b
tensor(a, b)

the product of the states a and b, on the system a.system ⊗ b.system, the sites of b following those of a: exact, its bond dimension the larger of theirs, its norm or its trace the product of theirs. A pure state with a mixed one is mixed, see mix. On fermions, the operators of a stand on the left of those of b: the fermionic product of two states of definite parity.

Examples

ψ ⊗ State{Pure}(System(2, Qubit()), "Up")       # two qubits more
left ⊗ right                                     # two halves made apart
source

Gates of circuits

The module Circuits, using .Circuits, gathers the gates of quantum circuits: H, S and T, which H and S extend to qudits, Phase, Sum, the rotations and the controlled gates. A rotation by θ has θ/2 in its exponent, Rx(θ) being $e^{-i\theta X/2}$ on a qubit and Rxx(θ) $e^{-i\theta X \otimes X/2}$ on two, as in OpenQASM, Qiskit or PennyLane.

TensorMixedStates.Circuits — Module
using .Circuits

module of the gates of quantum circuits: H, S and T, which H and S extend to qudits, Phase, the gate Sum of two qudits, the rotations Rx, Ry, Rz, Rxx, Ryy and Rzz, and the controlled gates CX or CNOT, CY, CZ, and CCX or Toffoli.

source
TensorMixedStates.H — Constant
H

the Hadamard gate of a qubit, $(X + Z)/\sqrt{2}$, and on a qudit the Fourier operator, $|j\rangle \mapsto \sum_k \omega^{jk} |k\rangle / \sqrt{d}$, $\omega = e^{2i\pi/d}$

source
TensorMixedStates.S — Constant
S

the phase gate of a qubit, $\mathrm{diag}(1, i)$, and on a qudit the phase operator, of order $d$ for odd $d$ and $2d$ for even $d$, see Qudit

source
TensorMixedStates.Sum — Constant
Sum

the generalized controlled not of two qudits, $|i, j\rangle \mapsto |i, i + j \mod d\rangle$, $d$ being the dimension of the second, read on the sites it is placed on; on two Qudit(2) it is the CNOT.

Examples

Sum(1, 2)
source
TensorMixedStates.Rx — Function
Rx(θ)

the rotation by the angle θ about the axis x, $e^{-i\theta S_x}$: on a qubit $e^{-i\theta X/2}$, as in OpenQASM, Qiskit or Nielsen and Chuang, and on a spin the rotation of the spin. Ry and Rz turn about y and z.

Examples

Rx(π / 2)(1)
controlled(Ry(0.3))(1, 2)
source
TensorMixedStates.Rz — Function
Rz(θ)

the rotation by the angle θ about the axis z, $e^{-i\theta S_z}$, see Rx. On a qubit it is Phase(θ) times the global phase $e^{-i\theta/2}$, which a controlled gate makes relative.

source
TensorMixedStates.Rxx — Function
Rxx(θ)

the Ising coupling of two sites by the angle θ, $e^{-2i\theta S_x \otimes S_x}$: on two qubits $e^{-i\theta X \otimes X/2}$, as in Qiskit or PennyLane. Ryy and Rzz couple Sy and Sz.

Examples

Rzz(π / 2)(1, 2)        # the square root of Z ⊗ Z, up to a global phase
source
TensorMixedStates.Ryy — Function
Ryy(θ)

the Ising coupling of two sites by the angle θ, $e^{-2i\theta S_y \otimes S_y}$, see Rxx

source
TensorMixedStates.Rzz — Function
Rzz(θ)

the Ising coupling of two sites by the angle θ, $e^{-2i\theta S_z \otimes S_z}$, see Rxx

source
TensorMixedStates.CX — Constant
CX

the controlled not, controlled(X), also named CNOT: on two qubits, X on the second when the first is in "Dn", "1".

Examples

apply(CX(1, 2) * H(1), State{Pure}(System(2, Qubit()), "Up"))      # a Bell pair
source
TensorMixedStates.CCX — Constant
CCX

the Toffoli gate, controlled(CX), also named Toffoli: on three qubits, X on the third when the first two are in "Dn".

source

Operators on another system

A representation of one's own that keeps its tensors on another system, see States of one's own, places the operators it measures or applies there with map_sites.

TensorMixedStates.map_sites — Function
map_sites(f, op)

the operator placed on sites op with each factor moved from its sites to their images by f: map_sites(i -> 2i - 1, X(1) * Y(2)) is X(1) * Y(3).

source

Operator types

These types describe the operators themselves, they are mostly useful when writing functions operating on operators. They are not exported: TensorMixedStates.GenericOp.

TensorMixedStates.Op — Type
Op{K <: OpKind, T <: GI, N}

the supertype of all operators: K their kind, IsOperator, IsChannel or IsGenerator, T Generic or Indexed, N the number of sites of a generic operator, 1 for a placed one.

source
TensorMixedStates.OpKind — Type
abstract type OpKind
IsOperator
IsChannel
IsGenerator

the kinds of operators: IsOperator for an operator, a linear map of the states of its sites; IsChannel for a channel, a completely positive map of density matrices; IsGenerator for a generator, the Lindblad generator of an evolution

source