Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contract_path with optimize=bool raises #219

Open
ev-br opened this issue Sep 8, 2023 · 3 comments
Open

contract_path with optimize=bool raises #219

ev-br opened this issue Sep 8, 2023 · 3 comments

Comments

@ev-br
Copy link

ev-br commented Sep 8, 2023

contract_path's optimize argument is documented as str, list or bool, but using bool arguments raises a TypeError:

n [1]: import opt_einsum as oe

In [2]: import numpy as np

In [3]: a = np.ones((2, 2))

In [4]: oe.contract_path('ij, jk, kl', a, a, a, optimize=False)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[4], line 1
----> 1 oe.contract_path('ij, jk, kl', a, a, a, optimize=False)

File ~/.conda/envs/pytorch-dev/lib/python3.8/site-packages/opt_einsum/contract.py:276, in contract_path(*operands, **kwargs)
    273 contraction_list = []
    275 # Build contraction tuple (positions, gemm, einsum_str, remaining)
--> 276 for cnum, contract_inds in enumerate(path):
    277     # Make sure we remove inds from right to left
    278     contract_inds = tuple(sorted(list(contract_inds), reverse=True))
    280     contract_tuple = helpers.find_contraction(contract_inds, input_sets, output_set)

TypeError: 'bool' object is not iterable

IIUC this is due to https://github.com/dgasmith/opt_einsum/blob/master/opt_einsum/contract.py#L305C1-L307C25:

    if not isinstance(path_type, (str, paths.PathOptimizer)):
        # Custom path supplied
        path = path_type

Granted, this is an edge case and maybe just a documentation issue of not allowing bools in the first place.

@jcmgray
Copy link
Collaborator

jcmgray commented Sep 8, 2023

I suppose the contract_path for optimize=False is a bit ill-defined. The options would be:

  1. Simply update the docs
  2. Always return path = [range(num_inputs)], which would allow contract_path to be called with the same args as contract always - probably preferable.

@ev-br
Copy link
Author

ev-br commented Sep 10, 2023

What about contract_path=True, should this be equivalent to "auto"?

@dgasmith
Copy link
Owner

I would agree contract_path=True should be equivalent to auto. It would seem natively to me that contract_path=False is equivalent to ensue or path = [range(num_inputs)].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants