qalgebra.core.state_algebra module¶
This module implements the algebra of states in a Hilbert space
For more details see State (Ket-) Algebra.
Summary¶
Classes:
Local basis state, identified by index or label |
|
The associated dual/adjoint state for any ket |
|
The symbolic inner product between two states |
|
Local coherent state, labeled by a complex amplitude \(\alpha\). |
|
Outer product of two states |
|
Indexed sum over Kets. |
|
Sum of states. |
|
Symbolic state. |
|
A state on a |
|
Product of an operator and a state. |
|
Product of a |
|
Base class for states in a Hilbert space |
|
Symbolic partial derivative of a state |
|
A tensor product of kets. |
Data:
TrivialKet constant (singleton) object. |
|
ZeroKet constant (singleton) object for the null-state. |
__all__
: BasisKet
, Bra
, BraKet
, CoherentStateKet
, KetBra
, KetIndexedSum
, KetPlus
, KetSymbol
, LocalKet
, OperatorTimesKet
, ScalarTimesKet
, State
, StateDerivative
, TensorKet
, TrivialKet
, ZeroKet
Reference¶
-
class
qalgebra.core.state_algebra.
BasisKet
(label_or_index, *, hs)[source]¶ Bases:
qalgebra.core.state_algebra.LocalKet
,qalgebra.core.state_algebra.KetSymbol
Local basis state, identified by index or label
Basis kets are orthornormal, and the
next()
andprev()
methods can be used to move between basis states.- Parameters
label_or_index – If str, the label of the basis state (must be an element of hs.basis_labels). If int, the (zero-based) index of the basis state. This works if hs has an unknown dimension. For a symbolic index, label_or_index can be an instance of an appropriate subclass of
SymbolicLabelBase
hs (LocalSpace) – The Hilbert space in which the basis is defined
- Raises
ValueError – if label_or_index is not in the Hilbert space
TypeError – if label_or_index is not of an appropriate type
BasisNotSetError – if label_or_index is a str but no basis is defined for hs
Note
Basis states that are instantiated via a label or via an index are equivalent:
>>> hs = LocalSpace('tls', basis=('g', 'e')) >>> BasisKet('g', hs=hs) == BasisKet(0, hs=hs) True >>> print(ascii(BasisKet(0, hs=hs))) |g>^(tls)
When instantiating the
BasisKet
viacreate()
, an integer label outside the range of the underlying Hilbert space results in aZeroKet
:>>> BasisKet.create(-1, hs=0) ZeroKet >>> BasisKet.create(2, hs=LocalSpace('tls', dimension=2)) ZeroKet
-
simplifications
= [<function basis_ket_zero_outside_hs>]¶
-
property
args
¶ Tuple containing label_or_index as its only element.
-
property
index
¶ The index of the state in the Hilbert space basis.
>>> hs = LocalSpace('tls', basis=('g', 'e')) >>> BasisKet('g', hs=hs).index 0 >>> BasisKet('e', hs=hs).index 1 >>> BasisKet(1, hs=hs).index 1
For a
BasisKet
with an indexed label, this may return a sympy expression:>>> hs = SpinSpace('s', spin='3/2') >>> i = symbols('i', cls=IdxSym) >>> lbl = SpinIndex(i/2, hs) >>> ket = BasisKet(lbl, hs=hs) >>> ket.index i/2 + 3/2
-
next
(n=1)[source]¶ Move up by n steps in the Hilbert space.
>>> hs = LocalSpace('tls', basis=('g', 'e')) >>> ascii(BasisKet('g', hs=hs).next()) '|e>^(tls)' >>> ascii(BasisKet(0, hs=hs).next()) '|e>^(tls)'
We can also go multiple steps:
>>> hs = LocalSpace('ten', dimension=10) >>> ascii(BasisKet(0, hs=hs).next(2)) '|2>^(ten)'
An increment that leads out of the Hilbert space returns zero:
>>> BasisKet(0, hs=hs).next(10) ZeroKet
-
class
qalgebra.core.state_algebra.
Bra
(ket)[source]¶ Bases:
qalgebra.core.state_algebra.State
,qalgebra.core.abstract_quantum_algebra.QuantumAdjoint
The associated dual/adjoint state for any ket
-
property
bra
¶ The bra associated with a ket
-
property
isket
¶ False, by defintion
-
property
isbra
¶ True, by definition
-
property
label
¶
-
property
-
class
qalgebra.core.state_algebra.
BraKet
(bra, ket)[source]¶ Bases:
qalgebra.core.scalar_algebra.ScalarExpression
,qalgebra.core.abstract_algebra.Operation
The symbolic inner product between two states
This mathermatically corresponds to:
\[\langle b | k \rangle\]which we define to be linear in the state \(k\) and anti-linear in \(b\).
- Parameters
-
simplifications
= [<function match_replace>]¶
-
property
ket
¶ The ket of the braket
-
class
qalgebra.core.state_algebra.
CoherentStateKet
(ampl, *, hs)[source]¶ Bases:
qalgebra.core.state_algebra.LocalKet
Local coherent state, labeled by a complex amplitude \(\alpha\).
\[\ket{\alpha} = \exp\left[ \alpha \Op{a}^\dagger - \alpha^* \Op{a} \right] \ket{0} = \Op{D}(\alpha) \ket{0}\]where \(\Op{D}\) is the displacement operator, see
Displace
.- Parameters
hs (LocalSpace) – The local Hilbert space degree of freedom.
ampl (Scalar) – The coherent displacement amplitude \(\alpha\).
-
property
args
¶ The tuple of positional arguments for the instantiation of the Expression
-
property
ampl
¶
-
class
qalgebra.core.state_algebra.
State
(*args, **kwargs)[source]¶ Bases:
qalgebra.core.abstract_quantum_algebra.QuantumExpression
Base class for states in a Hilbert space
-
property
isket
¶ Whether the state represents a ket
-
property
isbra
¶ Wether the state represents a bra (adjoint ket)
-
property
bra
¶ The bra associated with a ket
-
property
ket
¶ The ket associated with a bra
-
property
-
class
qalgebra.core.state_algebra.
KetBra
(ket, bra)[source]¶ Bases:
qalgebra.core.operator_algebra.Operator
,qalgebra.core.abstract_algebra.Operation
Outer product of two states
- Parameters
-
simplifications
= [<function match_replace>]¶
-
property
ket
¶ The left factor in the product
-
property
bra
¶ The co-state right factor in the product
This is a
Bra
instance (unlike the bra given to the constructor
-
property
space
¶ The Hilbert space of the states being multiplied
-
class
qalgebra.core.state_algebra.
KetPlus
(*operands)[source]¶ Bases:
qalgebra.core.state_algebra.State
,qalgebra.core.abstract_quantum_algebra.QuantumPlus
Sum of states.
-
simplifications
= [<function accept_bras>, <function assoc>, <function orderby>, <function collect_summands>, <function match_replace_binary>]¶
-
order_key
¶
-
-
class
qalgebra.core.state_algebra.
KetSymbol
(label, *sym_args, hs)[source]¶ Bases:
qalgebra.core.abstract_quantum_algebra.QuantumSymbol
,qalgebra.core.state_algebra.State
Symbolic state.
See
QuantumSymbol
.
-
class
qalgebra.core.state_algebra.
LocalKet
(*args, hs)[source]¶ Bases:
qalgebra.core.state_algebra.State
A state on a
LocalSpace
.This does not include operations, even if these operations only involve states acting on the same local space
-
property
space
¶ The
HilbertSpace
on which the operator acts non-trivially
-
property
kwargs
¶ The dictionary of keyword-only arguments for the instantiation of the Expression
-
property
-
class
qalgebra.core.state_algebra.
OperatorTimesKet
(operator, ket)[source]¶ Bases:
qalgebra.core.state_algebra.State
,qalgebra.core.abstract_algebra.Operation
Product of an operator and a state.
-
simplifications
= [<function match_replace>]¶
-
property
space
¶ The
HilbertSpace
on which the operator acts non-trivially
-
property
operator
¶
-
property
ket
¶ The ket associated with a bra
-
-
class
qalgebra.core.state_algebra.
ScalarTimesKet
(coeff, term)[source]¶ Bases:
qalgebra.core.state_algebra.State
,qalgebra.core.abstract_quantum_algebra.ScalarTimesQuantumExpression
Product of a
Scalar
coefficient and a ket-
simplifications
= [<function match_replace>]¶
-
classmethod
create
(coeff, term)[source]¶ Instantiate while applying automatic simplifications.
Instead of directly instantiating cls, it is recommended to use
create()
, which applies simplifications to the args and keyword arguments according to the simplifications class attribute, and returns an appropriate object (which may or may not be an instance of the original cls).Two simplifications of particular importance are
match_replace()
andmatch_replace_binary()
which apply rule-based simplifications.The
temporary_rules()
context manager may be used to allow temporary modification of the automatic simplifications thatcreate()
uses, in particular the rules formatch_replace()
andmatch_replace_binary()
. Inside the managed context, the simplifications class attribute may be modified and rules can be managed withadd_rule()
anddel_rules()
.
-
-
class
qalgebra.core.state_algebra.
TensorKet
(*operands)[source]¶ Bases:
qalgebra.core.state_algebra.State
,qalgebra.core.abstract_quantum_algebra.QuantumTimes
A tensor product of kets.
Each ket must belong to different degree of freedom (
LocalSpace
).-
simplifications
= [<function accept_bras>, <function assoc>, <function orderby>, <function filter_neutral>, <function match_replace_binary>]¶
-
order_key
¶
-
classmethod
create
(*ops)[source]¶ Instantiate while applying automatic simplifications.
Instead of directly instantiating cls, it is recommended to use
create()
, which applies simplifications to the args and keyword arguments according to the simplifications class attribute, and returns an appropriate object (which may or may not be an instance of the original cls).Two simplifications of particular importance are
match_replace()
andmatch_replace_binary()
which apply rule-based simplifications.The
temporary_rules()
context manager may be used to allow temporary modification of the automatic simplifications thatcreate()
uses, in particular the rules formatch_replace()
andmatch_replace_binary()
. Inside the managed context, the simplifications class attribute may be modified and rules can be managed withadd_rule()
anddel_rules()
.
-
-
qalgebra.core.state_algebra.
TrivialKet
= TrivialKet[source]¶ TrivialKet constant (singleton) object. This is the neutral element under the state tensor-product.
-
qalgebra.core.state_algebra.
ZeroKet
= ZeroKet[source]¶ ZeroKet constant (singleton) object for the null-state.
-
class
qalgebra.core.state_algebra.
KetIndexedSum
(term, *, ranges)[source]¶ Bases:
qalgebra.core.state_algebra.State
,qalgebra.core.abstract_quantum_algebra.QuantumIndexedSum
Indexed sum over Kets.
-
simplifications
= [<function assoc_indexed>, <function indexed_sum_over_kronecker>, <function indexed_sum_over_const>, <function match_replace>]¶
-
classmethod
create
(term, *, ranges)[source]¶ Instantiate while applying automatic simplifications.
Instead of directly instantiating cls, it is recommended to use
create()
, which applies simplifications to the args and keyword arguments according to the simplifications class attribute, and returns an appropriate object (which may or may not be an instance of the original cls).Two simplifications of particular importance are
match_replace()
andmatch_replace_binary()
which apply rule-based simplifications.The
temporary_rules()
context manager may be used to allow temporary modification of the automatic simplifications thatcreate()
uses, in particular the rules formatch_replace()
andmatch_replace_binary()
. Inside the managed context, the simplifications class attribute may be modified and rules can be managed withadd_rule()
anddel_rules()
.
-
-
class
qalgebra.core.state_algebra.
StateDerivative
(op, *, derivs, vals=None)[source]¶ Bases:
qalgebra.core.abstract_quantum_algebra.QuantumDerivative
,qalgebra.core.state_algebra.State
Symbolic partial derivative of a state
See
QuantumDerivative
.