-
Notifications
You must be signed in to change notification settings - Fork 22
Changes to the iterator interface #255
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
Merged
mtfishman
merged 56 commits into
ITensor:network_solvers
from
jack-dunham:network_solvers
Oct 20, 2025
Merged
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
7a51966
Add `Problem` as type parameter to `SweepIterator`
jack-dunham 245182b
Format test files and improve comparisons for readabilty on failure
jack-dunham 7af4b25
Redesign iterator interface by introducing AbstractNetworkIterator ab…
jack-dunham c0ae5d0
Add `EachRegion` adapter that wraps `RegionIterator`, behaving the sa…
jack-dunham 3b9d0af
Add unit tests for the `AbstractNetworkIterator` interface
jack-dunham 4ef4e75
Rename `done` to `laststep` to better reflect the when it evalutes to…
jack-dunham e112eb4
Rename `previous_region` to `prev_region` to better align with julia …
jack-dunham da360e0
Rename `PauseAfterIncrement` -> `NoComputeStep` and improve some vari…
jack-dunham 8bfc483
Make `extract` and `subspace_expand` mutating
jack-dunham 1ef8498
Make `update` mutable
jack-dunham 0a6e891
Make `insert` mutable
jack-dunham 0653c47
First implementation of an `options` system.
jack-dunham d77321e
Simplify options interface to a single function `default_kwargs`.
jack-dunham aff14c7
Put calls to `extract!` etc in `compute!` function directly
jack-dunham 4b21cc9
Refactor the region plan generating code.
jack-dunham e71512f
Have `dmrg` take a strict number of arguments
jack-dunham a4ce308
Purge non-mutating field setter functions.
jack-dunham a8b2c51
Use `current_kwargs` for getting kwargs from `RegionIterator`
jack-dunham 18a8503
Introduce defaults using `default_kwargs` and be stricter about which…
jack-dunham 0c9022c
Swap order of local_state and region_iter args
jack-dunham a9be11e
Add some unit tests for the defaults
jack-dunham 4d52088
Rename file options.jl -> test_default_kwargs.jl
jack-dunham 613d533
Fix `euler_sweep` returning kwargs not as `NamedTuple`
jack-dunham 20bf783
The `sweep_solve` callbacks now get called without any keyword argume…
jack-dunham 568c631
Some minor refactoring of the iterators.
jack-dunham fed9137
The `EachRegion` adapter now flattens the nested Sweep/Region iterato…
jack-dunham 4ce453e
Add tests for `EachRegion` and `eachregion` wrapper functions
jack-dunham c59a9c5
Rename `laststep` -> `islaststep` in fitting with Julia conventions.
jack-dunham 62195b6
Overhaul `default_kwargs` such that it mirrors the function signature…
jack-dunham 917f2f1
Rename `NoComputeStep` to `IncrementOnly`
jack-dunham 112d55e
Remove @info statement and fix bug with `astypes` not promoting corre…
jack-dunham 0a9f127
Update `default_kwargs` tests.
jack-dunham e35f325
Remove stray `end` from `adapters.jl`.
jack-dunham 6a8cdb1
Fix typo in docstring of `EachRegion` adapter.
jack-dunham 9760de1
Function `reverse_regions` is now more concise.
jack-dunham 26ece7b
Use explicit imports in `default_kwargs.jl`
jack-dunham 340d805
Fix test imports and broken tests in `test_iterators.jl`.
jack-dunham f89c379
Merge branch 'network_solvers' of https://github.com/jack-dunham/ITen…
jack-dunham 6a33f29
Rename @default_kwargs -> @define_default_kwargs
jack-dunham b4bcb93
Remove `astypes` option from `@define_default_kwargs`.
jack-dunham 624f964
Update `default_kwargs` tests.
jack-dunham bd35f09
Add `sweep_solve` method for `EachRegion` adapter.
jack-dunham 0b5314d
Add `@with_kwargs` macro which automatically splats `default_kwargs` …
jack-dunham a58ec92
Make use of `@with_kwargs` macro make code more concise.
jack-dunham b72a08f
The fallback default callback functions now no longer accept `kwargs.…
jack-dunham c5de5c4
Test fix: tests founds in sub-directories are now actually ran when i…
jack-dunham 2788057
Skip broken tests for now
jack-dunham 33b9e28
Rename `sweep_solve` -> `sweep_solve!` to obey convention
jack-dunham dedd82e
The `EachRegion` adapter now returns itself from `iterate` instead of…
jack-dunham d39f09e
The `sweep_solve!` function now always returns the type of the input …
jack-dunham 3f5c97c
Mutating functions now return the first argument before any additiona…
jack-dunham 7ad3138
Remove depreciated `solvers` code and tests from old interface
jack-dunham 60235bc
Method `subspace_expand!(::Backend"densitymatrix")` now defines kwarg…
jack-dunham da3ad27
Solvers code now no longer relies on `default_kwargs` system
jack-dunham 8725370
Remove `default_kwargs` related to source files
jack-dunham 8afce8a
Delete stale include
mtfishman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
|
|
||
| abstract type AbstractProblem end | ||
|
|
||
| set_truncation_info(P::AbstractProblem, args...; kws...) = P | ||
| set_truncation_info!(P::AbstractProblem, args...; kws...) = P |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,46 @@ | ||
| """ | ||
| struct PauseAfterIncrement{S<:AbstractNetworkIterator} | ||
|
|
||
| # | ||
| # TupleRegionIterator | ||
| # | ||
| # Adapts outputs to be (region, region_kwargs) tuples | ||
| # | ||
| # More generic design? maybe just assuming RegionIterator | ||
| # or its outputs implement some interface function that | ||
| # generates each tuple? | ||
| # | ||
|
|
||
| mutable struct TupleRegionIterator{RegionIter} | ||
| region_iterator::RegionIter | ||
| Iterator wrapper whos `compute!` function simply returns itself, doing nothing in the | ||
| process. This allows one to manually call a custom `compute!` or insert their own code it in | ||
| the loop body in place of `compute!`. | ||
| """ | ||
| struct IncrementOnly{S<:AbstractNetworkIterator} <: AbstractNetworkIterator | ||
| parent::S | ||
| end | ||
|
|
||
| region_iterator(T::TupleRegionIterator) = T.region_iterator | ||
| islaststep(adapter::IncrementOnly) = islaststep(adapter.parent) | ||
| state(adapter::IncrementOnly) = state(adapter.parent) | ||
| increment!(adapter::IncrementOnly) = increment!(adapter.parent) | ||
| compute!(adapter::IncrementOnly) = adapter | ||
|
|
||
| function Base.iterate(T::TupleRegionIterator, which=1) | ||
| state = iterate(region_iterator(T), which) | ||
| isnothing(state) && return nothing | ||
| (current_region, region_kwargs) = current_region_plan(region_iterator(T)) | ||
| return (current_region, region_kwargs), last(state) | ||
| end | ||
| IncrementOnly(adapter::IncrementOnly) = adapter | ||
|
|
||
| """ | ||
| region_tuples(R::RegionIterator) | ||
| struct EachRegion{SweepIterator} <: AbstractNetworkIterator | ||
|
|
||
| The `region_tuples` adapter converts a RegionIterator into an | ||
| iterator which outputs a tuple of the form (current_region, current_region_kwargs) | ||
| at each step. | ||
| Adapter that flattens each region iterator in the parent sweep iterator into a single | ||
| iterator. | ||
| """ | ||
| region_tuples(R::RegionIterator) = TupleRegionIterator(R) | ||
| struct EachRegion{SI<:SweepIterator} <: AbstractNetworkIterator | ||
| parent::SI | ||
| end | ||
|
|
||
| # In keeping with Julia convention. | ||
| eachregion(iter::SweepIterator) = EachRegion(iter) | ||
|
|
||
| # Essential definitions | ||
| function islaststep(adapter::EachRegion) | ||
| region_iter = region_iterator(adapter.parent) | ||
| return islaststep(adapter.parent) && islaststep(region_iter) | ||
| end | ||
| function increment!(adapter::EachRegion) | ||
| region_iter = region_iterator(adapter.parent) | ||
| islaststep(region_iter) ? increment!(adapter.parent) : increment!(region_iter) | ||
| return adapter | ||
| end | ||
| function compute!(adapter::EachRegion) | ||
| region_iter = region_iterator(adapter.parent) | ||
| compute!(region_iter) | ||
| return adapter | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,16 @@ | ||
| function extract(problem, region_iterator; sweep, trunc=(;), kws...) | ||
| trunc = truncation_parameters(sweep; trunc...) | ||
| region = current_region(region_iterator) | ||
| psi = orthogonalize(state(problem), region) | ||
| function extract!(region_iter::RegionIterator; subspace_algorithm="nothing") | ||
| prob = problem(region_iter) | ||
| region = current_region(region_iter) | ||
|
|
||
| psi = orthogonalize(state(prob), region) | ||
| local_state = prod(psi[v] for v in region) | ||
| problem = set_state(problem, psi) | ||
| problem, local_state = subspace_expand( | ||
| problem, local_state, region_iterator; sweep, trunc, kws... | ||
| ) | ||
| shifted_operator = position(operator(problem), state(problem), region) | ||
| return set_operator(problem, shifted_operator), local_state | ||
|
|
||
| prob.state = psi | ||
|
|
||
| _, local_state = subspace_expand!(region_iter, local_state; subspace_algorithm) | ||
| shifted_operator = position(operator(prob), state(prob), region) | ||
|
|
||
| prob.operator = shifted_operator | ||
|
|
||
| return region_iter, local_state | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.