states¶
Module for representing quantum states.
The BaseState
-class is intended to be subclassed for different types of states,
e.g. qubit states, qudit states, fock states etc.
The State
-class is then a sum of BaseState
-class
in the sum.
-
class
qualg.states.
BaseState
¶ Abstract base state class. Represents a single term of state and used to define how inner product should be taken etc.
Meant to be subclassed.
-
abstract
inner_product
(other)¶ Takes the inner product with another
BaseState
.- Parameters
other (
BaseState
) – The right hand side of the inner product.- Returns
The inner product
- Return type
class`~.scalar.Scalar`
-
to_state
()¶ Converts the base state to a state with a single term.
-
property
shape
¶ Returns the shape of the state, e.q. (2,) for a qubit.
None means that the shape is undefined, e.g. if the state is infinite-dimensional.
-
abstract
-
class
qualg.states.
State
(base_states=None, scalars=None)¶ -
__init__
(base_states=None, scalars=None)¶ A quantum state. Constructed as a sum of (subclass)
BaseState
.- Parameters
base_states (None or list of
BaseState
) – The base states that sums up to this state. If None, then the state is “zero”, i.e. no terms.scalar (None or list of
Scalar
) – The amplitudes used when taking the sum of base states. If None, then all operators have amplitude 1.
-
get_scalar
(base_state)¶ Returns the scalar of the given base_state
-
inner_product
(other, first_replace_var=True)¶ Takes the inner product with another
State
.- Parameters
other (
State
) – The right hand side of the inner product.(optional) (first_replace_var) – Whether to replace all varibles of the right hand side with new ones (only done for SingleVarFunctionScalar). This can be useful when the two states are actually integrals over the variables and should therefore be different.
- Returns
The inner product
- Return type
class`~.scalar.Scalar`
-
simplify
()¶ Tries to simplify the state.
-
replace_var
(old_variable, new_variable)¶ Replaces a variable with another.
-
get_variables
()¶ Returns the variable of this operator.
-