qml.labs.trotter_error.Fragment¶
- class Fragment[source]¶
Bases:
ABC
Abstract class used to define a fragment object for product formula error estimation.
A
Fragment
is an object that has a well-defined notion of a commutator. To ensure the existence of commutators, the implementation requires the following arithmetic dunder methods:__add__()
: implements addition__mul__()
: implements multiplication__matmul__()
: implements matrix multiplication
In addition to the arithmetic operators, a
norm
method should be defined. The norm is required to compute error estimates of Trotter error operators.Methods
apply
(state)Apply the Fragment to a state on the right.
expectation
(left, right)Return the expectation value of a state.
norm
(params)Compute the norm of the fragment.
- abstract apply(state)[source]¶
Apply the Fragment to a state on the right. The type of
state
is determined by each class inheriting fromFragment
.- Parameters:
state (AbstractState) – an object representing a quantum state
- Returns:
the result of applying the
Fragment
tostate
- Return type:
- expectation(left, right)[source]¶
Return the expectation value of a state. The type of
state
is determined by each class inheriting fromFragment
.- Parameters:
left (AbstractState) – the state to be multiplied on the left of the
Fragment
right (AbstractState) – the state to be multiplied on the right of the
Fragment
- Returns:
the expectation value obtained by applying
Fragment
to the given states- Return type:
float