qml.labs.trotter_error.generic_fragments¶
- generic_fragments(fragments, norm_fn=None)[source]¶
Instantiates
GenericFragmentobjects.- Parameters:
fragments (Sequence[Any]) – A sequence of objects of the same type. The type is assumed to implement
__add__,__mul__, and__matmul__.norm_fn (Callable) – A function that computes the norm of the fragments.
- Returns:
A list of
GenericFragmentobjects instantiated from fragments.- Return type:
List[GenericFragment]
Example
This code example demonstrates building fragments from numpy matrices.
>>> 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]])] >>> fragments = generic_fragments(matrices, norm_fn=np.linalg.norm) >>> fragments [GenericFragment(type=<class 'numpy.ndarray'>), GenericFragment(type=<class 'numpy.ndarray'>)] >>> fragments[0].norm() 1.4142135623730951
code/api/api/pennylane.labs.trotter_error.generic_fragments
Download Python script
Download Notebook
View on GitHub