Skip to content

Conversation

@jack-dunham
Copy link
Contributor

See discussions in: ITensor/ITensorNetworks.jl#255

@jack-dunham jack-dunham marked this pull request as ready for review October 31, 2025 16:33
@jack-dunham jack-dunham marked this pull request as draft October 31, 2025 16:51
@jack-dunham
Copy link
Contributor Author

I am going to look into expressing this interface in more general language.

@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

❌ Patch coverage is 70.40816% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.88%. Comparing base (c4085f7) to head (715946c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/iterators.jl 65.00% 28 Missing ⚠️
src/adapters.jl 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #17      +/-   ##
==========================================
+ Coverage   56.51%   58.88%   +2.37%     
==========================================
  Files           6        8       +2     
  Lines         476      574      +98     
==========================================
+ Hits          269      338      +69     
- Misses        207      236      +29     
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.

jack-dunham and others added 3 commits November 3, 2025 10:13
Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
Co-authored-by: Matt Fishman <mtfishman@users.noreply.github.com>
src/iterators.jl Outdated
Comment on lines 50 to 57
try
first(region_plan)
catch e
if e isa BoundsError
throw(ArgumentError("Cannot construct a region iterator with 0 elements."))
end
rethrow()
end
Copy link
Member

Choose a reason for hiding this comment

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

I'm always a bit weary to use try except in extenuating circumstances, when is it not enough to use something like isempty(region_plan)? It seems reasonable to expect whatever is input as region_plan to define some functions like isempty, length, etc.

Copy link
Member

Choose a reason for hiding this comment

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

Also, is it really a problem to have an empty RegionIterator? Can't that just mean that that if you iterate it it doesn't do anything?

Copy link
Contributor Author

@jack-dunham jack-dunham Nov 3, 2025

Choose a reason for hiding this comment

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

I like try as it allows one to both print a more descriptive error higher in the callstack as well as the error that would be inevitably be thrown later, but Ill be honest I don't have that much formal programming knowledge of how the statements should be used, so happy to use some other pattern if you think it would be more suitable.

Constructing empty AbstractNetworkIterators is undefined as the first iteration is implicit. This is a consequence of having both of the following behaviors:

  1. Work done during iteration. i.e. allowing for _ in iter end to do the full computation
  2. An AbstractNetworkIterator having a well defined state during the callback.

Might be easier to discuss this in person if you are uncomfortable with disallowing empty AbstractNetworkIterator, but I believe it to be fundamental to allow for the above two behaviors (that we already agreed were good behaviors).

Copy link
Member

Choose a reason for hiding this comment

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

Yes I think this would be easier to discuss in person, I've gotten a little bit lost around those edge cases in the design. If you want to write a custom error message I don't see why something closer to the previous design doesn't suffice, i.e.:

        if isempty(region_plan)
            throw(ArgumentError("Cannot construct a region iterator with 0 elements."))
        end

but maybe I'm missing something.

Copy link
Member

@mtfishman mtfishman Nov 3, 2025

Choose a reason for hiding this comment

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

Is the issue that isempty(region_plan) might sometimes throw an error? If so, in which cases would it throw an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are not missing anything, I am overcomplicating things!

Copy link
Member

@mtfishman mtfishman Nov 3, 2025

Choose a reason for hiding this comment

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

If the concern is that region_plan might be an iterator that doesn't have a length/size defined, maybe we can catch that more explicitly by checking Base.IteratorSize(region_plan) == Base.SizeUnknown() (https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-iteration). (But also that seems like a strange corner case that we can deal with if it comes up.)

@mtfishman
Copy link
Member

@jack-dunham this looks good from my end, is there anything else you wanted to do here? Also can you bump the package version?

@jack-dunham
Copy link
Contributor Author

@jack-dunham this looks good from my end, is there anything else you wanted to do here? Also can you bump the package version?

Happy to add in the contents of solvers/adapters.jl here too if you like, rather than making another PR.

@mtfishman
Copy link
Member

Happy to add in the contents of solvers/adapters.jl here too if you like, rather than making another PR.

Sure, we can include that here.

@jack-dunham jack-dunham marked this pull request as ready for review November 3, 2025 19:24
@mtfishman mtfishman merged commit 255d482 into ITensor:main Nov 3, 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