This is the HowToLens tutorial lecture series for PyAutoLens, a Python library for strong
gravitational lens modeling. Tutorials teach new users what strong lensing is and how to model it
from first principles. It is the teaching companion to ../autolens_workspace. These are the
canonical, agent-agnostic instructions for this repo.
scripts/— Runnable Python tutorial scripts:chapter_1_introduction/— Grids, profiles, galaxies, ray-tracing, point sources, data, fittingchapter_2_lens_modeling/— Non-linear searches, practicalities, difficult fits, linear profiles, data and likelihoods, component-based search chaining and an introduction to SLaMchapter_3_pixelizations/— Pixelized source reconstruction, mappings, inversions, evidence-guided regularization, borders, lens modeling, fit problems and adaptive reconstructionchapter_4_scaling_up_lensing/— Extra galaxies, multi-galaxy lenses, scaling relations, group and cluster scales, weak lensingchapter_optional/— Alternative searches, runtime and historical prior passingsimulator/— Simulator scripts that generate the tutorial datasets at runtime
notebooks/— Jupyter versions, generated fromscripts/(do not edit directly)config/— PyAutoLens configuration YAMLdataset/— Empty in the repo; written at runtime by the simulator scriptsoutput/— Model-fit results, generated at runtime and gitignored, except the stored Chapter 2 results underoutput/howtolens/chapter_2/(see Stored Chapter 2 Results)
Scripts are run from the repo root so relative paths to dataset/ and output/ resolve. A
tutorial that needs a dataset invokes the matching scripts/simulator/ script via subprocess if
the dataset folder is absent — no manual simulate-then-run step.
python scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.pyFast mode for integration: PYAUTO_TEST_MODE=1 skips sampling (=2 also bypasses; combine with
PYAUTO_SKIP_FIT_OUTPUT=1 PYAUTO_SKIP_VISUALIZATION=1 PYAUTO_SKIP_CHECKS=1 PYAUTO_FAST_PLOTS=1 for a
fast smoke run). Dataset realism: PYAUTO_SMALL_DATASETS is deliberately not used in
HowToLens — tutorials assume the full-resolution simulated datasets (unlike the workspaces, which
cap grids/masks).
On CI, every PR is gated on Python 3.12 and 3.13 by smoke_tests.yml (runs
python .github/scripts/run_smoke.py, which runs every script under scripts/ except the
exclusions in config/build/no_run.yaml, with per-script env from config/build/profile_smoke.yaml —
the definition of green), navigator_check.yml (PyAutoHands's reusable navigator-catalogue check;
see Notebooks vs Scripts), url_check.yml (link checking) and stored_results.yml (Chapter 2
stored results still load against the released libraries; also runs daily, see Stored Chapter 2
Results). The smoke and navigator jobs check
out PyAutoHands as a sibling and run the PyAuto* libraries from the same-named branch of each
source repo, so a HowToLens PR is validated against matching library branches.
If numba or matplotlib cannot write to the default cache locations, point them at writable dirs:
NUMBA_CACHE_DIR=/tmp/numba_cache MPLCONFIGDIR=/tmp/matplotlib python scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.pyNotebooks in notebooks/ are generated from the .py scripts via PyAutoHands. Always edit the
.py scripts, never the .ipynb directly. The # %% marker alternates code and markdown cells.
Regenerate from the repo root:
PYTHONPATH=../PyAutoHands/autohands python3 ../PyAutoHands/autohands/generate.py howtolensThe howtolens project target is registered in PyAutoHands (run_all.py, navigator.py,
config/). The navigator catalogue — llms-full.txt + workspace_index.json — is what
navigator_check.yml gates; it is rebuilt by the same PyAutoHands generate/merge flow that builds
the notebooks. Commit regenerated notebooks and catalogue alongside the script changes.
Chapter 2 Tutorials 2-6 ship the completed output of every search, so readers load each result in
seconds ("Fit Already Completed") instead of sampling. Tutorial 1 is not stored: its search writes
no output and is the reader's one live fit. Only the files needed to rebuild a result are kept,
with samples.csv thinned to a few equal-weight draws; Tutorial 2 keeps a fuller, illustrated
folder because it walks the reader through the output tree.
A stored result is found by an identifier hashed from the model and search settings (n_live,
seed, priors, profile classes), not the search name. Changing any of those, or a library change
that moves a profile class or default, makes that tutorial sample again. After such a change, rerun
the affected searches for real (test mode off, ideally on a cluster) and refresh the store:
python .github/scripts/stored_results.py harvest <output-root-of-the-real-runs>
git add -f output/howtolens/chapter_2/lens_sersic/*/*/
python .github/scripts/stored_results.py check # fails if any Tutorial 2-6 search would sampleAdd the fit folders only: loading a stored fit writes a .zip and status files beside each folder,
which stay gitignored. Smoke tests run in test mode and never exercise the stored results; the
stored_results.yml workflow runs check against the released libraries on every PR, on main and
daily, so a library release that invalidates the store turns it red.
When editing the same region across many scripts in one pass, only rewrite the targeted region. Never produce a whole-file write unless you have read the entire current file — a whole-file write from a header skim silently deletes every section below the header.
When a tutorial benefits from broader framing — landmark surveys, named lenses, degeneracies, or the
literature behind a mass-model or source-reconstruction choice — pull from the autolens_assistant
literature wiki at https://github.com/PyAutoLabs/autolens_assistant (wiki/literature/ — concepts,
entities, sources). If cloned as a sibling, read it locally at ../autolens_assistant/wiki/literature/.
../PyAutoLens,../PyAutoGalaxy— source libraries.../autolens_workspace— the user-facing workspace (tutorials point here as the next destination).../PyAutoHands— notebook generation + CI tooling.../autolens_assistant— science-assistant workspace (literature wiki; see Scientific Context).
[API Update] issues: find every renamed/moved/removed/changed public API, update each tutorial
script (preserving the teaching prose), run python .github/scripts/run_smoke.py, and fix [FAIL]
entries until the summary passes; regenerate notebooks + catalogue after. General issues: edit
only files in scripts/ (never notebooks/), preserve docstrings and explanations, test, then
regenerate. Flag any change that affects autolens_workspace or the source libraries in your PR.
Never rewrite pushed history on any repo with a remote — no git init over a
tracked repo, no force-push to main, no fresh-start "Initial commit", no
filter-repo / filter-branch / rebase -i on pushed branches. To get a
clean tree: git fetch origin && git reset --hard origin/main && git clean -fd.
A session ends when it reports its deliverable — never arm anything that
outlives the turn to wait for CI, a review or a merge: no send_later, no
subscribe_pr_activity, CronCreate, ScheduleWakeup, /loop, RemoteTrigger
create/update/run, or Monitor or background loop on GitHub. Judge once, report,
stop; the human re-runs /prm (or the batch review) when it is green. The one
exception, the shift cockpit's stream: PyAutoMind policy/shift_cockpit_watch.md.
Measured: five batch members armed hourly check-ins on 2026-08-31, and a mobile
/prm re-armed a 60-minute send_later all night on 2026-09-03, draining usage.
Questions, help with code or an analysis, ideas, bug reports and results from a
user or collaborator — or an agent acting for one — go to
https://github.com/orgs/PyAutoLabs/discussions in the matching category
(Help & Questions, Ideas & Proposals, Bugs & Errors, Show and tell;
Announcements is maintainers-only), never to this repo's Issues. An agent never
runs gh issue create for such a report: it drafts the title, category and
body and hands them to the human (sessions cannot create Discussions). Only the
development flow — Mind prompt → /start_dev → /create_issue → one issue per
task → PR — opens issues here. Why: PyAutoMind/policy/community_surface.md.
Before changing a shared interface, consult the applicable organism standard on demand, identify affected consumers, and validate their adoption. Change generated guidance at its canonical source and regenerate.