dgasmith / opt_einsum

⚡️Optimizing einsum functions in NumPy, Tensorflow, Dask, and more with contraction order optimization.
https://dgasmith.github.io/opt_einsum/
MIT License
863 stars 68 forks source link

Getting "not enough values to unpack" with optimize=dp #116

Closed yaroslavvb closed 4 years ago

yaroslavvb commented 5 years ago

The following breaks with optimize='dp' but works with default optimizer

import opt_einsum as oe 
einsum_string = 'a,bcd,efg->'
views = oe.helpers.build_views(einsum_string, {c: 2 for c in einsum_string.replace(',->','')})
path, path_info = oe.contract_path(einsum_string, *views, optimize='dp')
print(path_info)

produces

/usr/local/lib/python3.6/dist-packages/opt_einsum/contract.py in contract_path(*operands, **kwargs)
    270     else:
    271         path_optimizer = paths.get_path_fn(path_type)
--> 272         path = path_optimizer(input_sets, output_set, dimension_dict, memory_arg)
    273 
    274     cost_list = []

/usr/local/lib/python3.6/dist-packages/opt_einsum/paths.py in dynamic_programming(inputs, output, size_dict, memory_limit)
    971 def dynamic_programming(inputs, output, size_dict, memory_limit=None):
    972     optimizer = DynamicProgrammingOptimizer()
--> 973     return optimizer(inputs, output, size_dict, memory_limit)
    974 
    975 

/usr/local/lib/python3.6/dist-packages/opt_einsum/paths.py in __call__(self, inputs, output, size_dict, memory_limit)
    872         inputs, inputs_contractions = zip(*[
    873             (i - i_single, j if i.isdisjoint(i_single) else (j,))
--> 874             for j, i in enumerate(inputs)
    875             if len(i - i_single) > 0
    876         ])

ValueError: not enough values to unpack (expected 2, got 0)
jcmgray commented 5 years ago

I'm making a few small updates to 'dp' and will include a fix for this this shortly.

jcmgray commented 4 years ago

This should be fixed by #119.