Internals

These functions and types are not exported (they are accessible as QuantumAlgebra.name). They mostly form the internal interface of the package and should not be relevant to most users, apart from the settings (e.g., use_σpm, auto_normal_form and use_bracket_display) and some functions to inspect or modify expressions (e.g., replace_inds and is_normal_form).

QuantumAlgebra.BaseOpProduct — Type
BaseOpProduct(v::Vector{BaseOperator})

A product of operators stored as a vector that can be modified (e.g., while normal ordering). Inside the terms of an expression, products of operators are stored compactly together with the rest of the term (see QuTerm).

source
QuantumAlgebra.BaseOpType — Type
BaseOpType

The type of a BaseOperator, e.g., BosonCreate_ or TLSz_. Operators are ordered by their type (in the order of the values of BaseOpType), then by name, additional data and indices. Normal ordering brings products of operators into this order as far as their algebra allows, so that, e.g., creation operators end up to the left of annihilation operators.

source
QuantumAlgebra.BaseOperator — Type
BaseOperator

A single operator in a term, given by its type (see BaseOpType), its name, its indices, and additional data for some kinds of operators (e.g., the levels of a qudit transition, or the value of a spin). Operators are usually not created directly, but with the macros that define operators (e.g., @boson), which give QuExpr objects. For bosons, fermions and two-level systems, BaseOperators can also be created with BosonDestroy(name, inds...), BosonCreate(name, inds...), FermionDestroy, FermionCreate, TLSDestroy, TLSCreate, TLSx, TLSy and TLSz (e.g., BosonCreate(:a, :i) is $a_i^†$).

source
QuantumAlgebra.IndexFunction — Type
IndexFunction

A function that maps indices to indices (f(ind::QuIndex)), which can then be applied to operators, parameters, terms and expressions to change their indices (e.g., replace_inds).

source
QuantumAlgebra.MixedLindbladTerm — Type
MixedLindbladTerm(γ, (L1, L2))

The "mixed" Lindblad term with rate γ and two operators L1 and L2, which gives the symmetrized $\frac{1}{2} [γ (L_2^† A L_1 - \frac{1}{2} \{L_2^† L_1, A\}) + γ^* (L_1^† A L_2 - \frac{1}{2} \{L_1^† L_2, A\})]$ in the equation of motion of an operator $A$.

source
QuantumAlgebra.OpFamily — Type
OpFamily

The family of an operator (bosons, fermions, two-level systems, qudits, spins, or generators of so(n) or u(n), see opfamily). Operators of different families always commute, and the algebra within a family F is defined by methods of exchange!, contract! and commutes with the first argument ::Val{F} (see the comments at the beginning of src/operator_rules.jl), together with ladder, vacuum_eigenvalue_right, op_adjoint, opsymbol, lookahead_contraction, lookahead_meet and lookahead_exchange, which have default methods.

source
QuantumAlgebra.Param — Type
Param

A parameter in a term, given by its name, its state ('r' for a real parameter, 'n' for a complex parameter, and 'c' for the complex conjugate of a complex parameter) and its indices. Parameters are defined with @qparam or qparam (or, in the legacy interface, with param and the string macros @Pr_str and @Pc_str).

source
QuantumAlgebra.QuEqSys — Type
QuEqSys

A system of equations of motion for expectation values (QuEqSys{ExpVal}) or correlators (QuEqSys{Corr}), as returned by heisenberg_eom_system. EQ.eqs is an ordered dictionary from the expectation values (or correlators) to the right-hand sides of their equations, EQ[k] is the right-hand side of the k-th equation, and EQ[A] the one for the operator A (e.g., EQ[a] for $⟨a⟩$) or the expectation value (or correlator) A. The system is printed as the list of equations, and can be converted to LaTeX with latex.

source
QuantumAlgebra.QuExprConstructor — Type
QuExprConstructor

A callable object that creates operators (or parameters) as QuExprs, e.g., a in a(:i) for the operators of the legacy interface (see boson_ops). Its adjoint a' creates the adjoint operators. The variables of operators with indices (e.g., a after @boson a[:], see QuExprCstrctArrAlias) call it with the indices.

source
QuantumAlgebra.QuExprCstrctArrAlias — Type
QuExprCstrctArrAlias

The variable of an operator or parameter with indices, e.g., a after @boson a[:,:] (or a = boson(:a; ndims=2)): indexing it with the declared number of indices gives the operator with these indices, a[i,j], and its adjoint a' is the variable of the adjoint operator, a'[i,j]. It is also used for indices with a subindex, e.g., j after @qindex j[:] (with j[2] giving j₂).

source
QuantumAlgebra.QuIndex — Type
QuIndex(i)

An index of an operator or parameter: an integer (QuIndex(2)), a symbolic index, given by a single unicode character with an optional integer subindex (QuIndex(:i), or QuIndex(:j_2) and QuIndex("j_2"), printed as j₂), or a summation index (see sumindex).

Indices are usually not created directly: operators and parameters accept integers and symbols as indices (e.g., a[:i,2]), or index variables defined with @qindex (e.g., a[i,j[2]]).

See also isintindex, issumindex.

source
QuantumAlgebra.QuOpName — Type
QuOpName(name::Symbol)

The name of an operator or parameter. Names are stored as integer ids into a global table of names, so that they can be compared and hashed quickly, and they are ordered alphabetically.

source
QuantumAlgebra.QuTerm — Type
QuTerm

Represents a single term in a quantum algebra expression.

A term consists of:

  • Sum indices (summed-over indices)
  • Delta functions
  • Parameters
  • Expectation values
  • Correlators/cumulants
  • Bare operators

See also

QuExpr, BaseOperator

source
QuantumAlgebra.QuditVariable — Type
QuditVariable

A qudit created by qudit or @qudit: q(i,j) is the transition operator $|i⟩⟨j|$ (for a qudit with indices, an object that is indexed with the indices, q(i,j)[k]), and q(M) the operator with matrix M, $\sum_{ij} M_{ij} |i⟩⟨j|$ (or q(M)[k]).

source
QuantumAlgebra.SOVariable — Type
SOVariable

The generators of so(n) created by so or @so: L(a,b) is the generator $L_{ab}$ (for generators with indices, an object that is indexed with the indices, L(a,b)[k]).

source
QuantumAlgebra.SingleLindbladTerm — Type
SingleLindbladTerm(γ, L)

The Lindblad term with rate γ and jump operator L, which gives $γ (L^† A L - \frac{1}{2} \{L^† L, A\})$ in the equation of motion of an operator $A$.

source
QuantumAlgebra.UNVariable — Type
UNVariable

The generators of u(n) created by un or @un: S(a,b) is the generator $S_{ab}$ (for generators with indices, an object that is indexed with the indices, S(a,b)[k]).

source
QuantumAlgebra.WorkTerm — Type
WorkTerm

Mutable working form of a QuTerm used while normal ordering. All vectors are owned by the WorkTerm and can be modified freely. Convert back with QuTerm(w::WorkTerm).

source
QuantumAlgebra._COWDict — Type
_COWDict{K,V}()

A dictionary that can be read from several threads without locking. It is never modified in place, but replaced as a whole (under a lock) when entries are added, so it is only meant for small tables (such as caches with few entries).

source
QuantumAlgebra.replace_inds — Type
replace_inds(old => new, …)

The index function (see IndexFunction) that replaces the indices old by new, which can be applied to expressions, e.g., replace_inds(QuIndex(:i) => QuIndex(:k))(g[:i]*b[:i]*b'[:j]) gives g(k) b(k) b†(j).

source
QuantumAlgebra.δ — Type
δ(iA, iB)

The Kronecker delta $δ_{iA,iB}$ of two indices in a term. It is only stored for two different indices that can be equal (i.e., not for two different integers). Kronecker deltas appear, e.g., when normal ordering, such as in normal_form(b[:i]*b'[:j]), which gives δ(ij) + b†(j) b(i).

δ(Ainds, Binds), with two vectors of indices, returns the Kronecker deltas for the pairwise equality of Ainds and Binds (only for pairs of different indices), or nothing if not all of them can be equal.

source
QuantumAlgebra.CorrPerm_isless — Method
CorrPerm_isless(a,b)

isless for Tuples of Tuples representing products of Corr (see above) of a permutation of operators. E.g., ((1,3),(2,)) represents <A1 A3>C <A2>C. It is assumed that the total number of operators in a and b is equal, i.e., that sum(length.(a)) == sum(length.(b)).

source
QuantumAlgebra.CorrTup_isless — Method
CorrTup_isless(a,b)

isless for Tuples of integers that represent Corr of sorted operators (with n representing An such that n<m == An<Am). (n,m,...) ≡ Corr(AnAm...). Defined in such a way that the same order is obtained as with BaseOperator objects

source
QuantumAlgebra._canonicalize_suminds — Method
_canonicalize_suminds(t::QuTerm)

Renumber the sum indices of the normal-ordered term t canonically. Returns (tc, sign, isnormal) such that t = sign*tc, where isnormal is true if tc is in normal form, or nothing if the term vanishes (because renumbering gives the same term with opposite sign).

source
QuantumAlgebra._encode_term — Method
_encode_term(nsuminds, δs, params, expvals, corrs, bares, fδ, f)

Create a QuTerm from its parts. Each part is a tuple of collections whose concatenation gives the respective part of the term. The index function fδ is applied to the indices of the δs and f to all other indices (nothing stands for no change). Index functions are applied in the order in which the indices are stored, i.e., δs, params, expvals, corrs, bares.

source
QuantumAlgebra._spin_dim — Method

_spin_dim(A): the dimension 2j+1 of the representation of the spin operator A, or nothing if j is not a fixed number

source
QuantumAlgebra.auto_normal_form — Function
auto_normal_form(t::Bool=true; set_preference=false)

Enable (or disable, with t = false) automatic normal ordering, which brings every expression into normal form when it is created (e.g., a*a' then directly gives 1 + a†() a()). It is disabled by default, so that normal_form has to be called explicitly. If set_preference is true, the choice is stored with Preferences.jl (preference "auto_normal_form") for future sessions.

source
QuantumAlgebra.contract! — Method

contract!(emit, A, B): simplify the product A B. Returns nothing if it does not simplify, or (fac, op) with A B = fac op + R (see exchange! for R).

source
QuantumAlgebra.corrheis — Method
corrheis(A, H, Ls=())

Return the right-hand side of the equation of motion of the correlator (cumulant) $⟨A⟩_c$ of a product of operators A (or for a correlator A), expressed through correlators. The results are cached, so that the equations of the correlators that appear in the equations of higher-order correlators are only calculated once.

source
QuantumAlgebra.exchange! — Method

exchange!(emit, B, A): rewrite B A = x A B + R, with A < B. Passes the terms of R to emit(c, δs, ops...) and returns x.

source
QuantumAlgebra.expheis — Method
expheis(A, H, Ls=())

Return the right-hand side of the equation of motion of the expectation value $⟨A⟩$ (for an expectation value A or an expression of operators), i.e., the expectation value of the normal form of heisenberg_eom(A, H, Ls).

source
QuantumAlgebra.expval2corrs_inds — Method
expval2corrs_inds(N::Int)

for N operators, create an array of partitions (see OpPartition) that represents the terms in a sum of products of correlators. Each partition corresponds to a sum term. Internally, they are computed as tuples of tuples, see CorrTup_isless and CorrPerm_isless for details. The returned array and terms are sorted such that if the N operators are sorted, the represented expression is also sorted with the conventions of the QuantumAlgebra package. This allows to directly return a normal-ordered form.

source
QuantumAlgebra.hasind — Method
hasind(ind::QuIndex, A)

Return whether the index ind appears in A (a Kronecker delta, an operator, a parameter, a product of operators, an expectation value or a correlator).

source
QuantumAlgebra.ladder — Method

ladder(A): +1 for a creation operator, -1 for an annihilation operator, and 0 for other operators.

source
QuantumAlgebra.lookahead_contraction — Method

lookahead_contraction(A): whether A can contract with an operator that is not next to it in normal order (e.g., σˣ₁ in σˣ₁ σˣ₂ σʸ₁), if the operators in between commute with the later one.

source
QuantumAlgebra.lookahead_exchange — Method

lookahead_exchange(A): whether (for lookahead_contraction) the later operator can also be moved past operators in between that it does not commute with (which gives additional terms with their commutators), so that operators that can contract are always contracted.

source
QuantumAlgebra.maybe_same_site — Method

maybe_same_site(A, B): whether the operators A and B can act on the same mode, i.e., have the same name and indices that can all be equal.

source
QuantumAlgebra.normal_order! — Function
normal_order!(ops::BaseOpProduct, term_collector, shortcut_vacA_zero=false, prefactor=1)

Bring the operator product ops into normal order in place. Returns the prefactor p of the reordered product, such that the original prefactor*ops is equal to p*ops (after reordering) plus the terms that are added to term_collector (which still have to be normal ordered).

source
QuantumAlgebra.num_expr — Method
num_expr(x::Number)

The Julia expression for the coefficient x in julia_expression, which is a Float64 or a ComplexF64 by default. Packages that provide other number types (e.g., symbolic numbers) can add methods for them.

source
QuantumAlgebra.numlatex — Method
numlatex(x)

The object that is passed to Latexify for the coefficient x of a term in LaTeX output (x itself by default). Packages that provide other number types (e.g., symbolic numbers) can add methods for them, e.g., to put sums in parentheses.

source
QuantumAlgebra.numstring — Method
numstring(x::Number)

The string for printing the coefficient x of a term. Packages that provide other number types (e.g., symbolic numbers) can add methods for them, e.g., to put sums in parentheses.

source
QuantumAlgebra.ops — Method

ops(A::Union{ExpVal,Corr}): the product of operators inside the expectation value or correlator

source
QuantumAlgebra.qudit_op — Method

qudit_op(name, d, i, j, inds): the operator |i⟩⟨j| of a d-level system, with either i == 1 or j == 1 (but not both)

source
QuantumAlgebra.set_define_default_ops — Method
set_define_default_ops(t::Bool)

Set the preference "define_default_ops", which determines whether the default operators of the legacy interface (a, adag, f, fdag, σx, σy, σz, σp, σm) are defined when QuantumAlgebra is loaded (the default is true). The default operators are deprecated and will be removed in version 2.0; define operators with the macros instead (e.g., @boson a[:], see @boson).

Changing this preference requires restarting the Julia session to take effect.

source
QuantumAlgebra.set_quindices_type — Method
set_quindices_type(t::String)

Deprecated: indices are now always stored in a compact form that supports an arbitrary number of indices, so the "quindices_type" preference no longer has any effect.

source
QuantumAlgebra.simplify_number — Method
simplify_number(x::Number)

Simplify the coefficient x of a term when it is stored in a QuExpr (by default, floating-point numbers with integer values are converted to integers). Packages that provide other number types can add methods for them.

source
QuantumAlgebra.split_by_ind — Method
split_by_ind(ind::QuIndex, v)

Split the collection v (e.g., of operators or parameters) into the elements that do not contain the index ind and those that do (see hasind), and return both.

source
QuantumAlgebra.sumindex — Method
sumindex(i)

Return the summation index number i (printed as #ᵢ). Sums (see ∑) are stored with summation indices for the indices that are summed over, so that they cannot clash with other indices.

source
QuantumAlgebra.use_bracket_display — Function
use_bracket_display(t::Bool=true; set_preference=false)

Select whether operators and parameters are printed in the syntax of the interface with operator variables (see @boson), e.g., a†[i,j], g[i] and a (for true), or with parentheses, e.g., a†(ij), g(i) and a() (for false, the default in v1.x). If set_preference is true, the choice is stored with Preferences.jl for future sessions.

source
QuantumAlgebra.use_σpm — Function
use_σpm(t::Bool=true; set_preference=false)

Choose how the operators of two-level systems are represented: with the raising and lowering operators $σ^+$ and $σ^-$ (for true), or with the Pauli matrices $σ^x$, $σ^y$ and $σ^z$ (for false, the default). This applies to the operators that are created afterwards, e.g., σ[i] after @tls σ[:] (or σx after @tlsxyz σ, which is created when it is defined), which are then expressed in the chosen basis. If set_preference is true, the choice is stored with Preferences.jl (preference "use_σpm") for future sessions.

source
QuantumAlgebra.use_σxyz — Method
use_σxyz(; set_preference=false)

Represent the operators of two-level systems with the Pauli matrices $σ^x$, $σ^y$ and $σ^z$ (the default), equivalent to use_σpm(false; set_preference) (see use_σpm).

source
QuantumAlgebra.ϵ_ab — Method

ϵ_ab(A,B): for Pauli matrices σᵃ, σᵇ (with a≠b), return the third one, σᶜ, and the Levi-Civita symbol ϵ_abc

source