operator

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package operator provides quantum channel representations and conversions.

A quantum channel (completely positive trace-preserving map) can be represented in several equivalent forms:

  • Kraus: a set of Kraus operators {E_k} satisfying sum_k E_k-dagger E_k = I.
  • SuperOp: a d^2 x d^2 superoperator matrix S = sum_k (E_k (x) conj(E_k)).
  • Choi: a d^2 x d^2 Choi matrix (Choi-Jamiolkowski representation).
  • PTM: a d^2 x d^2 real Pauli transfer matrix.

The package provides lossless conversions between all representations, validity checks (IsCP, IsTP, IsCPTP), composition (Compose, Tensor), and channel fidelity measures (AverageGateFidelity, ProcessFidelity).

Existing noise.Channel values can be lifted into operator representations via FromChannel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AverageGateFidelity

func AverageGateFidelity(actual *Kraus) float64

AverageGateFidelity computes the average gate fidelity of a channel relative to the identity channel. F_avg = (d * F_pro + 1) / (d + 1)

func IsCP

func IsCP(c *Choi, tol float64) bool

IsCP checks if a channel (given as Choi matrix) is completely positive. A channel is CP if and only if its Choi matrix is positive semidefinite. All eigenvalues must be >= -tol.

func IsCPTP

func IsCPTP(k *Kraus, tol float64) bool

IsCPTP checks if a channel (given as Kraus operators) is both CP and TP.

func IsTP

func IsTP(k *Kraus, tol float64) bool

IsTP checks if a channel (given as Kraus operators) is trace-preserving. A channel is TP if sum_k E_k-dagger * E_k = I.

func ProcessFidelity

func ProcessFidelity(actual *Kraus) float64

ProcessFidelity computes the entanglement fidelity (process fidelity) of a channel relative to the identity channel. F_pro = Tr(Choi_identity-dagger * Choi_actual) / d^2 For the identity channel, Choi_identity[ik,jl] = delta_ij * delta_kl / d, which means F_pro = sum_{i,j} Choi_actual[ii, jj] / d^2 = (1/d^2) * sum of the "diagonal blocks" diagonal entries. Equivalently, F_pro = (1/d) * sum_k |Tr(E_k)|^2 / d.

Types

type Choi

type Choi struct {
	// contains filtered or unexported fields
}

Choi represents a quantum channel via its Choi matrix (Choi-Jamiolkowski). Lambda = sum_k vec(E_k) * vec(E_k)-dagger. The matrix is dim^2 x dim^2 flat row-major.

func KrausToChoi

func KrausToChoi(k *Kraus) *Choi

KrausToChoi converts a Kraus representation to a Choi matrix. Lambda = sum_k vec(E_k) * vec(E_k)-dagger where vec(E) stacks columns: vec[j*dim+i] = E[i,j].

func NewChoi

func NewChoi(nq int, matrix []complex128) *Choi

NewChoi creates a Choi from a dim^2 x dim^2 flat row-major matrix.

func PTMToChoi

func PTMToChoi(p *PTM) *Choi

PTMToChoi converts a PTM to a Choi matrix. Lambda = (1/d) * sum_ij R_ij * (sigma_j^T (x) sigma_i) Note: we use the relation that the Choi matrix can be reconstructed from the PTM via the Pauli basis.

func SuperOpToChoi

func SuperOpToChoi(s *SuperOp) *Choi

SuperOpToChoi converts a superoperator to a Choi matrix. The superoperator has S[a*dim+b, c*dim+d] = E[a,c] * conj(E[b,d]). The Choi matrix has Lambda[c*dim+a, d*dim+b] = E[a,c] * conj(E[b,d]). Reshuffling: S[a*dim+b, c*dim+d] -> Lambda[c*dim+a, d*dim+b].

func (*Choi) Matrix

func (c *Choi) Matrix() []complex128

Matrix returns a defensive copy of the Choi matrix.

func (*Choi) NumQubits

func (c *Choi) NumQubits() int

NumQubits returns the number of qubits the channel acts on.

type Kraus

type Kraus struct {
	// contains filtered or unexported fields
}

Kraus represents a quantum channel via Kraus operators. Each operator is a dim x dim flat row-major complex matrix where dim = 2^nq.

func ChoiToKraus

func ChoiToKraus(c *Choi) *Kraus

ChoiToKraus converts a Choi matrix to Kraus operators. Eigendecomposes the Choi matrix, then reshapes eigenvectors corresponding to positive eigenvalues into Kraus operators.

func Compose

func Compose(a, b *Kraus) *Kraus

Compose returns the sequential composition of two channels: first a, then b. The resulting Kraus operators are {B_j * A_i} for all pairs (i, j). Both channels must act on the same number of qubits.

func FromChannel

func FromChannel(ch noise.Channel) *Kraus

FromChannel bridges an existing noise.Channel to a Kraus representation.

func NewKraus

func NewKraus(nq int, operators [][]complex128) *Kraus

NewKraus creates a Kraus representation from the given operators. Each operator must be a dim x dim flat row-major matrix where dim = 2^nq.

func PTMToKraus

func PTMToKraus(p *PTM) *Kraus

PTMToKraus converts a PTM to Kraus operators via Choi decomposition. First converts PTM -> Choi, then Choi -> Kraus.

func Tensor

func Tensor(a, b *Kraus) *Kraus

Tensor returns the tensor product of two channels acting on disjoint qubits. If a acts on nA qubits and b acts on nB qubits, the result acts on nA+nB qubits. The resulting Kraus operators are {A_i (x) B_j} for all pairs (i, j).

func (*Kraus) NumQubits

func (k *Kraus) NumQubits() int

NumQubits returns the number of qubits the channel acts on.

func (*Kraus) Operators

func (k *Kraus) Operators() [][]complex128

Operators returns a defensive copy of the Kraus operators.

type PTM

type PTM struct {
	// contains filtered or unexported fields
}

PTM represents a quantum channel as a Pauli transfer matrix. R_ij = Tr(sigma_i * E(sigma_j)) / d. The matrix is dim^2 x dim^2 flat row-major real.

func ChoiToPTM

func ChoiToPTM(c *Choi) *PTM

ChoiToPTM converts a Choi matrix to a PTM.

func KrausToPTM

func KrausToPTM(k *Kraus) *PTM

KrausToPTM converts a Kraus representation to a Pauli transfer matrix. R_ij = Tr(sigma_i * E(sigma_j)) / d where E(sigma_j) = sum_k E_k * sigma_j * E_k-dagger.

func NewPTM

func NewPTM(nq int, matrix []float64) *PTM

NewPTM creates a PTM from a dim^2 x dim^2 flat row-major real matrix.

func SuperOpToPTM

func SuperOpToPTM(s *SuperOp) *PTM

SuperOpToPTM converts a superoperator to a PTM.

func (*PTM) Matrix

func (p *PTM) Matrix() []float64

Matrix returns a defensive copy of the PTM matrix.

func (*PTM) NumQubits

func (p *PTM) NumQubits() int

NumQubits returns the number of qubits the channel acts on.

type SuperOp

type SuperOp struct {
	// contains filtered or unexported fields
}

SuperOp represents a quantum channel as a superoperator matrix. S = sum_k (E_k (x) conj(E_k)), acts on vec(rho). The matrix is dim^2 x dim^2 flat row-major.

func ChoiToSuperOp

func ChoiToSuperOp(c *Choi) *SuperOp

ChoiToSuperOp converts a Choi matrix to a superoperator. Inverse reshuffling: Lambda[c*dim+a, d*dim+b] -> S[a*dim+b, c*dim+d].

func KrausToSuperOp

func KrausToSuperOp(k *Kraus) *SuperOp

KrausToSuperOp converts a Kraus representation to a superoperator. S = sum_k (E_k (x) conj(E_k)).

func NewSuperOp

func NewSuperOp(nq int, matrix []complex128) *SuperOp

NewSuperOp creates a SuperOp from a dim^2 x dim^2 flat row-major matrix.

func (*SuperOp) Matrix

func (s *SuperOp) Matrix() []complex128

Matrix returns a defensive copy of the superoperator matrix.

func (*SuperOp) NumQubits

func (s *SuperOp) NumQubits() int

NumQubits returns the number of qubits the channel acts on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL