ITensor / ITensor/ITensorNetworks.jl

Create an iterator interface for `alternating_update`

Open
#200 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
128
Forks
23
Avg merge
4d 7h
Merged PRs (30d)
7

Description

An iterator interface for alternating_update could allow advanced users more fine-grained control over iterating through region updates and sweeps, for example allow them to change the sweep pattern based on the current state of the solver, perform custom printing, move objects back and forth between different devices (i.e. CPU, GPU, disk, etc.) based on properties of the current state, etc.

Additionally, higher level function interfaces like alternating_update can be implemented as loops over those iterators, which could improve the code logic.

For example, alternating_update could be implemented like this:

sweep_iterator = AlternatingUpdateIterator(projected_operator, init_state, sweep_plans)
for (; region_iterator, which_sweep) in sweep_iterator # Iterate over sweep updates
  @show which_sweep # Custom printing
  for (; state, region) in region_iterator # Iterate over the region updates of the sweep
    @show region # More custom printing
    # Perform some logic, like if maxlinkdim(state) > 1000, move from GPU to CPU
    if maxlinkdim(state) > 1000
      sweep_iterator.state = cpu(state)
    end
  end
end

That's just a rough outline and example, I'm sure the interface won't be exactly like that.

This design approach could also help us rethink the sweep plan logic, which is a bit of a mess right now, and we'll also have to think about how it interfaces with the observer system (I think it fits in well, and would allow users to inject calls to the observer in a more custom way, while right now the calls are hardcoded at certain points in the code logic).

See these references for examples of iterative algorithms based around iterators:
https://docs.sciml.ai/DiffEqDocs/stable/basics/integrator
https://iterativesolvers.julialinearalgebra.org/dev/iterators
https://discourse.julialang.org/t/ann-optimkit-jl-a-blissfully-ignorant-julia-package-for-gradient-optimization/41063/3

@emstoudenmire @JoeyT1994

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the alternating_update entry point and reading the current sweep-plan logic and observer integration. Review the linked iterator examples for API patterns. Done means the iterator design, its relationship to alternating_update and observers, and the required behavior are agreed and covered by appropriate tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
hpc
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.