Repository navigation
Description
Overview
Reader-reported fixes to HowToFit chapter 1 tutorials 1-3: tutorial 1 opens on the
model equation with no picture of the data it describes, display/inline math in
tutorials 2 and 3 uses \[ \] / \( \) delimiters that Jupyter and Colab do not
typeset, and tutorial 3's MLE initialisation starts far enough from the truth that
LBFGS does not reliably converge. The reader also hit ModuleNotFoundError: No module named 'emcee' on Colab, whose root cause is the --no-deps Colab bootstrap in
PyAutoNerves, not HowToFit.
Plan
- Tutorial 1 — show the 1D Gaussian dataset (errorbar figure, as the RTD
python_apipage does) before the Gaussian equation and itsWhere:list, using
the same auto-simulation guard tutorials 2 and 3 already use. - Tutorial 1 — replace the model-figure "identical composition" paragraph with the
reader's wording, and close the Extensibility section with a worked 18-parameter
model (x2Gaussian+ x4Exponential) showing onlymodel.infoand the figure. - Tutorial 1 — backtick the bare
af.Model/Model/Gaussiancode references
and sweep the rest of chapter 1 for the same miss; fix the typos found in the audit. - Tutorials 1-3 — convert
\[ ... \]to$$ ... $$and\( ... \)to$ ... $so
the equations render in Jupyter, Colab and nbviewer. - Tutorial 3 — move the MLE
InitializerParamStartPointscloser to the truth
(50 / 25 / 10) so the fit converges reliably while still being a visibly imperfect
starting guess. - PyAutoNerves — add
emceeanddynestyto the Colab_SHARED_EXTRASinstall
list so--no-depsstops silently dropping two real autofit dependencies. - Regenerate notebooks + navigator catalogue and run the smoke suite.
Detailed implementation plan
Affected Repositories
- HowToFit (primary)
- PyAutoNerves
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./HowToFit | main (behind origin) | clean |
| ./PyAutoNerves | main | clean |
Suggested branch: feature/howtofit-tutorials-1-3
Branch-claim waiver. worktree_check_conflict exits 1 on HowToFit with two
claims: howtofit-mode (scope there is one uncommitted README.md, no commits
ahead — disjoint) and model-figure-prose-simplify (PR #56, open, all checks
green, which rewrites the same tutorial 1 model-figure paragraphs). The overlap
with #56 is real, so this task stacks on #56 rather than racing it: the branch
is cut from origin/feature/model-figure-prose-simplify and the PR is opened
against that base, so the diff shows only this task's changes and GitHub retargets
it to main once #56 merges. Merge #56 first. Where the two disagree — the
"identical composition" paragraph — the reader's wording in this issue is the newer
instruction and wins.
Implementation Steps
scripts/chapter_1_introduction/tutorial_1_models.py— in Model
Parameterization, add the dataset figure ahead of the equation: copy the
dataset_path = path.join("dataset", "example_1d", "gaussian_x1")+
auto-simulationsubprocessguard +af.util.numpy_array_from_jsonloads +
plt.errorbarblock fromtutorial_3_non_linear_search.py(lines 157-197), with
a short lead-in sentence. Requiresfrom os import pathat the tutorial head.
Keep the existing equation andWhere:list immediately after it.- Same file — fix the equation typos:
g(x, I, \sigma)->g(x, N, \sigma)and
g(x, I, \lambda)->g(x, N, \lambda); the "three parameters" line naming
(x, N, \sigma)->(centre, N, \sigma);ratw->rateand "has fast" ->
"how fast" in theExponentialdocstring;Exponential.model_data_from's
docstring "Returns a 1D Gaussian" -> "1D Exponential"; the
print("sigma (Exponential) = ", instance.exponential.rate)label ->rate; the
"If you don't have a HowToFit clone" URL -> the HowToFit repo; the stray double
blank line in theWhere:list. - Same file — backtick bare code references:
af.Model(Model Mapping intro),
Modelobject (Model Creation),Gaussianclass. Sweep the other chapter 1
scripts for the same miss (log_likelihood_functionin
tutorial_4_why_modeling_is_hard.py,Samples/Resultin
tutorial_5_results_and_samples.py) and fix only unambiguous code references —
ordinary English uses of "Gaussian" stay plain. - Same file — replace the model-figure "identical composition" paragraph with the
reader's two paragraphs, verbatim. - Same file — after "These objects serve numerous other essential purposes...",
add the worked extensibility example: anaf.Collectionof x2Gaussian+
x4Exponential(18 free parameters), thenprint(model.total_free_parameters)
is not wanted — onlyprint(model.info)andaf.ModelPlotter(model).figure(). tutorial_2_fitting_data.py— convert the display math at the normalized-residual,
chi-squared (x2), noise-normalization and log-likelihood blocks from\[ \]to
$$ $$. Check the surrounding docstrings are raw (r""") where backslashes need
to survive.tutorial_3_non_linear_search.py— same conversion in the Parameter Space
section, including the inline\( x \)forms ->$x$; also fix the parameter
naming(x, I, \sigma)there.tutorial_3_non_linear_search.py— moveInitializerParamStartPointsfrom
centre=55.0, normalization=20.0, sigma=8.0to a closer but still visibly wrong
guess against the truth50.0 / 25.0 / 10.0; verify by running the tutorial that
the fit converges (max log likelihood instance within a few percent of truth).PyAutoNerves/autonerves/setup_colab.py— add"emcee>=3.1.6"and
"dynesty==2.1.5"to_SHARED_EXTRAS(matchingPyAutoFit/pyproject.toml),
with a comment saying why a--no-depsinstall has to name them. Check
PyAutoNervestests for any assertion over that list.- Regenerate notebooks + catalogue from the HowToFit repo root:
PYTHONPATH=../PyAutoHands/autohands python3 ../PyAutoHands/autohands/generate.py howtofit,
then runpython .github/scripts/run_smoke.pyuntil green.
Key Files
HowToFit/scripts/chapter_1_introduction/tutorial_1_models.py— data figure, worked 18-parameter example, prose replacement, typosHowToFit/scripts/chapter_1_introduction/tutorial_2_fitting_data.py— math delimitersHowToFit/scripts/chapter_1_introduction/tutorial_3_non_linear_search.py— math delimiters, MLE start pointHowToFit/notebooks/chapter_1_introduction/*.ipynb— regenerated, never hand-editedPyAutoNerves/autonerves/setup_colab.py—_SHARED_EXTRASColab install list
Out of scope (follow-up)
Tutorials 6, 7 and tutorial_optional_bayesian_formalism.py carry the same
unrendered \[ \] / \( \) blocks; the reader scoped this task to tutorials 1-3.
Original Prompt
Click to expand starting prompt
# HowToFit tutorials 1-3: data figure, math rendering, MLE start point
Type: docs
Target: HowToFit
Repos:
- HowToFit
- PyAutoNerves
Themes:
- howtofit
- notebooks
- rendering
- colab
Difficulty: medium
Autonomy: safe
Priority: normal
Status: formalised
Consequence: judge
Review-minutes: 20
Unattended: ready
Filed: 2026-09-14
## User request (verbatim)
Fixes to HowToFit tutorials 1 through 3, auto all the way to PR without asking me HowToFit:
Tutorial 1
show image of 1D Gaussian data (from the RTD example) with brief explanatory text after:
"Where:
x: The x-axis coordinate where the Gaussian is evaluated.
N: The overall normalization of the Gaussian.
\sigma: The size of the Gaussian (Full Width Half Maximum, FWHM , is 22ln2−−−−√σ )."
An af.Model did not have `` around it to look like code, fix that and make sure its ok through HowTo.
Replace:
same issue here albeit it is less technical:
The figure is identical to the previous one too, and that is the point worth taking from this example. The two ways of writing the composition look different on the page, but they build the same structure, and structure is all the map draws. Whenever you change how a model is written, draw it: if the map does not move then nothing about the model moved either, and any difference between the two fits has to be hiding in the legend rather than in the model.
With:
The figure is identical to the previous example, because both ways of writing the model produce the same model structure.
This is a useful check when composing models in different ways: if the figure looks the same, the underlying structure of the model is the same too. Any differences between the fits must therefore come from details such as the parameter priors or fixed values, rather than how the model is composed.
Can you end tutorial 1 here:
Extensibility
It should now be clear why we use Model and Collection objects to construct our model.
These objects facilitate the straightforward extension of our models to include multiple components and parameters. For instance, we can add more Gaussian and Exponential components to the Collection, or define new Python classes to represent entirely new model components with additional parameters.
These objects serve numerous other essential purposes that we will explore in subsequent tutorials.
With an actual example which uses the API, Gaussian and Exponential to compose an 18 parameter model of x2 Gaussian
and x4 Expoentnial, displaying its model.info and image but nothing else.
Also look for typos
Tutorial 2:
Make sure stuff like this displays correctly in jupyter:
[ \text{normalized_residual} = \frac{\text{residual_map}}{\text{noise_map}} = \frac{\text{data} - \text{model_data}}{\text{noise_map}} ]
Also look for typos
Tutorial 3:
Again certain equations especially in the parameter space bit are not math formatted.
The MLE fit went wrong for me can you make the starting point closer so it always work, but not so close its
unfair.
result = search.fit(model=model, analysis=analysis)
ModuleNotFoundError: No module named 'emcee'
(traceback through autofit/non_linear/search/mcmc/emcee/search.py line 135, Colab,
/usr/local/lib/python3.13/dist-packages/autofit)
## Audit (session findings, 2026-09-14)
**Tutorial 1** (`scripts/chapter_1_introduction/tutorial_1_models.py`)
- No data figure exists. The RTD original is
`PyAutoFit/docs/overview/python_api.md` lines 48-68: the `data.png` errorbar
figure, then the `g(x, I, \sigma)` equation, then the `Where:` list. The
tutorial has the equation + `Where:` list (lines 101-112) but no figure.
The dataset is `dataset/example_1d/gaussian_x1` (centre 50.0,
normalization 25.0, sigma 10.0); tutorials 2 and 3 already load it with an
auto-simulation `subprocess` guard that tutorial 1 can copy verbatim.
- Line 261 `af.Model` is bare prose; line 212 `a Model object` and line 204
`the Gaussian class` are the same class of miss. A sweep of every
module-level docstring in `scripts/` finds only two `af.`-prefixed misses
(t1:261 and `log_likelihood_function` at
`tutorial_4_why_modeling_is_hard.py:169`), plus a handful of bare class
names in chapter 1.
- Typos: the Gaussian equation writes `g(x, I, \sigma)` but the parameter is
named `N` below it (same for the Exponential's `g(x, I, \lambda)`);
line 118 calls the parameters `(x, N, \sigma)` when the class names them
`centre, normalization, sigma`; line 367 `ratw` -> `rate`; line 368 `has
fast` -> `how fast`; line 376 the `Exponential.model_data_from` docstring
says "Returns a 1D Gaussian"; line 461 prints `sigma (Exponential)` for
`instance.exponential.rate`; line 93 points a HowToFit clone at
`autofit_workspace`; line 110/111 carry a stray double blank line.
**Tutorial 2** (`tutorial_2_fitting_data.py`) — display math at lines 297,
323, 344, 365-367 and 387 uses `\[ ... \]`, which Jupyter/Colab's markdown
renderer does not typeset (only `$...$` / `$$...$$` are default delimiters).
Confirmed unrendered in `notebooks/.../tutorial_2_fitting_data.ipynb` cell 22.
**Tutorial 3** (`tutorial_3_non_linear_search.py`) — the Parameter Space
section (lines 52-88) uses both `\[ ... \]` display math and `\( ... \)`
inline math; neither renders. The MLE `InitializerParamStartPoints` at lines
508-514 starts at `centre=55.0, normalization=20.0, sigma=8.0` against a truth
of `50.0 / 25.0 / 10.0` — far enough that LBFGS does not reliably converge.
**Root cause of the `emcee` traceback** — not a HowToFit bug. `emcee>=3.1.6`
and `dynesty==2.1.5` are real `dependencies` of autofit
(`PyAutoFit/pyproject.toml` lines 42 and 44), but the Colab bootstrap
`PyAutoNerves/autonerves/setup_colab.py` installs the stack with `--no-deps`
(line ~270) and neither package is listed in `_SHARED_EXTRAS`. Every Colab
run of tutorial 3 therefore dies at the `af.Emcee` fit, and would die again at
`af.DynestyStatic`. Fix belongs in `_SHARED_EXTRAS`; it reaches users on the
next `autonerves` release.
## Scope
Math-delimiter conversion is scoped to tutorials 1-3 as requested. Tutorials 6,
7 and `tutorial_optional_bayesian_formalism.py` carry the same unrendered
`\[ \]` / `\( \)` blocks and need a follow-up sweep.
Activity
Jammy2211 commentedon Sep 14, 2026
Shipped
Merged in #58 (tutorials 1-3) with the Colab half in PyAutoLabs/PyAutoNerves#164.
Where:list, as the RTDpython_apipage has it); the reader's replacement wording for the model-figure paragraph, verbatim; Extensibility closes with a worked 18-parameter model (x2Gaussian+ x4Exponential) showingmodel.infoand the figure only; code references backticked; ~10 typos.\[ \]/\( \)onto$$ $$/$ $, which Jupyter and Colab actually typeset.InitializerParamStartPointswas keyed on oneaf.Model(Gaussian)while a freshly built one was passed tosearch.fit, so no key matched and PyAutoFit fell back to random draws. Fixed in both the LBFGS and Emcee blocks; start points 52/23/9 recover 49.889 / 25.147 / 9.847.ModuleNotFoundError: No module named 'emcee'was not a HowToFit bug — the Colab bootstrap installs with--no-depsand never namedemcee/dynesty, both realautofitdependencies. Fixed in PyAutoNerves#164; it reaches Colab on the nextautonervesrelease.Smoke 18/18, CI green on all 7 checks.