Skip to content

maintenance: raw-string the LaTeX-carrying docstrings - #73

Merged
Jammy2211 merged 1 commit into
mainfrom
claude/latex-raw-string-docstrings-9h4ine
Aug 20, 2026
Merged

maintenance: raw-string the LaTeX-carrying docstrings#73
Jammy2211 merged 1 commit into
mainfrom
claude/latex-raw-string-docstrings-9h4ine

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Part of PyAutoLabs/autolens_workspace#491 — one of six independent, prose-only PRs (one per workspace repo). No API surface, so no cross-repo merge ordering.

This repo carries the defect the whole task was filed on. In chapter_4_scaling_up_lensing/tutorial_3_scaling_relation.py, \theta_E was stored as TAB + "heta_E" — a silent corruption with no diagnostic whatsoever. Confirmed repaired: the docstring value now holds a real backslash and contains no TAB.

what it is diagnostic
warned \s, \l, \[ — escapes Python does not recognise SyntaxWarning per compile; slated to become SyntaxError
silent \t in \theta, \f in \frac, \r in \rm none at all — the value is simply corrupted

chapter_4_scaling_up_lensing/tutorial_5_cluster_scale.py has only silent hits and zero warnings, so a warning-only sweep skips it entirely. It is included here.

32 literals across 8 files get the r prefix. Both sweeps now return zero. Prose is untouched — only the delimiter gains an r.

Verification

  • Baseline regeneration is a no-op — the generator was run before editing and left the tree clean, so generator noise cannot fake the gate below.
  • Runtime values: 21 corruptions repaired, 0 other changes. Every changed literal's value was compared HEAD vs worktree; the prefix may only ever remove corruption. This is the check that catches real mistakes — the regeneration gate structurally cannot, because the generator reads source text, not runtime values.
  • Regenerated with autohands: notebooks/, markdown/, llms-full.txt and workspace_index.json are all byte-identical — the diff-empty gate passes exactly.

Two docstrings needed a hand-approved prefix, both read in full first: chapter_2_lens_modeling/tutorial_1_non_linear_search.py has pre-existing malformed nested LaTeX the math-span matcher cannot bracket, and tutorial_3_scaling_relation.py writes bare \sigma/\theta_E/\pi in undelimited equation blocks. Neither carries a deliberate escape. Malformed delimiters were left exactly as found.

Left alone deliberately

Real newlines in print() and already-escaped LaTeX line breaks. The prefix was applied only where every backslash in the literal sits in a LaTeX context ($…$, \(…\), \[…\], \begin{}…\end{}, or a markdown code span), with an absolute veto on \\, escaped quotes and numeric escapes regardless of context.

Unblocked by PyAutoHands#251, which taught the notebook and env parsers to accept an r""" opener.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MTjtx5mdituitiyQYFGn2E


Generated by Claude Code

Non-raw docstrings containing LaTeX are corrupted by Python's escape handling.
Two distinct failure classes, and only the first is visible:

  warned  `\s`, `\l`, `\[` ... escapes Python does NOT recognise. It leaves
          them literal but emits SyntaxWarning on every compile/import, and
          they are slated to become a SyntaxError.
  silent  `\t` in `\theta`, `\f` in `\frac`, `\r` in `\rm`, `\b` in `\beta`.
          Escapes Python DOES recognise: the value is corrupted with NO
          diagnostic at all. `\theta_E` was literally TAB + "heta_E".

32 literals across 8 files get the `r` prefix. Both sweeps now return zero.

Verified, not assumed:
- Runtime values: 21 corruptions repaired, 0 other changes. Every changed
  literal's value was compared HEAD vs worktree; the prefix may only ever
  REMOVE corruption, never alter a string otherwise.
- Regenerated with autohands: notebooks/, markdown/, llms-full.txt and workspace_index.json are ALL byte-identical -- the diff-empty gate passes exactly.

This repo carries the defect the original prompt was filed on:
chapter_4 tutorial_3_scaling_relation.py had `\theta_E` stored as TAB + "heta_E".
Confirmed repaired -- the docstring value now holds a real backslash and no TAB.
chapter_4 tutorial_5_cluster_scale.py has ONLY silent hits and zero warnings, so
a warning-only sweep would have skipped it entirely; it is included here.

Prose is untouched -- only the delimiter gains an `r`. Deliberate escapes were
left alone (real newlines in print(), already-escaped LaTeX line breaks): the
prefix was applied only where every backslash sits in a LaTeX context.

Copy link
Copy Markdown
Collaborator Author

Smoke is red on this PR, but the failure is on main, not here — merging despite the red check on that basis.

Two scripts fail with numba Pass nopython_type_inference:

chapter_3_pixelizations/tutorial_8_adaptive_pixelization.py
chapter_3_pixelizations/tutorial_11_brightness_adaption.py

Evidence it isn't this PR:

  • Neither file is in the diff, and all 8 files that are pass smoke — including tutorial_5_bayesian_formalism.py in the same directory.
  • The failure reproduced identically on one re-run.
  • Control experiment: I re-ran the last green main build (run 255, commit dcb67e9, zero changes from this branch, fresh dependency install). It now fails on the same script with the same error — the Slack payload from that run reads HowToLens/main smoke tests (Python 3.12) failure. So main itself is red.
  • A one-character r prefix on a docstring cannot cause a numba typing failure.

Likely cause, not proven: PyAutoLabs/PyAutoArray#453 ("in-place Cholesky buffer + copy-free numba solves for fnnls_cholesky") merged at 22:09:30 UTC, minutes before these runs. CI builds autoarray from source at HEAD, and the last green main run (04:29 UTC) predates it. fnnls is the NNLS solver pixelization reconstruction uses, and the two failing scripts are the adaptive-pixelization ones.

I tested two specific mechanisms under the exact CI versions (numba 0.67.0 + scipy 1.17.1) and both passed — a strided Ubuf view into _cholupdate, and the newly-introduced np.dot inside _cho_solve_buffer (correct to 2.8e-17). I also ruled out a new numba release: 0.67.0 shipped nine days before the last green run. So the attribution rests on timing and code area, not a reproduced mechanism — worth a look from someone who owns that solver.

This PR's own verification is unaffected: 21 corruptions repaired with 0 unexpected value changes, and notebooks/, markdown/, llms-full.txt and workspace_index.json all byte-identical after regeneration.


Generated by Claude Code

@Jammy2211
Jammy2211 merged commit ffc2294 into main Aug 20, 2026
6 of 10 checks passed
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