QutipOperator
- class pulser_simulation.QutipOperator(operator, eigenstates)
Bases:
Operator[complex,complex,QutipStateType]A quantum operator stored as a qutip.Qobj.
- Parameters:
state – The operator as a qutip.Qobj.
eigenstates (
Sequence[Literal['u','d','r','g','h','x'] |Literal['0','1']]) – The eigenstates that form a qudit’s eigenbasis, each given as an individual character. The order of the eigenstates matters, as for eigenstates (“a”, “b”, …), “a” will be associated to eigenvector (1, 0, …), “b” to (0, 1, …) and so on.
Attributes
The eigenstates that form a qudit's eigenbasis.
Methods
Apply the operator to a state.
Compute the expectation value of self on the given state.
Creates a new operator of this type from another operator.
Create an operator from the operator representation.
Returns a copy of the operators's Qobj representation.
Signatures
- apply_to(state, /)
Apply the operator to a state.
- Parameters:
state (
TypeVar(QutipStateType, bound=QutipState)) – The state to apply this operator to.- Return type:
TypeVar(QutipStateType, bound=QutipState)- Returns:
The resulting state.
- expect(state, /)
Compute the expectation value of self on the given state.
- Parameters:
state (
QutipState) – The state with which to compute.- Return type:
complex- Returns:
The expectation value.
- classmethod from_operator(operator)
Creates a new operator of this type from another operator.
By default, the operator is converted through its abstract representation, which is only possible if it was created via
from_operator_repr(). If the operator is already an instance of this type, a shallow copy of it is returned instead, so it does not need to be serializable.Subclasses can override this method to support other conversions (e.g. directly from an operator type they know).
- Parameters:
operator (
Operator) – The operator to convert.- Return type:
TypeVar(OperatorType, bound= Operator)- Returns:
A new operator of this type, equivalent to the given one.
- Raises:
TypeError – If the operator can’t be converted to this type.
- classmethod from_operator_repr(*, eigenstates, n_qudits, operations)
Create an operator from the operator representation.
Only operators constructed with this method are allowed in remote backend.
The full operator representation (
FullOp) is a weigthed sum of tensor operators (TensorOp), written as a sequence of coefficient and tensor operator pairs, ieFullOp = Sequence[tuple[ScalarType, TensorOp]]Each
TensorOpis itself a sequence of qudit operators (QuditOp) applied to mutually exclusive sets of qudits (represented by their indices), ieTensorOp = Sequence[tuple[QuditOp, Collection[int]]]Qudits without an associated
QuditOpare applied the identity operator.Finally, each
QuditOpis represented as weighted sum of pre-defined single-qudit operators. It is given as a mapping between a string representation of the single-qudit operator and its respective coefficient, ieQuditOp = Mapping[str, ScalarType]By default, it identifies strings
"ij"as single-qudit operators, whereiandjare eigenstates that denote|i><j|.- Parameters:
eigenstates (
Sequence[Literal['u','d','r','g','h','x'] |Literal['0','1']]) – The eigenstates to use.n_qudits (
int) – How many qudits there are in the system.operations (
Sequence[tuple[TypeVar(ArgScalarType),Sequence[tuple[Mapping[str,TypeVar(ArgScalarType)],Collection[int]]]]]) – The full operator representation.
- Return type:
TypeVar(OperatorType, bound= Operator)- Returns:
The constructed operator.
Examples
>>> eigenstates = ("r", "g") >>> n_qudits = 4 >>> # define X,Y,Z >>> X = {"gr": 1.0, "rg": 1.0} >>> Y = {"gr": 1.0j, "rg": -1.0j} >>> Z = {"rr": 1.0, "gg": -1.0} >>> # build for example 0.5*X0Y1X2Z3 - j0.2*Z1Y3 + (-0.1+j4.0)*X2 >>> operations = [ >>> ( >>> 0.5, >>> [ >>> (X, [0, 2]), # acts on qudit 0 and 2 >>> (Y, [1]), >>> (Z, [3]), >>> ], >>> ), >>> ( >>> -0.2j, >>> [ >>> (Z, [1]), >>> (Y, [3]), >>> ], >>> ), >>> ( >>> -0.1 + 4.0j, >>> [ >>> (X, [2]), >>> ], >>> ), >>> ] >>> config_class = your_pulser_backend.config_type >>> operator_class = config_class.operator_type >>> op = operator_class.from_operator_repr( >>> eigenstates=eigenstates, >>> n_qudits=n_qudits, >>> operations=operations >>> )
- to_qobj()
Returns a copy of the operators’s Qobj representation.
- Return type:
Qobj
- property eigenstates: tuple[Literal['u', 'd', 'r', 'g', 'h', 'x', '0', '1'], ...]
The eigenstates that form a qudit’s eigenbasis.
The order of the states should match the order in a numerical (ie state vector or density matrix) representation. For example, with eigenstates (“a”, “b”, …), “a” will be associated to eigenvector (1, 0, …), “b” to (0, 1, …) and so on.