qml.labs.trotter_error.GenericFragment

class GenericFragment(fragment, norm_fn=None)[source]

Bases: pennylane.labs.trotter_error.abstract.Fragment

Abstract class used to define a generic fragment object for product formula error estimation.

This class allows using any object implementing arithmetic dunder methods to be used for product formula error estimation.

Parameters
  • fragment (Any) – An object that implements the following arithmetic methods: __add__, __mul__, and __matmul__.

  • norm_fn (optional, Callable) – A function used to compute the norm of fragment.

Note

GenericFragment objects should be instantated through the generic_fragments function.

Example

>>> from pennylane.labs.trotter_error import generic_fragments
>>> import numpy as np
>>> matrices = [np.array([[1, 0], [0, 1]]), np.array([[0, 1], [1, 0]])]
>>> generic_fragments(matrices)
[GenericFragment(type=<class 'numpy.ndarray'>), GenericFragment(type=<class 'numpy.ndarray'>)]

apply(state)

Apply the fragment to a state using the underlying object's __matmul__ method.

expectation(left, right)

Compute the expectation value using the underlying object's __matmul__ method.

norm([params])

Compute the norm of the fragment.

apply(state)[source]

Apply the fragment to a state using the underlying object’s __matmul__ method.

expectation(left, right)[source]

Compute the expectation value using the underlying object’s __matmul__ method.

norm(params=None)[source]

Compute the norm of the fragment.