qml.labs.trotter_error.sparse_fragments

sparse_fragments(fragments)[source]

Instantiates SparseFragment objects.

Parameters:

fragments (Sequence[csr_array]) – A sequence of sparse matrices to be used as fragments.

Returns:

A list of SparseFragment objects instantiated from fragments.

Return type:

List[SparseFragment]

Example This code example demonstrates building fragments from scipy sparse matrices.

>>> from pennylane.labs.trotter_error import sparse_fragments
>>> from scipy.sparse import csr_array
>>> matrices = [csr_array([[1, 0], [0, 1]]), csr_array([[0, 1], [1, 0]])]
>>> fragments = sparse_fragments(matrices)
>>> fragments
[SparseFragment(shape=(2, 2), dtype=int64), SparseFragment(shape=(2, 2), dtype=int64)]
>>> fragments[0].norm()
1.4142135623730951