qnet.algebra.operator_algebra module

This module features classes and functions to define and manipulate symbolic Operator expressions. For more details see Operator Algebra.

For a list of all properties and methods of an operator object, see the documentation for the basic Operator class.

Summary

Classes:

Adjoint The symbolic Adjoint of an operator.
Commutator Commutator of two operators
Create Bosonic creation operator acting on a particular LocalSpace hs.
Destroy Bosonic annihilation operator acting on a particular LocalSpace hs.
Displace Unitary coherent displacement operator
Jminus \(\Op{J}_{-} = \Op{J}_x - i \op{J}_y\) is lowering ladder operator of a
Jplus \(\Op{J}_{+} = \Op{J}_x + i \op{J}_y\) is the raising ladder operator
Jz \(\Op{J}_z\) is the \(z\) component of a general spin operator acting
LocalOperator Base class for all kinds of operators that act locally, i.e.
LocalProjector A projector onto a specific level.
LocalSigma A local level flip operator operator acting on a particular LocalSpace hs.
NullSpaceProjector Returns a projection operator \(\mathcal{P}_{{\rm Ker} X}\) that
Operator The basic operator class, which fixes the abstract interface of operator objects and where possible also defines the default behavior under operations.
OperatorOperation Base class for Operations acting only on Operator arguments, for when the Hilbert space of the operation result is the product space of the operands.
OperatorPlus A sum of Operators
OperatorPlusMinusCC An operator plus or minus its complex conjugate
OperatorSymbol Symbolic operator, parametrized by an identifier string and an associated Hilbert space.
OperatorTimes A product of Operators that serves both as a product within a Hilbert space as well as a tensor product.
OperatorTrace Take the (partial) trace of an operator op ($Op{O}) over the degrees
Phase Unitary “phase” operator
PseudoInverse The symbolic pseudo-inverse \(X^+\) of an operator \(X\).
ScalarTimesOperator Multiply an operator by a scalar coefficient.
SingleOperatorOperation Base class for Operations that act on a single Operator
Squeeze Unitary Squeezing operator

Functions:

Jmjmcoeff Eigenvalue of the \(\Op{J}_{-}\) (Jminus) operator, as a Sympy
Jpjmcoeff Eigenvalue of the \(\Op{J}_{+}\) (Jplus) operator, as a Sympy expression.
Jzjmcoeff Eigenvalue of the \(\Op{J}_z\) (Jz) operator, as a Sympy expression.
X Pauli-type X-operator
Y Pauli-type Y-operator
Z Pauli-type Z-operator
adjoint Return the adjoint of an obj.
commutator_order Apply anti-commutative property of the commutator to apply a standard
create_operator_pm_cc Return a list of rules that can be used in an
decompose_space Simplifies OperatorTrace expressions over tensor-product spaces by turning it into iterated partial traces.
delegate_to_method Create a simplification rule that delegates the instantiation to the
disjunct_hs_zero Return ZeroOperator if all the operators in ops have a disjunct
expand_operator_pm_cc Return a list of rules that can be used in simplify to expand
factor_coeff Factor out coefficients of all factors.
factor_for_trace Given a LocalSpace ls to take the partial trace over and an operator op, factor the trace such that operators acting on disjoint degrees of freedom are pulled out of the trace.
get_coeffs Create a dictionary with all Operator terms of the expression (understood as a sum) as keys and their coefficients as values.
implied_local_space Return a simplification that converts the positional argument
scalar_free_symbols Return all free symbols from any symbolic operand
scalars_to_op Convert any scalar \(\alpha\) in ops into an operator $alpha
simplify_scalar Simplify all occurences of scalar expressions in s
space Gives the associated HilbertSpace with an object.

Data:

II IdentityOperator constant (singleton) object.
IdentityOperator IdentityOperator constant (singleton) object.
ZeroOperator ZeroOperator constant (singleton) object.

__all__: Adjoint, Commutator, Create, Destroy, Displace, II, IdentityOperator, Jminus, Jmjmcoeff, Jpjmcoeff, Jplus, Jz, Jzjmcoeff, LocalOperator, LocalProjector, LocalSigma, NullSpaceProjector, Operator, OperatorOperation, OperatorPlus, OperatorPlusMinusCC, OperatorSymbol, OperatorTimes, OperatorTrace, Phase, PseudoInverse, ScalarTimesOperator, SingleOperatorOperation, Squeeze, X, Y, Z, ZeroOperator, adjoint, create_operator_pm_cc, decompose_space, expand_operator_pm_cc, factor_coeff, factor_for_trace, get_coeffs, scalar_free_symbols, simplify_scalar, space

Reference

qnet.algebra.operator_algebra.implied_local_space(*, arg_index=None, keys=None)[source]

Return a simplification that converts the positional argument arg_index from (str, int) to LocalSpace, as well as any keyword argument with one of the given keys

qnet.algebra.operator_algebra.delegate_to_method(mtd)[source]

Create a simplification rule that delegates the instantiation to the method mtd of the operand (if defined)

qnet.algebra.operator_algebra.scalars_to_op(cls, ops, kwargs)[source]

Convert any scalar \(\alpha\) in ops into an operator $alpha identity$

qnet.algebra.operator_algebra.disjunct_hs_zero(cls, ops, kwargs)[source]

Return ZeroOperator if all the operators in ops have a disjunct Hilbert space, or an unchanged ops, kwargs otherwise

qnet.algebra.operator_algebra.commutator_order(cls, ops, kwargs)[source]

Apply anti-commutative property of the commutator to apply a standard ordering of the commutator arguments

class qnet.algebra.operator_algebra.Operator[source]

Bases: object

The basic operator class, which fixes the abstract interface of operator objects and where possible also defines the default behavior under operations. Any operator contains an associated HilbertSpace object, on which it is taken to act non-trivially.

space

The HilbertSpace on which the operator acts non-trivially

adjoint()[source]

The Hermitian adjoint of the operator.

conjugate()

The Hermitian adjoint of the operator.

dag()

The Hermitian adjoint of the operator.

pseudo_inverse()[source]

The pseudo-Inverse of the Operator, i.e., it inverts the operator on the orthogonal complement of its nullspace

expand()[source]

Expand out distributively all products of sums. Note that this does not expand out sums of scalar coefficients.

Returns:A fully expanded sum of operators.
Return type:Operator
expand_in_basis(basis_states=None, hermitian=False)[source]

Write the operator as an expansion into all KetBras spanned by basis_states.

Parameters:
  • basis_states (list or None) – List of basis states (Ket instances) into which to expand the operator. If None, use the operator’s space.basis_states
  • hermitian (bool) – If True, assume that the operator is Hermitian and represent all elements in the lower triangle of the expansion via OperatorPlusMinusCC. This is meant to enhance readability
Raises:

BasisNotSetError – If basis_states is None and the operator’s Hilbert space has no well-defined basis

Example

>>> hs = LocalSpace(1, basis=('g', 'e'))
>>> op = LocalSigma('g', 'e', hs=hs) + LocalSigma('e', 'g', hs=hs)
>>> from qnet.printing import ascii
>>> print(ascii(op, sig_as_ketbra=False))
sigma_e,g^(1) + sigma_g,e^(1)
>>> print(ascii(op.expand_in_basis()))
|e><g|^(1) + |g><e|^(1)
>>> print(ascii(op.expand_in_basis(hermitian=True)))
|g><e|^(1) + c.c.
simplify_scalar()[source]

Simplify all scalar coefficients within the Operator expression.

Returns:The simplified expression.
Return type:Operator
diff(sym, n=1, expand_simplify=True)[source]

Differentiate by scalar parameter sym.

Parameters:
  • sym (Symbol) – What to differentiate by.
  • n (int) – How often to differentiate
  • expand_simplify (bool) – Whether to simplify the result.
Return (Operator):
 

The n-th derivative.

series_expand(param, about, order)[source]

Expand the operator expression as a truncated power series in a scalar parameter.

Parameters:
  • param (Symbol) – Expansion parameter
  • about (SCALAR_TYPES) – Point about which to expand
  • order (int) – Maximum order of expansion (>= 0)
Returns:

tuple of length order + 1, where the entries are the expansion coefficients (instances of Operator)

class qnet.algebra.operator_algebra.LocalOperator(*args, hs)[source]

Bases: qnet.algebra.operator_algebra.Operator, qnet.algebra.abstract_algebra.Expression

Base class for all kinds of operators that act locally, i.e. only on a single degree of freedom.

All LocalOperator instances have a fixed associated identifier (symbol) that is used when printing that operator. A custom identifier can be useed through the associated LocalSpace’s local_identifiers parameter. For example:

>>> from qnet.printing import ascii
>>> from qnet.algebra.operator_algebra import Destroy
>>> hs1_custom = LocalSpace(1, local_identifiers={'Destroy': 'b'})
>>> b = Destroy(hs=hs1_custom)
>>> ascii(b)
'b^(1)'
space

Hilbert space of the operator (LocalSpace instance)

args

The positional arguments used for instantiating the operator

kwargs

The keyword arguments used for instantiating the operator

identifier

The identifier (symbol) that is used when printing the operator.

A custom identifier can be used through the associated LocalSpace’s local_identifiers parameter. For example:

>>> from qnet.algebra.operator_algebra import Destroy
>>> a = Destroy(hs=1)
>>> a.identifier
'a'
>>> hs1_custom = LocalSpace(1, local_identifiers={'Destroy': 'b'})
>>> b = Destroy(hs=hs1_custom)
>>> b.identifier
'b'
>>> from qnet.printing import ascii; ascii(b)
'b^(1)'
all_symbols()[source]

Set of symbols used in the operator

class qnet.algebra.operator_algebra.OperatorOperation(*operands, **kwargs)[source]

Bases: qnet.algebra.operator_algebra.Operator, qnet.algebra.abstract_algebra.Operation

Base class for Operations acting only on Operator arguments, for when the Hilbert space of the operation result is the product space of the operands.

space

Hilbert space of the operation result

class qnet.algebra.operator_algebra.SingleOperatorOperation(op, **kwargs)[source]

Bases: qnet.algebra.operator_algebra.Operator, qnet.algebra.abstract_algebra.Operation

Base class for Operations that act on a single Operator

space

Hilbert space for the operation result

operand

The operator that the operation acts on

class qnet.algebra.operator_algebra.OperatorSymbol(identifier, *, hs)[source]

Bases: qnet.algebra.operator_algebra.Operator, qnet.algebra.abstract_algebra.Expression

Symbolic operator, parametrized by an identifier string and an associated Hilbert space.

Parameters:
args

The positional arguments used for instantiating the operator

kwargs

The keyword arguments used for instantiating the operator

space

Hilbert space of the operator

all_symbols()[source]
qnet.algebra.operator_algebra.IdentityOperator = IdentityOperator[source]

IdentityOperator constant (singleton) object.

qnet.algebra.operator_algebra.II = IdentityOperator

IdentityOperator constant (singleton) object.

qnet.algebra.operator_algebra.ZeroOperator = ZeroOperator[source]

ZeroOperator constant (singleton) object.

class qnet.algebra.operator_algebra.Destroy(*, hs)[source]

Bases: qnet.algebra.operator_algebra.LocalOperator

Bosonic annihilation operator acting on a particular LocalSpace hs.

It obeys the bosonic commutation relation:

>>> Destroy(hs=1) * Create(hs=1) - Create(hs=1) * Destroy(hs=1)
IdentityOperator
>>> Destroy(hs=1) * Create(hs=2) - Create(hs=2) * Destroy(hs=1)
ZeroOperator
identifier

The identifier (symbols) that is used when printing the annihilation operator. This is identical to the identifier of Create. A custom identifier for both Destroy and Create can be set through the local_identifiers parameter of the associated Hilbert space:

>>> from qnet.algebra.operator_algebra import Create, Destroy
>>> hs_custom = LocalSpace(0, local_identifiers={'Destroy': 'b'})
>>> Create(hs=hs_custom).identifier
'b'
>>> Destroy(hs=hs_custom).identifier
'b'
class qnet.algebra.operator_algebra.Create(*, hs)[source]

Bases: qnet.algebra.operator_algebra.LocalOperator

Bosonic creation operator acting on a particular LocalSpace hs. It is the adjoint of Destroy.

identifier

The identifier (symbols) that is used when printing the creation operator. This is identical to the identifier of Destroy

class qnet.algebra.operator_algebra.Jz(*, hs)[source]

Bases: qnet.algebra.operator_algebra.LocalOperator

\(\Op{J}_z\) is the \(z\) component of a general spin operator acting on a particular LocalSpace hs of freedom with well defined spin quantum number \(s\). It is Hermitian:

>>> print(ascii(Jz(hs=1).adjoint()))
J_z^(1)

Jz, Jplus and Jminus satisfy the angular momentum commutator algebra:

>>> print(ascii((Jz(hs=1) * Jplus(hs=1) -
...              Jplus(hs=1)*Jz(hs=1)).expand()))
J_+^(1)

>>> print(ascii((Jz(hs=1) * Jminus(hs=1) -
...              Jminus(hs=1)*Jz(hs=1)).expand()))
-J_-^(1)

>>> print(ascii((Jplus(hs=1) * Jminus(hs=1)
...              - Jminus(hs=1)*Jplus(hs=1)).expand()))
2 * J_z^(1)

Printers should represent this operator with the default identifier:

>>> Jz._identifier
'J_z'

A custom identifier may be define using hs’s local_identifiers argument.

class qnet.algebra.operator_algebra.Jplus(*, hs)[source]

Bases: qnet.algebra.operator_algebra.LocalOperator

\(\Op{J}_{+} = \Op{J}_x + i \op{J}_y\) is the raising ladder operator of a general spin operator acting on a particular LocalSpace hs with well defined spin quantum number \(s\). It’s adjoint is the lowering operator:

>>> print(ascii(Jplus(hs=1).adjoint()))
J_-^(1)

Jz, Jplus and Jminus satisfy that angular momentum commutator algebra, see Jz

Printers should represent this operator with the default identifier:

>>> Jplus._identifier
'J_+'

A custom identifier may be define using hs’s local_identifiers argument.

class qnet.algebra.operator_algebra.Jminus(*, hs)[source]

Bases: qnet.algebra.operator_algebra.LocalOperator

\(\Op{J}_{-} = \Op{J}_x - i \op{J}_y\) is lowering ladder operator of a general spin operator acting on a particular LocalSpace hs with well defined spin quantum number \(s\). It’s adjoint is the raising operator:

>>> print(ascii(Jminus(hs=1).adjoint()))
J_+^(1)

Jz, Jplus and Jminus satisfy that angular momentum commutator algebra, see Jz.

Printers should represent this operator with the default identifier:

>>> Jminus._identifier
'J_-'

A custom identifier may be define using hs’s local_identifiers argument.

class qnet.algebra.operator_algebra.Phase(phi, *, hs)[source]

Bases: qnet.algebra.operator_algebra.LocalOperator

Unitary “phase” operator

\[\op{P}_{\rm hs}(\phi) = \exp\left(i \phi \Op{a}_{\rm hs}^\dagger \Op{a}_{\rm hs}\right)\]

where \(a_{\rm hs}\) is the annihilation operator acting on the LocalSpace hs.

Printers should represent this operator with the default identifier:

>>> Phase._identifier
'Phase'

A custom identifier may be define using hs’s local_identifiers argument.

phi

Phase \(\phi\)

args

List of arguments of the operator, containing the phase \(\phi\) as the only element

all_symbols()[source]
class qnet.algebra.operator_algebra.Displace(alpha, *, hs)[source]

Bases: qnet.algebra.operator_algebra.LocalOperator

Unitary coherent displacement operator

\[\op{D}_{\rm hs}(\alpha) = \exp\left({\alpha \Op{a}_{\rm hs}^\dagger - \alpha^* \Op{a}_{\rm hs}}\right)\]

where \(\Op{a}_{\rm hs}\) is the annihilation operator acting on the LocalSpace hs.

Printers should represent this operator with the default identifier:

>>> Displace._identifier
'D'

A custom identifier may be define using hs’s local_identifiers argument.

alpha

Displacement amplitude \(\alpha\)

args

List of arguments of the operator, containing the displacement amplitude \(\alpha\) as the only element

all_symbols()[source]
class qnet.algebra.operator_algebra.Squeeze(eta, *, hs)[source]

Bases: qnet.algebra.operator_algebra.LocalOperator

Unitary Squeezing operator

\[\Op{S}_{\rm hs}(\eta) = \exp {\left( \frac{\eta}{2} {\Op{a}_{\rm hs}^\dagger}^2 - \frac{\eta^*}{2} {\Op{a}_{\rm hs}}^2 \right)}\]

where \(\Op{a}_{\rm hs}\) is the annihilation operator acting on the LocalSpace hs.

Printers should represent this operator with the default identifier:

>>> Squeeze._identifier
'Squeeze'

A custom identifier may be define using hs’s local_identifiers argument.

eta

sqeezing parameter \(\eta\)

args
all_symbols()[source]

List of arguments of the operator, containing the squeezing parameter \(\eta\) as the only element

class qnet.algebra.operator_algebra.LocalSigma(j, k, *, hs)[source]

Bases: qnet.algebra.operator_algebra.LocalOperator

A local level flip operator operator acting on a particular LocalSpace hs.

\[\Op{\sigma}_{jk}^{\rm hs} = \left| j\right\rangle_{\rm hs} \left \langle k \right |_{\rm hs}\]

For \(j=k\) this becomes a projector \(\Op{P}_k\) onto the eigenstate \(\ket{k}\); see LocalProjector.

Parameters:
  • j (int or str) – The label or index identifying \(\ket{j}\)
  • k (int or str) – The label or index identifying \(\ket{k}\)
  • hs (HilbertSpace) – The Hilbert space on which the operator acts

Note

The parameters j or k may be an integer or a string. A string refers to the label of an eigenstate in the basis of hs, which needs to be set. An integer refers to the (zero-based) index of eigenstate of the Hilbert space. This works if hs has an unknown dimension.

Raises:ValueError – If j or k are invalid value for the given hs

Printers should represent this operator either in braket notation, or using the operator identifier

>>> LocalSigma(0, 0, hs=0).identifier
'sigma'
j

label/index of eigenstate \(\ket{j}\)

k

label/index of eigenstate \(\ket{k}\)

args

The two eigenstate labels j and k that the operator connects

index_j

Index j or (zero-based) index of the label j in the basis

index_k

Index k or (zero-based) index of the label k in the basis

raise_jk(j_incr=0, k_incr=0)[source]

Return a new LocalSigma instance with incremented j, k, on the same Hilbert space:

\[\Op{\sigma}_{jk}^{\rm hs} \rightarrow \Op{\sigma}_{j'k'}^{\rm hs}\]

This is the result of multiplying \(\Op{\sigma}_{jk}^{\rm hs}\) with any raising or lowering operators.

If \(j'\) or \(k'\) are outside the Hilbert space \({\rm hs}\), the result is the ZeroOperator .

Parameters:
  • j_incr (int) – The increment between labels \(j\) and \(j'\)
  • k_incr (int) – The increment between labels \(k\) and \(k'\). Both increments may be negative.
class qnet.algebra.operator_algebra.LocalProjector(j, *, hs)[source]

Bases: qnet.algebra.operator_algebra.LocalSigma

A projector onto a specific level.

Parameters:
  • j (int or str) – The label or index identifying the state onto which is projected
  • hs (HilbertSpace) – The Hilbert space on which the operator acts
args

One-element tuple containing eigenstate label j that the projector projects onto

class qnet.algebra.operator_algebra.OperatorPlus(*operands, **kwargs)[source]

Bases: qnet.algebra.operator_algebra.OperatorOperation

A sum of Operators

Parameters:operands (list) – Operator summands
neutral_element = ZeroOperator

ZeroOperator constant (singleton) object.

order_key

alias of FullCommutativeHSOrder

class qnet.algebra.operator_algebra.OperatorTimes(*operands, **kwargs)[source]

Bases: qnet.algebra.operator_algebra.OperatorOperation

A product of Operators that serves both as a product within a Hilbert space as well as a tensor product.

Parameters:operands (list) – Operator factors
neutral_element = IdentityOperator

IdentityOperator constant (singleton) object.

order_key

alias of DisjunctCommutativeHSOrder

factor_for_space(spc)[source]
class qnet.algebra.operator_algebra.ScalarTimesOperator(coeff, term)[source]

Bases: qnet.algebra.operator_algebra.Operator, qnet.algebra.abstract_algebra.Operation

Multiply an operator by a scalar coefficient.

Parameters:
static has_minus_prefactor(c)[source]

For a scalar object c, determine whether it is prepended by a “-” sign.

space
coeff
term
all_symbols()[source]
class qnet.algebra.operator_algebra.Commutator(A, B)[source]

Bases: qnet.algebra.operator_algebra.OperatorOperation

Commutator of two operators

\[[\Op{A}, \Op{B}] = \Op{A}\Op{B} - \Op{A}\Op{B}\]
order_key

alias of FullCommutativeHSOrder

A

Left side of the commutator

B

Left side of the commutator

class qnet.algebra.operator_algebra.OperatorTrace(op, *, over_space)[source]

Bases: qnet.algebra.operator_algebra.SingleOperatorOperation

Take the (partial) trace of an operator op ($Op{O}) over the degrees of freedom of a Hilbert space over_space ($mathcal{H}$):

\[{\rm Tr}_{\mathcal{H}} \Op{O}\]
Parameters:
  • over_space (HilbertSpace) – The degrees of freedom to trace over
  • op (Opwerator) – The operator to take the trace of.
kwargs
operand
space
all_symbols()[source]
class qnet.algebra.operator_algebra.Adjoint(op, **kwargs)[source]

Bases: qnet.algebra.operator_algebra.SingleOperatorOperation

The symbolic Adjoint of an operator.

Parameters:op (Operator) – The operator to take the adjoint of.
class qnet.algebra.operator_algebra.OperatorPlusMinusCC(op, *, sign=1)[source]

Bases: qnet.algebra.operator_algebra.SingleOperatorOperation

An operator plus or minus its complex conjugate

kwargs
minimal_kwargs
class qnet.algebra.operator_algebra.PseudoInverse(op, **kwargs)[source]

Bases: qnet.algebra.operator_algebra.SingleOperatorOperation

The symbolic pseudo-inverse \(X^+\) of an operator \(X\). It is defined via the relationship

\[\begin{split}X X^+ X = X \\ X^+ X X^+ = X^+ \\ (X^+ X)^\dagger = X^+ X \\ (X X^+)^\dagger = X X^+\end{split}\]
Parameters:X (Operator) – The operator to take the adjoint of.
class qnet.algebra.operator_algebra.NullSpaceProjector(op, **kwargs)[source]

Bases: qnet.algebra.operator_algebra.SingleOperatorOperation

Returns a projection operator \(\mathcal{P}_{{\rm Ker} X}\) that projects onto the nullspace of its operand

\[\begin{split}X \mathcal{P}_{{\rm Ker} X} = 0 \Leftrightarrow X (1 - \mathcal{P}_{{\rm Ker} X}) = X\\ \mathcal{P}_{{\rm Ker} X}^\dagger = \mathcal{P}_{{\rm Ker} X} = \mathcal{P}_{{\rm Ker} X}^2\end{split}\]
Parameters:X (Operator) – Operator argument
qnet.algebra.operator_algebra.X(local_space, states=('h', 'g'))[source]

Pauli-type X-operator

Parameters:
  • local_space (LocalSpace) – Associated Hilbert space.
  • states (tuple with two elements of type int or str) – The qubit state labels for the basis states \(\left\{|0\rangle, |1\rangle \right\}\), where \(Z|0\rangle = +|0\rangle\), default = ('h', 'g').
Returns:

Local X-operator as a linear combination of LocalSigma

Return type:

Operator

qnet.algebra.operator_algebra.Y(local_space, states=('h', 'g'))[source]

Pauli-type Y-operator

Parameters:
  • local_space (LocalSpace) – Associated Hilbert space.
  • states (tuple with two elements of type int or str) – The qubit state labels for the basis states \(\left\{|0\rangle, |1\rangle \right\}\), where \(Z|0\rangle = +|0\rangle\), default = ('h', 'g').
Returns:

Local Y-operator as a linear combination of LocalSigma

Return type:

Operator

qnet.algebra.operator_algebra.Z(local_space, states=('h', 'g'))[source]

Pauli-type Z-operator

Parameters:
  • local_space (LocalSpace) – Associated Hilbert space.
  • states (tuple with two elements of type int or str) – The qubit state labels for the basis states \(\left\{|0\rangle, |1\rangle \right\}\), where \(Z|0\rangle = +|0\rangle\), default = ('h', 'g').
Returns:

Local Z-operator as a linear combination of LocalSigma

Return type:

Operator

qnet.algebra.operator_algebra.factor_for_trace(ls, op)[source]

Given a LocalSpace ls to take the partial trace over and an operator op, factor the trace such that operators acting on disjoint degrees of freedom are pulled out of the trace. If the operator acts trivially on ls the trace yields only a pre-factor equal to the dimension of ls. If there are LocalSigma operators among a product, the trace’s cyclical property is used to move to sandwich the full product by LocalSigma operators:

\[{\rm Tr} A \sigma_{jk} B = {\rm Tr} \sigma_{jk} B A \sigma_{jj}\]
Parameters:
  • ls (HilbertSpace) – Degree of Freedom to trace over
  • op (Operator) – Operator to take the trace of
Returns:

The (partial) trace over the operator’s spc-degrees of freedom

Return type:

Operator

qnet.algebra.operator_algebra.decompose_space(H, A)[source]

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

Parameters:H (ProductSpace) – The full space.
Returns:Iterative partial trace expression
Return type:Operator
qnet.algebra.operator_algebra.get_coeffs(expr, expand=False, epsilon=0.0)[source]

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

The returned object is a defaultdict that return 0. if a term/key doesn’t exist. :param expr: The operator expression to get all coefficients from. :param expand: Whether to expand the expression distributively. :param epsilon: If non-zero, drop all Operators with coefficients that have absolute value less than epsilon. :return: A dictionary of {op1: coeff1, op2: coeff2, …} :rtype: dict

qnet.algebra.operator_algebra.space(obj)[source]

Gives the associated HilbertSpace with an object. Also works for SCALAR_TYPES

qnet.algebra.operator_algebra.simplify_scalar(s)[source]

Simplify all occurences of scalar expressions in s

Parameters:s (Expression or SympyBasic) – The expression to simplify.
Returns:The simplified version.
Return type:Expression or SympyBasic
qnet.algebra.operator_algebra.scalar_free_symbols(*operands)[source]

Return all free symbols from any symbolic operand

qnet.algebra.operator_algebra.factor_coeff(cls, ops, kwargs)[source]

Factor out coefficients of all factors.

qnet.algebra.operator_algebra.adjoint(obj)[source]

Return the adjoint of an obj.

qnet.algebra.operator_algebra.Jpjmcoeff(ls, m, shift=False)[source]

Eigenvalue of the \(\Op{J}_{+}\) (Jplus) operator, as a Sympy expression.

\[\Op{J}_{+} \ket{s, m} = \sqrt{s (s+1) - m (m+1)} \ket{s, m}\]

where the multiplicity \(s\) is implied by the size of the Hilbert space ls: there are \(2s+1\) eigenstates with \(m = -s, -s+1, \dots, s\).

Parameters:
  • ls (LocalSpace) – The Hilbert space in which the \(\Op{J}_{+}\) operator acts.
  • m (Any) – If str, the label of the basis state of hs to which the operator is applied. If integer together with shift=True, the zero-based index of the basis state. Otherwise, directly the quantum number \(m\).
  • shift (bool) – If True for a integer value of m, treat m as the zero-based index of the basis state (i.e., shift m down by \(s\) to obtain the quantum number $m$)
qnet.algebra.operator_algebra.Jzjmcoeff(ls, m, shift)[source]

Eigenvalue of the \(\Op{J}_z\) (Jz) operator, as a Sympy expression.

\[\Op{J}_{z} \ket{s, m} = m \ket{s, m}\]

See also Jpjmcoeff().

qnet.algebra.operator_algebra.Jmjmcoeff(ls, m, shift)[source]

Eigenvalue of the \(\Op{J}_{-}\) (Jminus) operator, as a Sympy expression

\[\Op{J}_{-} \ket{s, m} = \sqrt{s (s+1) - m (m-1)} \ket{s, m}\]

See also Jpjmcoeff().

qnet.algebra.operator_algebra.create_operator_pm_cc()[source]

Return a list of rules that can be used in an extra_binary_rules() context for OperatorPlus in order to combine suitable terms into a OperatorPlusMinusCC instance:

>>> A = OperatorSymbol('A', hs=1)
>>> sum = A + A.dag()
>>> from qnet.algebra.abstract_algebra import extra_binary_rules
>>> with extra_binary_rules(OperatorPlus, create_operator_pm_cc()):
...     sum2 = sum.simplify()
>>> print(ascii(sum2))
A^(1) + c.c.

The inverse is done through expand_operator_pm_cc():

>>> print(ascii(sum2.simplify(rules=expand_operator_pm_cc())))
A^(1) + A^(1)H
qnet.algebra.operator_algebra.expand_operator_pm_cc()[source]

Return a list of rules that can be used in simplify to expand instances of OperatorPlusMinusCC

Inverse of create_operator_pm_cc().