qalgebra package

Main QAlgebra package

The qalgebra package exposes all of QAlgebra’s functionality for easy interactive or programmative use.

For interactive usage, the package should be initialized as follows:

>>> import qalgebra
>>> qalgebra.init_printing()

QNET provides a “flat” API. That is, after

>>> import qalgebra

all submodules are directly accessible, e.g.

>>> qalgebra.core.operator_algebra.OperatorSymbol
<class 'qalgebra.core.operator_algebra.OperatorSymbol'>

Furthermore, every package exports the “public” symbols of any of its submodules/subpackages (public symbols are those listed in __all__)

>>> (qalgebra.core.operator_algebra.OperatorSymbol is
...  qalgebra.core.OperatorSymbol is qalgebra.OperatorSymbol is
...  qalgebra.OperatorSymbol)
True

In an interactive context (and only there!), a star import such as

from qalgebra import *

may be useful.

Submodules:

Subpackages:

Summary

__all__ Exceptions:

AlgebraError

Base class for all algebraic errors.

AlgebraException

Base class for all algebraic exceptions.

BasisNotSetError

Raised if the basis or a Hilbert space dimension is unavailable.

CannotSimplify

Raised when a rule cannot further simplify an expression.

CannotSymbolicallyDiagonalize

Matrix cannot be diagonalized analytically.

InfiniteSumError

Raised when expanding a sum into an infinite number of terms.

NoConjugateMatrix

Raised when entries of Matrix have no defined conjugate.

NonSquareMatrix

Raised when a Matrix fails to be square.

OverlappingSpaces

Raised when objects fail to be in separate Hilbert spaces.

SpaceTooLargeError

Raised when objects fail to be have overlapping Hilbert spaces.

UnequalSpaces

Raised when objects fail to be in the same Hilbert space.

__all__ Classes:

Adjoint

Symbolic Adjoint of an operator

BasisKet

Local basis state, identified by index or label

Bra

The associated dual/adjoint state for any ket

BraKet

The symbolic inner product between two states

CoherentStateKet

Local coherent state, labeled by a complex amplitude \(\alpha\).

Commutator

Commutator of two operators

Create

Bosonic creation operator

Destroy

Bosonic annihilation operator

Displace

Unitary coherent displacement operator.

Expression

Base class for all QAlgebra Expressions.

FockIndex

Symbolic index labeling a basis state in a LocalSpace

FockLabel

Symbolic label that evaluates to the label of a basis state

HilbertSpace

Base class for Hilbert spaces

IdxSym

Index symbol in an indexed sum or product.

IndexOverFockSpace

Index range over the integer indices of a LocalSpace basis

IndexOverList

Index over a list of explicit values

IndexOverRange

Index over the inclusive range between two integers

IndexedSum

Base class for indexed sums.

IntIndex

A symbolic label that evaluates to an integer.

Jminus

Lowering operator on a spin space

Jplus

Raising operator of a spin space

Jz

Spin (angular momentum) operator in z-direction

KetBra

Outer product of two states

KetIndexedSum

Indexed sum over Kets.

KetPlus

Sum of states.

KetSymbol

Symbolic state.

LocalKet

A state on a LocalSpace.

LocalOperator

Base class for “known” operators on a LocalSpace.

LocalSigma

Level flip operator between two levels of a LocalSpace.

LocalSpace

Hilbert space for a single degree of freedom.

MatchDict

Result of a Pattern.match().

Matrix

Matrix of Expressions.

NullSpaceProjector

Projection operator onto the nullspace of its operand.

Operation

Base class for “operations”

Operator

Base class for all quantum operators.

OperatorDerivative

Symbolic partial derivative of an operator

OperatorIndexedSum

Indexed sum over operators

OperatorPlus

Sum of Operators

OperatorPlusMinusCC

An operator plus or minus its complex conjugate.

OperatorSymbol

Symbolic operator

OperatorTimes

Product of operators

OperatorTimesKet

Product of an operator and a state.

OperatorTrace

(Partial) trace of an operator

Pattern

Pattern for matching an expression.

Phase

Unitary “phase” operator

ProductSpace

Tensor product of local Hilbert spaces.

PseudoInverse

Unevaluated pseudo-inverse \(\Op{X}^+\) of an operator \(\Op{X}\).

QuantumAdjoint

Base class for adjoints of quantum expressions

QuantumDerivative

Symbolic partial derivative.

QuantumExpression

Base class for expressions associated with a Hilbert space

QuantumIndexedSum

Base class for indexed sums of quantum expressions.

QuantumOperation

Base class for operations on quantum expression

QuantumPlus

General implementation of addition of quantum expressions

QuantumSymbol

Symbolic element of an algebra.

QuantumTimes

General implementation of product of quantum expressions

SPost

Linear post-multiplication operator.

SPre

Linear pre-multiplication operator

Scalar

Base class for Scalars

ScalarDerivative

Symbolic partial derivative of a scalar

ScalarExpression

Base class for scalars with non-scalar arguments

ScalarIndexedSum

Indexed sum over scalars.

ScalarPlus

Sum of scalars

ScalarPower

A scalar raised to a power.

ScalarTimes

Product of scalars

ScalarTimesKet

Product of a Scalar coefficient and a ket

ScalarTimesOperator

Product of a Scalar coefficient and an Operator.

ScalarTimesQuantumExpression

Product of a Scalar and a QuantumExpression

ScalarTimesSuperOperator

Product of a Scalar coefficient and a SuperOperator.

ScalarValue

Wrapper around a numeric or symbolic value

SingleQuantumOperation

Base class for operations on a single quantum expression

Singleton

Metaclass for singletons.

SpinIndex

Symbolic label for a spin degree of freedom

SpinOperator

Base class for operators in a spin space

SpinSpace

A Hilbert space for an integer or half-integer spin system.

Squeeze

Unitary squeezing operator.

State

Base class for states in a Hilbert space

StateDerivative

Symbolic partial derivative of a state

StrLabel

Symbolic label that evaluates to a string

SuperAdjoint

Adjoint of a super-operator.

SuperOperator

Base class for super-operators

SuperOperatorDerivative

Symbolic partial derivative of a super-operator

SuperOperatorPlus

A sum of super-operators

SuperOperatorSymbol

Symbolic super-operator

SuperOperatorTimes

Product of super-operators

SuperOperatorTimesOperator

Application of a super-operator to an operator.

TensorKet

A tensor product of kets.

__all__ Functions:

KroneckerDelta

Kronecker delta symbol.

LocalProjector

A projector onto a specific level of a LocalSpace

PauliX

Pauli-type X-operator.

PauliY

Pauli-type Y-operator

PauliZ

Pauli-type Z-operator

SpinBasisKet

Constructor for a BasisKet for a SpinSpace.

Sum

Instantiator for an arbitrary indexed sum.

adjoint

Return the adjoint of an obj.

anti_commutator

If B != None, return the anti-commutator \(\{A,B\}\), otherwise return the super-operator \(\{A,\cdot\}\).

ascii

Return an ASCII representation of the given object / expression

block_matrix

Generate the operator matrix with quadrants

commutator

Commutator of A and B

configure_printing

Context manager for temporarily changing the printing system.

convert_to_qutip

Convert a QAlgebra expression to a qutip object

convert_to_sympy_matrix

Convert a QAlgebra expression to an explicit n x n instance of sympy.Matrix, where n is the dimension of full_space.

decompose_space

Simplifies OperatorTrace expressions over tensor-product spaces by turning it into iterated partial traces.

diagm

Generalizes the diagonal matrix creation capabilities of numpy.diag to Matrix objects.

dotprint

Return the DOT (graph) description of an Expression tree as a string.

expand_commutators_leibniz

Recursively expand commutators in expr according to the Leibniz rule.

factor_coeff

Factor out coefficients of all factors.

factor_for_trace

Factor ls out of op for easy tracing.

get_coeffs

Create a dictionary with all Operator terms of the expression (understood as a sum) as keys and their coefficients as values.

hstackm

Generalizes numpy.hstack to Matrix objects.

identity_matrix

Generate the N-dimensional identity matrix.

init_printing

Initialize the printing system.

latex

Return a LaTeX representation of the given object / expression

lindblad

Return the super-operator Lindblad term of the Lindblad operator C

liouvillian

Return the Liouvillian super-operator associated with H and Ls

match_pattern

Recursively match expr with the given expr_or_pattern.

no_instance_caching

Temporarily disable instance caching in create()

pattern

‘Flat’ constructor for Pattern.

pattern_head

Constructor for a Pattern matching a ProtoExpr.

print_tree

Print a tree representation of the structure of expr

rewrite_with_operator_pm_cc

Try to rewrite expr using OperatorPlusMinusCC.

singleton_object

Class decorator that transforms (and replaces) a class definition (which must have a Singleton metaclass) with the actual singleton object.

sqrt

Square root of a Scalar or scalar value.

srepr

Render the given expression into a string that can be evaluated in an appropriate context to re-instantiate an identical expression.

substitute

Substitute symbols or (sub-)expressions with the given replacements.

symbols

The symbols() function from SymPy.

temporary_instance_cache

Use a temporary cache for instances in create()

temporary_rules

Allow temporary modification of rules for create()

tex

Alias for latex().

tr

Instantiate while applying automatic simplifications.

tree

Give the output of tree as a multiline string, using line drawings to visualize the hierarchy of expressions (similar to the tree unix command line program for showing directory trees)

unicode

Return a unicode representation of the given object / expression

vstackm

Generalizes numpy.vstack to Matrix objects.

wc

Constructor for a wildcard-Pattern.

zerosm

Generalizes numpy.zeros to Matrix objects.

__all__ Data:

FullSpace

The ‘full space’, i.e.

II

IdentityOperator constant (singleton) object.

IdentityOperator

IdentityOperator constant (singleton) object.

IdentitySuperOperator

Neutral element for product of super-operators

One

The neutral element with respect to scalar multiplication

SingletonType

A dummy type that for checking whether an object is a Singleton.

TrivialKet

TrivialKet constant (singleton) object.

TrivialSpace

The ‘nullspace’, i.e.

Zero

The neutral element with respect to scalar addition

ZeroKet

ZeroKet constant (singleton) object for the null-state.

ZeroOperator

ZeroOperator constant (singleton) object.

ZeroSuperOperator

Neutral element for sum of super-operators

Reference

qalgebra.init_algebra(*, default_hs_cls='LocalSpace')[source]

Initialize the algebra system.

Parameters

default_hs_cls (str) – The name of the LocalSpace subclass that should be used when implicitly creating Hilbert spaces, e.g. in OperatorSymbol