Skip to content
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

Use Observer for output #93

Merged
merged 18 commits into from
Jul 11, 2023
Merged

Use Observer for output #93

merged 18 commits into from
Jul 11, 2023

Conversation

emstoudenmire
Copy link
Contributor

This PR moves the task of printing output into helper functions which are put into Observers, either the step_observer! or the sweep_observer!. The tdvp function now takes advantage of this design to inject another function that prints the current time reached after each sweep.

Some other changes include:

  • calling update!(step_observer!,...) from inside local_update to avoid returning too many variables from local_update (which makes me wonder if local_update should just be inlined back into update_step?)
  • changed the "info" returned by solvers to be a NamedTuple. This seems more flexible and useful to me than solvers returning a sort of ad hoc set of values or their own custom info type. For one thing, it helps with generic code because then the info return value can be splatted into the call to update! so that the observer can have access to it.
  • [Minor change:] renamed update_sweep to default_sweep_regions
  • [Minor change:] the outputlevel >= 2 step printing prints the region rather than attempting to print a site or bond, which would be less generic

@codecov-commenter
Copy link

codecov-commenter commented Jun 23, 2023

Codecov Report

Merging #93 (41cc5d1) into main (34fd5dc) will decrease coverage by 0.05%.
The diff coverage is 62.31%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
- Coverage   79.25%   79.20%   -0.05%     
==========================================
  Files          61       61              
  Lines        3442     3458      +16     
==========================================
+ Hits         2728     2739      +11     
- Misses        714      719       +5     
Impacted Files Coverage Δ
src/ITensorNetworks.jl 77.77% <ø> (ø)
src/treetensornetworks/solvers/linsolve.jl 60.00% <ø> (ø)
src/treetensornetworks/solvers/update_step.jl 82.85% <50.00%> (-3.91%) ⬇️
src/treetensornetworks/solvers/tdvp.jl 68.25% <62.06%> (-4.09%) ⬇️
...c/treetensornetworks/solvers/alternating_update.jl 86.53% <73.33%> (+5.05%) ⬆️
src/treetensornetworks/solvers/contract.jl 91.30% <100.00%> (ø)
src/treetensornetworks/solvers/dmrg.jl 100.00% <100.00%> (ø)
src/treetensornetworks/solvers/dmrg_x.jl 100.00% <100.00%> (ø)

... and 4 files with indirect coverage changes

@emstoudenmire
Copy link
Contributor Author

Tests are passing, except for code coverage. (Can fix but it's a bit stringent when making large changes to the code.)

@mtfishman
Copy link
Member

Looks good, thanks!

I think it makes sense to keep local_update separate, I could imagine making that fully customizable in the future (i.e. letting people pass their own local_update function).

@mtfishman mtfishman merged commit 1476e5a into ITensor:main Jul 11, 2023
@emstoudenmire
Copy link
Contributor Author

Good point regarding local_update. Let's leave it for now, even though the args passing back and forth there is a bit awkward at the moment.

A good test case might be TCI when that goes in: there the solver can be simply overloaded, but the factorize step has to be customized to use the LDU method and return pivot information etc. I could envision doing this by completely overloading local_update though in that example it's probably calling for a more narrow customization like a keyword arg to factorize or a more generic callback that replaces factorize. So perhaps a full overload of local_update would be for some even more complicated/different algorithm that we aren't envisioning yet.

@mtfishman
Copy link
Member

Yeah, I agree that we also want to more narrowly be able to customize the factorize step, since that could be quite different for general region updates on trees (where the tools that @LinjianMa is developing for factorizing a network into a TTN will be helpful) or updating regions of general tensor networks, especially if we want to account for different gauges (like isometric gauges vs. the Vidal gauge).

@emstoudenmire
Copy link
Contributor Author

emstoudenmire commented Jul 11, 2023 via email

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