Skip to content

Align tutorial parameter files with their scripts and the tutorial text - #134

Open
marcusr2ML wants to merge 1 commit into
ALPSim:masterfrom
marcusr2ML:fix/tutorial-parameter-drift
Open

Align tutorial parameter files with their scripts and the tutorial text#134
marcusr2ML wants to merge 1 commit into
ALPSim:masterfrom
marcusr2ML:fix/tutorial-parameter-drift

Conversation

@marcusr2ML

@marcusr2ML marcusr2ML commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

There was a drift between parameters in the source files and the tutorials. I had Claude fix this in 2 stages already, but will rescan after this change to make sure things align.

(CLADUE)
The plain-text parm* files and the .py/.ipynb scripts that are supposed to describe the same simulation had drifted apart, so the two halves of several tutorials no longer ran the same thing. This aligns them.

DMRG follows the tutorial text; everything else follows the scripts.

Bugs (wrong results if run as-is)

  • ed-05parm_nnn-pt and parm_nnn-heisenberg declared a plain "chain lattice", which has no next-nearest-neighbour bonds. J1 was silently ignored and both runs degenerated into an ordinary Heisenberg chain — the frustration the entire tutorial is about never happened. Now "nnn chain lattice", as the two .py files in the same directory already had it.
  • ed-01tutorial1a.py had a stray = inside a dictionary key, so the diagonal correlations were registered under a name ending in = and never appeared under the expected label.
  • mc-08tutorial8d.py was a copy of tutorial8c.py with BETA = L instead of 2L, so the aspect ratio was not held fixed and the finite-size crossing could not land in the right place. It now reproduces parm8d, its actual namesake (the fine J₂ scan over 0.31–0.32). Also fixed 'W' : l/2, a float on Python 3, in tutorial8b.py and tutorial8c.py.

DMRG — matched to the text

  • CONSERVED_QUANTUMNUMBERS is now "N,Sz" throughout dmrg-03dmrg-06, matching what the pages show. Beyond the seven parm files, four artefacts still said "Sz" and are included: dmrg-04-gaps/{spin_one_gap,spin_one_gap_multiple,spin_one_half_gap_multiple}.py and dmrg-05-local-observables/spin_one.
  • Dropped dmrg-03's checked-in my_lattice.xml. It declared vertices="16", but dmrg-03 asks for a 32-site chain and dmrg-05 for 66. Both pages tell the reader to generate it with build_lattice.py, so the stale copy could only override them with the wrong lattice. Added to .gitignore.

Parameter files matched to their scripts

Tutorial Change
ed-02 parm2a/2b sweep L = 4…14, matching tutorial2a/2b.py — the extra sizes are what make the gap extrapolation work
mc-02 parm2a/2b use THERMALIZATION=10000 and a flat SWEEPS=500000
mc-03 parm3a drops a redundant repeated SWEEPS line; parm3b no longer drops to 5000 sweeps at h=1.5
mc-04 parm4 sets local_S, drops REPRESENTATION="SSE" and W
mc-06 parm6a takes CUTOFF=1000 and leaves the temperature grid to evaluateQWL; parm6d runs both L=4 (CUTOFF 500) and L=6 (CUTOFF 1000)
mc-07 parm7b uses a flat SWEEPS=150000 and scans T=2.24…2.35 at every size; parm7a's L=16 block stages its sweeps at the same temperature as L=4 and L=8

Notebooks

  • DMRG-04_Correlations.ipynb — the spin-1 cell used SWEEPS: 4 while its own parameter block and both files in dmrg-06-correlations use 6.
  • DMRG-02_Gaps.ipynbNUMBER_EIGENVALUES was set twice inside one dict literal.

Note on N_HISTOGRAM_ORDERS

No change was needed. applications/dmft/qmc/hybridization/hybsim.cpp reads parms["N_HISTOGRAM_ORDERS"] and N_ORDER appears nowhere in the DMFT code, so the tutorials were already using the correct name.

🤖 Generated with Claude Code

The plain-text parm files and the .py/.ipynb scripts that are supposed to
describe the same simulation had drifted apart, so the two halves of several
tutorials no longer ran the same thing.

DMRG follows the tutorial text:

- CONSERVED_QUANTUMNUMBERS is now "N,Sz" everywhere in dmrg-03..06, matching
  what the pages show. This covers the seven parm files plus four artefacts
  that still said "Sz": dmrg-04-gaps/{spin_one_gap,spin_one_gap_multiple,
  spin_one_half_gap_multiple}.py and dmrg-05-local-observables/spin_one.
- Drop dmrg-03's checked-in my_lattice.xml. It declared 16 vertices, but
  dmrg-03 asks for a 32-site chain and dmrg-05 for 66; both pages tell the
  reader to generate it with build_lattice.py, so the stale copy could only
  override them with the wrong lattice. Added to .gitignore.

Everything else follows the scripts:

- ed-02  parm2a/2b sweep L = 4..14, matching tutorial2a/2b.py. The extra
         sizes are what make the gap extrapolation work.
- mc-02  parm2a/2b use THERMALIZATION=10000 and a flat SWEEPS=500000.
- mc-03  parm3a drops a redundant repeated SWEEPS line; parm3b no longer
         drops to 5000 sweeps at h=1.5.
- mc-04  parm4 sets local_S and drops REPRESENTATION="SSE" and W.
- mc-06  parm6a takes CUTOFF=1000 and leaves the temperature grid to
         evaluateQWL; parm6d runs both L=4 (CUTOFF 500) and L=6 (CUTOFF 1000).
- mc-07  parm7b uses a flat SWEEPS=150000 and scans T=2.24..2.35 at every
         size; parm7a's L=16 block now stages its sweeps at the same
         temperature as L=4 and L=8.

Outright bugs:

- ed-05  parm_nnn-pt and parm_nnn-heisenberg declared a plain "chain lattice",
         which has no next-nearest-neighbour bonds. J1 was silently ignored
         and both runs degenerated into an ordinary Heisenberg chain. Now
         "nnn chain lattice", as the .py files already had it.
- ed-01  tutorial1a.py had a stray = inside a dictionary key, registering the
         diagonal correlations under the wrong observable name.
- mc-08  tutorial8d.py was a copy of tutorial8c.py with BETA = L instead of
         2L, so the aspect ratio was not held fixed and the finite-size
         crossing landed in the wrong place. It now reproduces parm8d, its
         actual namesake: the fine J2 scan over 0.31..0.32. Pointing it at
         parm8c as first suggested would have made it a duplicate of
         tutorial8c.py. Also fixed 'W' : l/2, which is a float on Python 3,
         in tutorial8b.py and tutorial8c.py.

Notebooks:

- DMRG-04_Correlations.ipynb: the spin-1 cell used SWEEPS 4 while its own
  parameter block and both files in dmrg-06-correlations use 6.
- DMRG-02_Gaps.ipynb: NUMBER_EIGENVALUES was set twice in one dict literal.

No change was needed for N_HISTOGRAM_ORDERS: hybsim.cpp reads that name and
N_ORDER appears nowhere in the DMFT code, so the tutorials were already right.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@marcusr2ML
marcusr2ML requested review from Ooolab and egull August 22, 2026 14:32

@egull egull left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks reasonable to me, but I'm not familiar with the dmrg tutorials. I suggest adding @afeiguin as a reviewer for those.
Some of the mc changes are minor and cosmetic, but some of the other changes really are not. Thanks!

@egull
egull requested a review from afeiguin August 25, 2026 07:24
@egull

egull commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Requesting a review from @afeiguin specifically for the dmrg tutorial changes.

@Ooolab

Ooolab commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Independent verification of this PR's claims

I checked each claim against the source tree and test-ran the changed files against locally built ALPS binaries. All claims hold up; everything run exits cleanly with correct physics.

The three bug claims — confirmed by direct experiment

ed-05 — Ran sparsediag on parm_nnn-pt with both lattices. With the old "chain lattice", the L=12 ground-state energy is −5.387391 for every J1 (0.0, 0.5, 1.0) — J1 really is silently ignored. With "nnn chain lattice" the energy varies with J1, and at J1=0.5 it gives exactly −4.5 = −(3/8)L, the analytically exact Majumdar–Ghosh dimer energy. (lattices.xml confirms: "chain lattice" has only type-0 edges; "nnn chain lattice" adds the type-1 offset-2 edges J1 couples to.)

ed-01 — Ran tutorial1a.py both ways. With the old stray = in the dict key, "Diagonal spin correlations" never appears in the output at all (only the Offdiagonal lines). With the fix, both observables appear.

mc-08 — Confirmed from git history that the old tutorial8d.py was tutorial8c's parameters with BETA = l instead of 2*l, and verified programmatically that the rewritten script generates exactly the same 32 tasks as parm8d. Smoke-tested the new parameters through loop — runs fine. One nuance: running loop with W=8.0 vs W=8 gives bit-identical results (E = −150.5891, same seed) — the parameter parser accepts the float, so the l//2 change is hygiene rather than an observable bug fix.

DMRG changes — ran on the real binary

  • dmrg-03/spin_one_half with CONSERVED_QUANTUMNUMBERS="N,Sz" → E0 = −13.99731562, the canonical L=32 Heisenberg-chain value. spin_one (lattice regenerated via build_lattice.py 32 per the tutorial) → E0 = −42.6514.
  • dmrg-04/spin_one_half_gap, spin_one_half_triplet (Sz_total=1 sector), and dmrg-05/spin_one all run cleanly with N,Sz.
  • Deleted my_lattice.xml: confirmed it declared 16 vertices while the DMRG-01 notebook says build_lattice.py 32 > my_lattice.xml, and only dmrg-03's spin_one/spin_one.py reference it — the stale file could only override the intended 32-site lattice. (Minor: could not verify the "dmrg-05 needs 66" detail from the repo — dmrg-05's files reference the checked-in my_lattices.xml, plural; the deletion is justified regardless.)
  • Notebook fixes (DMRG-02 duplicate NUMBER_EIGENVALUES, DMRG-04 SWEEPS 4→6) verified; dmrg-06-correlations files use SWEEPS=6, and all DMRG tutorial scripts/pages now uniformly say N,Sz.

"Parameter files matched to their scripts" — verified programmatically

A checker extracted the parameter dicts from each .py script and diffed them against parameter2xml's task output for the corresponding parm file (normalizing 1/2 vs 0.5 etc.). mc-02 a/b, mc-03 a/b, mc-04, mc-06 a/d, mc-07 a/b, mc-08 d, and ed-02 a/b all match exactly (ed-02 matches as a set — script orders tasks by L-then-Sz, parm file by Sz-then-L; mc-04's only diff was True vs true).

Full runs of the changed parm files — all exit 0 with sensible physics

File Result
ed-02/parm2a Spin gap shrinks monotonically L=4→14 (1.000 → 0.459), heading toward the Haldane gap 0.4105 — the added L=12,14 points are what the extrapolation needs
mc-02/parm2a Smooth χ(T) over all 15 temperatures at 500k sweeps
mc-03/parm3a,3b Textbook m(h): saturates at m=0.5 exactly above h=2, the spin-½ chain saturation field
mc-04/parm4 Runs under dirloop_sse with local_S=1/2; all promised observables present (Spin Correlations, Structure Factor, Green's Function)
mc-06/parm6a,6d QWL runs; evaluateQWL supplies the T grid as intended; 6d specific-heat peaks at T≈1.05 (L=4) and ≈0.95 (L=6), converging on cubic-Heisenberg Tc ≈ 0.946
mc-07/parm7b Full 36-task run; Binder-ratio curves for L=32/48/64 cross between T=2.26–2.28, bracketing the exact Ising Tc = 2.2692 — the crossing now lands inside the scanned window

Also confirmed the N_HISTOGRAM_ORDERS non-change: hybsim.cpp:59 reads parms["N_HISTOGRAM_ORDERS"] and bare N_ORDER appears nowhere in the DMFT code.

Not run at full scale: tutorial8d.py as written (L=128, β=256, 50k sweeps × 32 tasks is a multi-day job) — its parameters were smoke-tested instead; the full parm7a (63 tasks) and the mc-02/ed-02 "b" variants were validated via the parameter-equivalence check rather than execution.

Overall: the PR does what it says, and the two headline physics bugs (ed-05's missing frustration, mc-08's wrong aspect ratio) are real and really fixed. Only wording nitpicks: the harmless-in-practice float W, and the unverifiable "66-site" detail for dmrg-05 — neither affects the changes.

🤖 Generated with Claude Code

@Ooolab Ooolab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test runs all passed successfully!

@marcusr2ML

Copy link
Copy Markdown
Collaborator Author

@egull Yes, DMRG needed A LOT of work.

The tutorials were broken before, so that is why there were so many changes and why DMRG-05 has extra examples. The original .md file described the results of a pure spin-1 chain in the text, but the simulations were for spin-1/2's attached at the ends. This was very confussing... so I just made the tutorial cover both these cases.

Adrian did verify he liked this idea via email after I showed him the two plots, even the change in system size 32->64. This was all part of testing his latest dmrg code before approval. I'll wait for his response here still.

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