Skip to content

Add Documenter docs and docstrings#300

Open
emstoudenmire wants to merge 12 commits intomainfrom
MS_documenter
Open

Add Documenter docs and docstrings#300
emstoudenmire wants to merge 12 commits intomainfrom
MS_documenter

Conversation

@emstoudenmire
Copy link
Contributor

This PR adds docstrings to many user-facing functions and create a Documenter setup plus additional Documenter content.

All content (docstrings and Documenter pages) have been manually checked, and I ran and tested the example codes appearing in the Documenter. I created a file test/test_documentation_examples.jl for this purpose.

One question is whether there should be a whole page on the TreeTensorNetwork type, or whether we should somewhat de-emphasize that type. I think it might be better to leave it clearer for someone who is trying to understand the structure of the code and who might occasionally see issues where one needs to convert to the ITensorNetwork type, and so must appreciate that it is a different type.

Comment on lines +74 to +80
When computing multiple operators on the same state, reuse the belief propagation cache
to avoid redundant work:

```julia
using ITensors: Op
sz = expect(psi, Op("Sz", v)) # single-operator form
```
Copy link
Member

@mtfishman mtfishman Mar 2, 2026

Choose a reason for hiding this comment

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

The test mentions reusing the BP cache, but the code doesn't show that. Also, I'm not sure if we should be showing Op here, that seems a bit low-level. Maybe best to delete this part and rethink it?

sz = expect(psi, "Sz")

# Selected vertices only
sz = expect(psi, "Sz", [(1,), (3,), (5,)])
Copy link
Member

Choose a reason for hiding this comment

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

This passes vertices as arguments while below it passes them as keyword arguments, better to be consistent. I don't remember what the intended preferred syntax was.

Comment on lines +41 to +44
nsweeps = 10,
nsites = 2,
factorize_kwargs = (; cutoff = 1e-10, maxdim = 50),
outputlevel = 1,
Copy link
Member

Choose a reason for hiding this comment

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

Not a big deal, but I personally don't like this formatting where the = are aligned across lines.

psi = orthogonalize(psi, [v1, v2]) # two-site center (for nsites=2 sweeps)

ortho_region(psi) # query current ortho region (returns an index set)
psi = set_ortho_region(psi, vs) # update metadata only, no tensor operations
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we shouldn't document this since it is really more of an internal/expert function (users should generally be orthogonalizing).

```@docs; canonical=false
ITensorNetworks.orthogonalize
ITensorNetworks.ortho_region
ITensorNetworks.set_ortho_region
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above.

@mtfishman
Copy link
Member

mtfishman commented Mar 2, 2026

All content (docstrings and Documenter pages) have been manually checked, and I ran and tested the example codes appearing in the Documenter. I created a file test/test_documentation_examples.jl for this purpose.

It would be nice to set it up so that examples interspersed in the docs are run during CI and we get some indication that they at least run without erroring. I think the minimal change to make to achieve that would be to change over the julia codeblocks to @example codeblocks (https://documenter.juliadocs.org/stable/man/syntax/#reference-at-example) which get run by Documenter when the docs are built. Then, if we remove warnonly = true from makedocs in docs/make.jl, if the examples don't run the docs build will fail so we know to look into the examples as a potential issue. test/test_documentation_examples.jl isn't really a sustainable solution since that would need to be updated as the docs are updated, which isn't very practical and that process itself would be error-prone.

(Note that you can do fancier things where you turn them into proper tests where you check the output: https://documenter.juliadocs.org/stable/man/doctests but we don't have to do that here, just pointing it out for future reference.)

One question is whether there should be a whole page on the TreeTensorNetwork type, or whether we should somewhat de-emphasize that type. I think it might be better to leave it clearer for someone who is trying to understand the structure of the code and who might occasionally see issues where one needs to convert to the ITensorNetwork type, and so must appreciate that it is a different type.

Since it plays an important role in the existing form of the library it seems reasonable to document it.

@codecov
Copy link

codecov bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.50%. Comparing base (87826ee) to head (e1e5809).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #300      +/-   ##
==========================================
+ Coverage   69.07%   71.50%   +2.43%     
==========================================
  Files          81       81              
  Lines        4029     4029              
==========================================
+ Hits         2783     2881      +98     
+ Misses       1246     1148      -98     
Flag Coverage Δ
docs 36.58% <ø> (+36.58%) ⬆️

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.

@mtfishman
Copy link
Member

@emstoudenmire I changed over most docstrings to regular comments so the API Reference list is much smaller. We can add them back as needed.

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