operators¶
Module for representing operators of quantum states.
An Operator
is constructed as a sum of BaseState
and in turn State
The BaseOperator
-class represents a single term of the form |left><right|,
where left and right are BaseState
’s. The BaseOperator
is
agnostic to which subclass of BaseState
is used.
The Operator
-class is then a sum of BaseOperator
.
-
class
qualg.operators.
BaseOperator
(left, right)¶ -
__init__
(left, right)¶ Represents a single term of an operator, i.e. |left><right|, where left and right are
BaseState
’s.
-
property
shape
¶ Returns the shape of the operator, e.q. (2, 2) for a single-qubit operator.
None means that the shape is undefined, e.g. if the state is infinite-dimensional.
-
replace_var
(old_variable, new_variable)¶ Replaces a variable with another.
-
get_variables
()¶ Returns the variable of this operator.
-
-
class
qualg.operators.
Operator
(base_ops=None, scalars=None)¶ -
__init__
(base_ops=None, scalars=None)¶ An operator represented as a sum of
BaseOperator
of a subclass thereof.- Parameters
base_ops (None or list of
BaseOperator
) – The base operators that sums up to this operator. If None, then the operator is “zero”, i.e. no terms.scalar (None or list of
Scalar
) – The amplitudes used when taking the sum of base operators. If None, then all operators have amplitude 1.
-
property
shape
¶ Returns the shape of the operator, e.q. (2, 2) for a single-qubit operator.
None means that the shape is undefined, e.g. if the state is infinite-dimensional.
-
get_scalar
(base_op)¶ Returns the scalar of the given base_op
-
dagger
()¶ Complex conjugate of the operator.
-
simplify
()¶ Tries to simplify the operator, returning a new one.
-
replace_var
(old_variable, new_variable)¶ Replaces a variable with another.
-
get_variables
()¶ Returns the variable of this operator.
-
to_numpy_matrix
(convert_scalars=None, **kwargs)¶ Converts the operator to a numpy matrix.
If there are non-number scalars then the provided function convert_scalars is used to convert a non-number scalar to a number. This function should then take a scalar (plus optional keyword arguments) and return a number.
- Parameters
convert_scalars (function) – Function to convert a non-number scalar to a number.
**kwargs – Keyword-arguments to be passed to convert_scalars.
- Returns
The operator in numerical matrix form.
- Return type
numpy.ndarray
-