Skip to content

Conversation

@JoeyT1994
Copy link
Collaborator

@JoeyT1994 JoeyT1994 commented Oct 2, 2025

This PR introduces the ability to contract vectors of AbstractArrays and thus AbstractTensorNetworks via the contractnetwork(tn; sequence) function.

The sequence is used to tell the contraction_sequence backend how to find the desired sequence, with the strings sequence= "leftassociative" and "optimal" supported (the latter via TensorOperations) alongside support for sending a specific pre-defined sequence.

Rudimentary tests are included, although we might want to consider making these more robust and also testing the sequence finding functionality ourselves.

@codecov
Copy link

codecov bot commented Oct 2, 2025

Codecov Report

❌ Patch coverage is 93.10345% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.51%. Comparing base (2819116) to head (5a7dc37).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/contract_network.jl 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #7      +/-   ##
==========================================
+ Coverage   54.13%   56.51%   +2.37%     
==========================================
  Files           4        6       +2     
  Lines         447      476      +29     
==========================================
+ Hits          242      269      +27     
- Misses        205      207       +2     
Flag Coverage Δ
docs 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2025

Your PR no longer requires formatting changes. Thank you for your contribution!

@JoeyT1994
Copy link
Collaborator Author

@mtfishman I'm not really sure what the failing test is to do with... something coming from Aqua.jl and stale dependencies...

@mtfishman
Copy link
Member

@mtfishman I'm not really sure what the failing test is to do with... something coming from Aqua.jl and stale dependencies...

It looks like moving the TensorOperations code to a package extension made it so that ITensorBase is no longer a direct dependency of ITensorNetworksNext, since now it is only used in that package extension (Aqua is rightly detecting that situation and seeing that there is a dependency listed in the Project.toml that isn't being used in the main package).

However, in this case I think we should try to use NamedDimsArrays directly rather than ITensorBase, I can give you pointers on how to do that.

Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
JoeyT1994 and others added 7 commits October 24, 2025 15:04
Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
@mtfishman
Copy link
Member

Could you also bump the package version?

@mtfishman mtfishman changed the title Working ContractNetwork Working contract_network Oct 25, 2025
@mtfishman
Copy link
Member

Also thinking about it more, I'd slightly prefer the name contract_network over contractnetwork, I think it is easier to read and makes it clearer it is a version of contract for networks.

@JoeyT1994
Copy link
Collaborator Author

Makes sense. I'll make that change.

@mtfishman
Copy link
Member

I think this looks good for now, thanks for sticking with all the comments. I think there are a few follow-ups to this:

  1. The default keyword argument wrangling is a little bit hard to follow, maybe thinking about it more broadly using Add default_kwargs interface and associated macros #13 could help.
  2. As discussed, we should implement an eager contraction sequence finder and use that as the default instead of "leftassociative", I can do that in a follow-up PR.
  3. Adding more sequence finding backends to get feature-completeness with ITensorNetworks.jl.

But this seems like a good enough start to build other algorithms like BP so I'll merge this and we can work on those things as next steps.

@mtfishman mtfishman merged commit c4085f7 into ITensor:main Oct 26, 2025
13 checks passed
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.

2 participants