Skip to content

Fill out the docs for the Boson, Fermion, Hubbard and t-J operators - #58

Merged
lkdvos merged 6 commits into
mainfrom
electron-docs
Jul 31, 2026
Merged

lkdvos merged 6 commits into
mainfrom
electron-docs

Conversation

@lkdvos

@lkdvos lkdvos commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

Closes #45.

spinoperators.md and quantumgates.md were full documentation pages; the other four were 9-line bare @autodocs stubs. This brings all six to the same structure — Conventions (basis ordering, symmetry sectors), an operator overview table, then the @autodocs API section. Since @autodocs only renders what the docstrings contain, the docstrings were upgraded in step: math definitions, matrix elements, and an explicit Supported symmetries: line where Boson/Fermion had none and Hubbard had only ad-hoc prose.

Rendered preview

Mostly prose, tables and math, so much easier to review rendered than as a diff:

Page Preview
Boson operators https://quantumkithub.github.io/TensorKitTensors.jl/previews/PR58/bosonoperators/
Fermion operators https://quantumkithub.github.io/TensorKitTensors.jl/previews/PR58/fermionoperators/
Hubbard operators https://quantumkithub.github.io/TensorKitTensors.jl/previews/PR58/hubbardoperators/
t-J operators https://quantumkithub.github.io/TensorKitTensors.jl/previews/PR58/tjoperators/

Full preview: https://quantumkithub.github.io/TensorKitTensors.jl/previews/PR58/

Notable decisions

  • The Hubbard/t-J overview tables use separate particle and spin columns. Exact, not an approximation: every has_*(P, S) predicate in the test suite factorizes into an independent condition per axis.
  • The basis-ordering sections document the parity-sorted reference order — for Hubbard |0⟩, |↑↓⟩, |↑⟩, |↓⟩, not the enumeration used so far, which is not an index order anywhere and read as a competing convention against basis_transform.
  • The dense order of the symmetric spaces is a recipe, not a table, since it follows TensorKit's sector sorting and is not part of the interface; tabulating it could silently desync.
  • The t-J page documents slave_fermion, including the warning that transform_slave_fermion does not distribute over ⊗.

Fitting the t-J docstrings to #57

#57 made each t-J operator docstring inherit its description from the HubbardOperators docstring of the same name, so this prose lives in HubbardOperators and reaches TJOperators through the inheritance. Two rules follow:

  • Hubbard-only statements go into admonitions, the mechanism Refactor TJOperators to the dense-first strategy #57 already uses for the staggered-gauge note. That now also covers the nonzero-matrix-element listings (basis-specific) and the SU2Irrep-particle remarks (t-J has no such symmetry). Shared prose is worded to hold in both spaces, so eigenvalue listings characterize the states they act on rather than enumerate a fixed basis.
  • The symmetry line is derived, not restated. t-J supports exactly the Hubbard combinations minus SU2Irrep particle symmetry — the η-pairing doublet (|↑↓⟩, |0⟩) loses its doubly occupied state to the projection — so _project_symmetries strips that entry from the inherited line. Spin symmetries carry over verbatim for all 31 operators.

Trade-off worth flagging: per-operator prose true only of t-J has no home under this design (that n never exceeds one, that nʰ + n = 1). Both are stated on the t-J page instead.

Bugs found along the way

  • HubbardOperators.h_num did not count holes. It was 1 - n, returning -1 on the doubly occupied state; now (1 - nꜛ)(1 - nꜜ), the projector onto the empty state. Invisible through the t-J projection — the discrepancy lives entirely on |↑↓⟩, which the projector removes — so TJOperators.h_num agreed either way. Tests now pin down idempotency and nʰ + n = 1 + nꜛnꜜ.
  • boson_space(; cutoff) was a MethodError, unlike every other module's space constructor, while its docstring already advertised the symmetry argument as optional.
  • An inherited @ref cannot name a Hubbard-only binding. h_num's See also ud_num broke cross-references on the t-J page; it moves into the admonition with the rest of the double-occupancy caveat.

Also

Documenter compat bumped to 1.9, which introduced checkdocs = :public (on 1.8.x the symbol is unvalidated and silently disables the check). operatorpages puts Hubbard before t-J, since the t-J page refers to it several times. Harmonized on Supported symmetries package-wide. Assorted typos, and T → elt in FermionOperators for consistency.

Verification

  • Full test suite passes: 2387 tests. Runic clean, docs build clean.
  • 855 symmetry combinations checked against the overview tables, 0 mismatches — tables parsed out of the markdown, every listed combination asserted to construct and every unlisted one to throw, across both t-J bases.
  • All 31 generated t-J docstrings audited: no Hubbard-only text inherited, every symmetry line correct.
  • 440 math expressions validated against KaTeX — Documenter renders math client-side, so a glyph with no font metrics gives a clean build and a blank on the page.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/tjoperators.jl 66.66% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/bosonoperators.jl 95.55% <100.00%> (ø)
src/fermionoperators.jl 95.00% <100.00%> (ø)
src/hubbardoperators.jl 98.89% <100.00%> (+<0.01%) ⬆️
src/quantumgates.jl 100.00% <ø> (ø)
src/spinoperators.jl 91.57% <ø> (ø)
src/tjoperators.jl 97.97% <66.66%> (-0.98%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from ld-tj to main July 30, 2026 03:06
lkdvos and others added 4 commits July 30, 2026 09:46
Rewrite the two stub pages to the structure of the spin operator page:
conventions with basis ordering and symmetry sectors, an operator overview
table, and the autodocs API section.

Upgrade the corresponding docstrings to match, adding the math definitions,
matrix elements and `Compatible symmetries:` lines that were missing.

Also add the default-symmetry method to `boson_space`, which every other
module has and its own docstring already advertised, and bump the Documenter
compat bound to 1.9, the version that introduced `checkdocs = :public`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Closes the main part of #45. Both stub pages now follow the structure of the
spin operator page: conventions with basis ordering and symmetry sectors, an
operator overview table, and the autodocs API section.

Since both modules take two independent symmetry arguments, the overview
tables carry separate particle and spin columns. This is exact rather than an
approximation: every availability predicate in the test suite factorizes into
an independent condition per symmetry axis.

The basis-ordering sections document the parity-sorted reference order
(|0>, |updn>, |up>, |dn> for Hubbard) rather than the enumeration order used
in the prose so far, and give a recipe for reading off the dense order of the
symmetric spaces instead of tabulating it, since it follows TensorKit's sector
sorting and is not part of the interface.

The t-J page additionally documents the slave-fermion keyword, including the
warning that the transformation does not distribute over tensor products, and
the projection relation to the Hubbard model.

Upgrade the docstrings of both modules to match: math definitions where they
were missing, and an explicit `Compatible symmetries:` line replacing the
ad-hoc prose notes. Since #57 made the t-J operator docstrings inherit their
description from the Hubbard docstring of the same name, that prose now lives
in `HubbardOperators` and reaches `TJOperators` through the inheritance, which
imposes two rules on it:

- Anything true only of the Hubbard space goes into an admonition, the
  mechanism #57 already uses to keep the staggered-gauge note out of the t-J
  docs. That now also covers the listings of nonzero matrix elements, which
  are basis-specific, and the remarks about `SU2Irrep` particle symmetry,
  which t-J does not have. The shared prose is worded to hold in both spaces,
  which is why the eigenvalue listings characterize the states they act on
  instead of enumerating a fixed basis.

- The symmetry line is derived rather than restated. t-J supports exactly the
  Hubbard combinations minus `SU2Irrep` particle symmetry, because the
  eta-pairing doublet (|updn>, |0>) loses its doubly occupied state to the
  projection, so `_project_symmetries` strips that one entry from the
  inherited line. The spin symmetries carry over verbatim, for all 31
  operators of the registry.

Along the way:
- `HubbardOperators.h_num` is `1 - n`, so it takes the value -1 on the doubly
  occupied state rather than counting holes as its docstring claimed. Document
  what it actually does, and point to the t-J module, where it is a genuine
  projector.
- Fix a few typos and an inconsistent float literal.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…metries"

`h_num` was implemented as `1 - n`, which returns -1 on the doubly occupied
state instead of counting holes as its docstring described. Implement it as
the projector onto the empty state, `(1 - nꜛ)(1 - nꜜ)`, matching both the
documented intent and `TJOperators.h_num`.

The bug survived because it is invisible through the t-J projection: the
discrepancy lives entirely on the doubly occupied state, which the projector
removes, so `TJOperators.h_num` agreed either way. Add tests pinning down the
two properties that distinguish them, idempotency and `nʰ + n = 1 + nꜛnꜜ`.

Symmetry availability is unchanged: the projector onto the empty state is
still a spin scalar and still not an eta-pairing scalar.

With the implementation fixed the docstring no longer has to warn that the
operator contradicts its own name, and what remains of the caveat -- that the
doubly occupied state is not a hole -- is Hubbard-specific, so it moves into
an admonition and stops being inherited by `TJOperators.h_num`. The pointer to
`ud_num` moves along with it, which it has to: an unqualified `@ref` to
`ud_num` in the shared prose cannot resolve on the t-J page, since that module
has no such binding.

Also harmonize on "Supported symmetries" package-wide, replacing the
"Compatible symmetries" wording used in the docstrings and in the quantum
gates overview table.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Replace the LaTeX commands that have a direct unicode equivalent, matching the
convention the package already used for kets, arrows and greek letters:
\rangle, \uparrow, \dagger, \otimes, \eta, \mapsto, \cdot, \ldots, \mathbf{S}
and friends, along with the simple radicals \sqrt{2} and \sqrt{n}.

Kept as LaTeX where there is no unicode equivalent, or where the command is
structural rather than a symbol: \mathrm, \text, \tfrac, \underbrace, the
pmatrix environments, the spacing macros, and the two radicals that have to
span a compound expression.

Validating every math expression against KaTeX turned up two rendering bugs
that the docs build cannot catch, since Documenter renders math in the browser:
`↤` and `bꜛ`/`bꜜ` have no font metrics and came out blank in math mode. Move
the former into the fenced matrix-element blocks used elsewhere in the module,
and the latter into code spans, where they belong anyway.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@lkdvos lkdvos linked an issue Jul 30, 2026 that may be closed by this pull request
@lkdvos
lkdvos requested a review from Yue-Zhengyuan July 30, 2026 14:42
Yue-Zhengyuan
Yue-Zhengyuan previously approved these changes Jul 31, 2026
@Yue-Zhengyuan

Copy link
Copy Markdown
Member

There are still some mentions of where the nonzero elements are in the operators, which I think are unnecessary.

@lkdvos
lkdvos merged commit e3be3c0 into main Jul 31, 2026
8 of 9 checks passed
@lkdvos
lkdvos deleted the electron-docs branch July 31, 2026 15:26
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.

More detailed explanation of Hubbard and tJ operators in docs

2 participants