Skip to content

ci: tests, README steps, format check and dependabot - #6

Merged
NaNIsaac merged 8 commits into
mainfrom
chore/conventions
Oct 23, 2026
Merged

NaNIsaac merged 8 commits into
mainfrom
chore/conventions

Conversation

@NaNIsaac

Copy link
Copy Markdown
Owner

Tier: medium

  • Adds tests, a pytest job, dependabot, the ruff format check and a tested README install step; no experiment script changes.
  • uv.lock changes (pytest in the dev group; torch from PyPI on macOS; wxpython dropped on Linux).
  • One source change: abeles_np now computes in complex128 for float64 input (abeles_np always computes in complex64 because of a dtype identity check #5). The function is not called anywhere in the repository.

Stacked on #4.

C10 items:

  • dependabot.yml (github-actions, monthly), ruff format --check in lint.yml, readme.yml calling the shared workflow, and ci.yml running pytest. The README install block is split so git clone is plain and uv sync plus uv pip install -e . are the tested step.
  • tests/ (24 tests, 3 s): the utilities in io_utils, math_utils, physics_utils; both Abeles engines against a Parratt recursion written in the test; and the run paths from fix: evaluate the run main.py trained, not a fixed folder #4 / exp02/exp04 evaluate scripts read a fixed folder, not the run main.py trained #3 (below).
  • Formatting: ruff format over 96 files in its own commit. The parsed syntax of every .py file is unchanged apart from a docstring's leading space (checked with a script that compares ast).

Found while writing the tests, with the failing test committed before each fix:

  • abeles_np always computes in complex64 because of a dtype identity check #5: q.dtype is np.float64 is never true, so abeles_np always used complex64 (rel. error 2e-5 against the Parratt recursion; 2.6e-15 after the fix). Test commit 36fdf77 fails on 3 cases, d0be930 fixes it.
  • The torch engine is off by up to 4.4e-7 relative against the same recursion, near a critical edge (q = 0.0224 for SLD 10). It comes from 4 * math.pi * sld on a complex128 tensor, where the product shows about 1.5e-8 relative error, which is single-precision rounding of the scalar. I did not change it (it feeds the training data, so it is a physics-tier decision); the test allows 1e-5. Not reported as an issue yet.
  • append_timestamp("scan.dat") returns scan.dat_<time>.dat, the suffix twice. The docstring says the format is not fixed, so the test only checks that the suffix and folder are kept.

The run-path test (ReflectoExp#3, fixed by #4): exp02 and exp04 evaluate scripts take the run folder from CONFIG["base_dir"] / CONFIG["exp_name"], as their main.py does, and no longer contain the hard-coded XRR_AI\data\one_layer\run. It reads the source lines because the scripts run under __main__ and need data on disk.

Two things the README job needed, both in pyproject.toml:

  • macOS could not resolve: all three torch packages came only from the cu128 index, which has no macOS wheels. They now use it for every platform but macOS.
  • On Linux, genx3 pulls wxpython, which has no Linux wheel and fails to build without GTK headers, the same failure as ReflectoLearn#13 / #26. Dropped there with an override.

Local checks (Windows, Python 3.13, ruff 0.17.1): ruff check and ruff format --check pass, pytest 24 passed. uv pip compile resolves macOS, Linux and Windows. The README step was not run through readme-test.ps1; this PR's CI is the first run of the new jobs.

conventions.py check ReflectoExp reads the main checkout, not this branch. On main it reports the four findings this PR addresses (dependabot, format check, src without tests, README steps). I did not rerun it on the branch.

@NaNIsaac

Copy link
Copy Markdown
Owner Author

Physics follow-up on the 4.4e-7 note (BACKLOG R2e). Measured on your three stacks and Q grid:

  • Computing 4 * math.pi * sld in complex128 alone leaves 7.3e-7, so the scalar product is not the cause.
  • The cause is the test input. torch.tensor([x]) builds thickness, roughness and sld as float32 (torch's default dtype). The engine picks complex128 from the float64 q, but (sld - sld[..., :1]) * 1e-6 is then evaluated in float32.
    • With sld alone in float64 the engine matches your Parratt recursion to 8.9e-15. With everything in float64 it is the same.
    • With float32 parameters, as now, the worst case is 2.3e-6 (the 250 Å / 45 stack), not 4.4e-7.
  • The error peaks just above the substrate's critical q (0.0323 vs q_c 0.0317), where k² = q²/4 − 4πρ cancels and amplifies the rounding.

Suggestion for this PR: build the parameters with dtype=torch.float64 in test_torch_engine_matches_the_parratt_recursion and tighten rtol to 1e-12. That tests the engine, not float32 input rounding.

The float32-input case is negligible for fitting: the linearised bias it causes is ≤ 0.22 % of the Cramér–Rao bound at 1e8 counts. Details are in the workspace notes (docs/r2e).

@NaNIsaac
NaNIsaac changed the base branch from fix/evaluate-reads-own-run to main October 23, 2026 06:34
@NaNIsaac
NaNIsaac merged commit 65d150a into main Oct 23, 2026
5 checks passed
@NaNIsaac
NaNIsaac deleted the chore/conventions branch October 23, 2026 15:51
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.

1 participant