Skip to content

Easily store einsum paths #22

@evanberkowitz

Description

@evanberkowitz

For numeric reproducibility it would be good to store the einsum paths that different observables use. (It depends on the lattice size, nt, etc.)

Annoyingly the output of np.einsum_path can't just be dumped to h5.

import h5py as h5
import numpy as np

M = np.arange(1024).reshape(4,4,8,8)

path, summary = np.einsum_path('abde,acdf,bcef->',M,M,M,optimize="optimal")

# path = ['einsum_path', (0, 1), (0, 1)]
# print(summary) yields
#   Complete contraction:  abde,acdf,bcef->
#         Naive scaling:  6
#     Optimized scaling:  6
#      Naive FLOP count:  9.830e+04
#  Optimized FLOP count:  6.758e+04
#   Theoretical speedup:  1.455
#  Largest intermediate:  1.024e+03 elements
#--------------------------------------------------------------------------
#scaling                  current                                remaining
#--------------------------------------------------------------------------
#   6             acdf,abde->bcef                              bcef,bcef->
#   4                 bcef,bcef->                                       ->

# Another example
path, summary = np.einsum_path('abde,acdf,bcef,gghh->',M,M,M,M,optimize="optimal")

but because it's a mixed array path can't easily be written to an h5 path.

I tried pickling the whole shebang, but I couldn't figure out how to send the pickle.dump to an h5 field. There is an hdf5 pickle but I'd be afraid to use it and h5py at the same time.

How should this be accomplished? Sometimes many different contractions share an optimization (as in spin-spin correlators). Could be a string attribute (str(path) works).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions