Skip to content

fix contract_ind passing inplace kwarg to cotengra#361

Open
JiwaniZakir wants to merge 1 commit into
jcmgray:mainfrom
JiwaniZakir:fix/issue-303
Open

fix contract_ind passing inplace kwarg to cotengra#361
JiwaniZakir wants to merge 1 commit into
jcmgray:mainfrom
JiwaniZakir:fix/issue-303

Conversation

@JiwaniZakir
Copy link
Copy Markdown

TensorNetwork.contract_ind accepted **contract_opts and forwarded them directly to tensor_contract, causing an inplace kwarg to reach cotengra's _build_expression, which does not accept it and raises a TypeError. The fix adds a single contract_opts.pop("inplace", None) line at the top of contract_ind before the opts are passed down. To verify, call tn.contract_ind(ind, inplace=False) on any two-tensor network sharing an index and confirm no TypeError is raised; the new test test_contract_ind_with_inplace_kwarg covers this case.

Fixes #303

Strip `inplace` from contract_opts in `TensorNetwork.contract_ind` before
passing to `tensor_contract`, preventing a TypeError in cotengra's
`_build_expression` which does not accept that keyword argument.
@jcmgray
Copy link
Copy Markdown
Owner

jcmgray commented May 17, 2026

Hi @JiwaniZakir, I'm afraid this it not a suitable fix. Supplying inplace=False needs to genuinely not modify the tensor network. Either the behavior of the method needs to be updated or an error raised for supplying an invalid kwarg (inplace), not just ignoring it.

By the way, is this an AI generated fix?

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

Successfully merging this pull request may close these issues.

TypeError in cotengra's _build_expression due to inplace kwarg when using TensorNetwork.contract_ind

2 participants