|
1 | | -# HowToLens |
2 | | - |
3 | | -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. |
4 | | - |
5 | | -## Scientific Context |
6 | | - |
7 | | -When a tutorial benefits from broader scientific framing — references to |
8 | | -landmark surveys, named lenses, degeneracies, or the literature behind a |
9 | | -mass model or source-reconstruction choice — pull from the lensing |
10 | | -sub-wiki at |
11 | | -[`PyAutoLabs/PyAutoPaper`](https://github.com/PyAutoLabs/PyAutoPaper), |
12 | | -locally at `../PyAutoPaper/lensing_wiki/`. It has topical concept pages |
13 | | -(`concepts/`), named-entity pages (`entities/`, including SLACS, H0liCOW, |
14 | | -Euclid Q1, Abell 1201, the Cosmic Horseshoe), and a per-topic |
15 | | -bibliography (`sources/`, ~190 papers — most stubs are `status: stub` |
16 | | -until verified against the PDF). Start at |
17 | | -`../PyAutoPaper/lensing_wiki/index.md`. Use it especially for the |
18 | | -science-narrative tutorials that Opus authors. |
19 | | - |
20 | | -## Repository Structure |
21 | | - |
22 | | -- `scripts/` — Runnable Python tutorial scripts |
23 | | - - `chapter_1_introduction/` — Grids, profiles, galaxies, ray-tracing, data, fitting |
24 | | - - `chapter_2_lens_modeling/` — Non-linear searches, Bayesian inference, lens modeling |
25 | | - - `chapter_3_search_chaining/` — Search chaining, prior passing, automated pipelines |
26 | | - - `chapter_4_pixelizations/` — Pixelized source reconstruction, inversions, regularization |
27 | | - - `chapter_optional/` — Alternative non-linear searches and advanced topics |
28 | | - - `simulator/` — Simulator scripts that generate the tutorial datasets at runtime |
29 | | -- `notebooks/` — Jupyter notebook versions of scripts (generated from `scripts/`, do not edit directly) |
30 | | -- `config/` — `PyAutoLens` configuration YAML files |
31 | | -- `dataset/` — Empty in the repo; tutorial datasets are written here at runtime by the simulator scripts |
32 | | -- `output/` — Model-fit results (generated at runtime, not committed) |
33 | | - |
34 | | -## Running Scripts |
35 | | - |
36 | | -Scripts are run from the repository root so relative paths to `dataset/` and `output/` resolve correctly: |
37 | | - |
38 | | -```bash |
39 | | -python scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.py |
40 | | -``` |
41 | | - |
42 | | -Tutorials in chapters 1 and 2 that need a dataset invoke the relevant script in `scripts/simulator/` via `subprocess` if the dataset folder does not already exist — there is no manual simulate-then-run step. |
43 | | - |
44 | | -**Integration testing / fast mode**: set `PYAUTO_TEST_MODE=1` to skip non-linear search sampling: |
45 | | - |
46 | | -```bash |
47 | | -PYAUTO_TEST_MODE=1 python scripts/chapter_2_lens_modeling/tutorial_1_non_linear_search.py |
48 | | -``` |
49 | | - |
50 | | -**Fast smoke tests**: combine test mode with the skip flags: |
51 | | - |
52 | | -```bash |
53 | | -PYAUTO_TEST_MODE=2 PYAUTO_SKIP_FIT_OUTPUT=1 PYAUTO_SKIP_VISUALIZATION=1 PYAUTO_SKIP_CHECKS=1 PYAUTO_FAST_PLOTS=1 python scripts/chapter_1_introduction/tutorial_7_fitting.py |
54 | | -``` |
55 | | - |
56 | | -Note: `PYAUTO_SMALL_DATASETS` is deliberately **not** used in HowToLens. Tutorials assume the full-resolution simulated datasets that the simulator scripts produce. |
57 | | - |
58 | | -**Codex / sandboxed runs**: set writable cache directories so `numba` and `matplotlib` do not fail on unwritable home paths: |
59 | | - |
60 | | -```bash |
61 | | -NUMBA_CACHE_DIR=/tmp/numba_cache MPLCONFIGDIR=/tmp/matplotlib python scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.py |
62 | | -``` |
63 | | - |
64 | | -## Core API Patterns |
65 | | - |
66 | | -Imports used throughout the tutorials: |
67 | | - |
68 | | -```python |
69 | | -import autofit as af |
70 | | -import autolens as al |
71 | | -import autolens.plot as aplt |
72 | | -``` |
73 | | - |
74 | | -## Notebooks vs Scripts |
75 | | - |
76 | | -Notebooks in `notebooks/` are generated from the `.py` files in `scripts/` using `generate.py` from the `PyAutoBuild` repo. **Always edit the `.py` scripts**, never the notebooks directly. The `# %%` marker alternates between code and markdown cells. |
77 | | - |
78 | | -### Building Notebooks |
79 | | - |
80 | | -Run from the workspace root: |
81 | | - |
82 | | -```bash |
83 | | -PYTHONPATH=../PyAutoBuild/autobuild python3 ../PyAutoBuild/autobuild/generate.py howtolens |
84 | | -``` |
85 | | - |
86 | | -The `howtolens` project target in `PyAutoBuild/autobuild/config.yaml` is what drives this. |
87 | | - |
88 | | -## Relationship to autolens_workspace |
89 | | - |
90 | | -HowToLens is the teaching companion to `autolens_workspace`. Many tutorials (particularly in chapters 2–4) point users to `autolens_workspace` scripts (e.g. `scripts/imaging/modeling.py`, `scripts/guides/...`) as the next destination after the relevant concept has been introduced. Those cross-references use absolute paths like `autolens_workspace/scripts/...` and refer to the separate `autolens_workspace` repository — not to anything inside HowToLens. |
91 | | - |
92 | | -## Related Repos |
93 | | - |
94 | | -- **PyAutoLens** source: `../PyAutoLens` |
95 | | -- **PyAutoGalaxy** source: `../PyAutoGalaxy` |
96 | | -- **autolens_workspace**: `../autolens_workspace` — main user-facing workspace |
97 | | -- **PyAutoBuild**: `../PyAutoBuild` — notebook generation and CI/CD tooling |
98 | | -## Never rewrite history |
99 | | - |
100 | | -NEVER perform these operations on any repo with a remote: |
101 | | - |
102 | | -- `git init` in a directory already tracked by git |
103 | | -- `rm -rf .git && git init` |
104 | | -- Commit with subject "Initial commit", "Fresh start", "Start fresh", "Reset |
105 | | - for AI workflow", or any equivalent message on a branch with a remote |
106 | | -- `git push --force` to `main` (or any branch tracked as `origin/HEAD`) |
107 | | -- `git filter-repo` / `git filter-branch` on shared branches |
108 | | -- `git rebase -i` rewriting commits already pushed to a shared branch |
109 | | - |
110 | | -If the working tree needs a clean state, the **only** correct sequence is: |
111 | | - |
112 | | - git fetch origin |
113 | | - git reset --hard origin/main |
114 | | - git clean -fd |
115 | | - |
116 | | -This applies equally to humans, local Claude Code, cloud Claude agents, Codex, |
117 | | -and any other agent. The "Initial commit — fresh start for AI workflow" pattern |
118 | | -that appeared independently on origin and local for three workspace repos is |
119 | | -exactly what this rule prevents — it costs ~40 commits of redundant local work |
120 | | -every time it happens. |
| 1 | +# HowToLens — agent instructions |
| 2 | +The canonical, agent-agnostic instructions live in `AGENTS.md`. Claude Code loads them |
| 3 | +via the import below; if your tool does not process `@`-imports, open `AGENTS.md` in |
| 4 | +this directory and read it directly. |
| 5 | +@AGENTS.md |
0 commit comments