Skip to content

ITensorNetwork type fixes and other minor refactors. - #175

Merged
mtfishman merged 22 commits into
mainfrom
jd/tensornetwork-type-updates
Sep 28, 2026
Merged

mtfishman merged 22 commits into
mainfrom
jd/tensornetwork-type-updates

Conversation

@jack-dunham

@jack-dunham jack-dunham commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes and cleanups to the ITensorNetwork type, the BP message cache, and gate application.

  • add_edge!/rem_edge! on ITensorNetwork return false instead of throwing.
  • dimnamevertices returns an empty set for a name the network does not hold.
  • New operator_support(tn, op): the vertices carrying the operator's input index names. An absent name contributes no vertex; a name on several vertices throws.
  • Tensor assignment checks index names before mutating, so a rejected assignment no longer leaves dimname_vertices and the underlying graph half-updated.
  • finalize_substate! takes both subsolve and solve objects as arguments.
  • bethe_free_energy's duplicated log-sum factored into sumlog.

@ITensorBot

ITensorBot commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

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

@codecov

codecov Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.57143% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 87.19%. Comparing base (5a03ef2) to head (41eb83f).

Files with missing lines Patch % Lines
src/tensornetwork.jl 96.55% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #175      +/-   ##
==========================================
+ Coverage   86.09%   87.19%   +1.09%     
==========================================
  Files          15       16       +1     
  Lines         669      687      +18     
==========================================
+ Hits          576      599      +23     
+ Misses         93       88       -5     
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 Harness.
📢 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.

@jack-dunham
jack-dunham force-pushed the jd/tensornetwork-type-updates branch 2 times, most recently from dee5559 to faa56ff Compare September 9, 2026 18:12
Comment thread src/beliefpropagation/messagecache.jl Outdated
Comment thread src/abstracttensornetwork.jl Outdated
return tn
end

function supportof(tn::AbstractGraph, op::ITensorOperator)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe I'd call this operator_support, just to not make it sound so generic, i.e. we don't know what the "scope" of this function will be. Also, what about constraining to tn::AbstractITensorNetwork?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry about constraining such functions as then they no longer "just work" on e.g. wrappers that do not subtype AbstractITensorNetwork.

As for the name, I have no strong opinions. I have been drafting the ITensorNetworkOperator object, where this function would also have a method for. I don't know if that changes your opinion (although operator_support would still work in that case).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"wrappers that do not subtype AbstractITensorNetwork": We could always generalize when we have those cases (or maybe you have one already?). "I don't know if that changes your opinion": I think that still fits, i.e. I think operator_support would assume some structure of the operator, like it has input and output indices and you are specifically matching against input indices. We could always generalize the name as the use cases generalize.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no specific case. It is more of a case of me deciding to choose the default to be AbstractGraph when it does not introduce type piracy or ambiguity after having to change this multiple times to accommodate QuotientView.

Happy to change the name.

Comment thread src/tensornetwork.jl Outdated
Comment thread src/tensornetwork.jl Outdated
Comment thread src/tensornetwork.jl
# PERF: fast lookup compared to `AbstractITensorNetwork` fallback.
dimnamevertices(tn::ITensorNetwork, name) = tn.dimname_vertices[name]
function dimnamevertices(tn::ITensorNetwork, name)
return get(tn.dimname_vertices, name, Set{vertextype(tn)}())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes more sense, but was this inspired by a particular use case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for consistency with the fallback method (which returns an empty set).

@jack-dunham
jack-dunham force-pushed the jd/tensornetwork-type-updates branch from 7225dab to 48534f9 Compare September 14, 2026 18:56
Comment thread src/beliefpropagation/messagecache.jl Outdated
Comment thread src/beliefpropagation/messagecache.jl Outdated
Comment thread src/abstracttensornetwork.jl Outdated
Comment thread src/tensornetwork.jl Outdated
Comment thread src/beliefpropagation/messagecache.jl Outdated
Comment thread src/beliefpropagation/messagecache.jl Outdated
Comment thread src/beliefpropagation/messagecache.jl
jack-dunham and others added 7 commits September 28, 2026 10:42
…nergy` as its negative.

The function returns the BP estimate of log Z, which is the free entropy; the free energy is -log Z.
Adds tests for the relation between the two and for a vanishing edge overlap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t arg.

This is for consistency with `vertex_scalars`.
@jack-dunham
jack-dunham force-pushed the jd/tensornetwork-type-updates branch from 12d850e to e1702bd Compare September 28, 2026 15:04
@jack-dunham
jack-dunham force-pushed the jd/tensornetwork-type-updates branch from e1702bd to 8a9b645 Compare September 28, 2026 15:12
@mtfishman

Copy link
Copy Markdown
Member

Looks good to me, thanks! Can you bump the version?

@mtfishman
mtfishman enabled auto-merge (squash) September 28, 2026 18:54
@mtfishman
mtfishman merged commit c27fc8e into main Sep 28, 2026
18 checks passed
@mtfishman
mtfishman deleted the jd/tensornetwork-type-updates branch September 28, 2026 19:17
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.

3 participants