|
| 1 | +# HowToGalaxy — Agent Instructions |
| 2 | + |
| 3 | +This is the **HowToGalaxy** tutorial lecture series for **PyAutoGalaxy**, a Python library for galaxy |
| 4 | +morphology modeling. Tutorials teach new users how to model galaxy light from first principles. It is |
| 5 | +the teaching companion to `../autogalaxy_workspace`. These are the canonical, agent-agnostic |
| 6 | +instructions for this repo. |
| 7 | + |
| 8 | +## Repository Structure |
| 9 | + |
| 10 | +- `scripts/` — Runnable Python tutorial scripts: |
| 11 | + - `chapter_1_introduction/` — Grids, light profiles, galaxies, data, fitting |
| 12 | + - `chapter_2_modeling/` — Non-linear searches, Bayesian inference, galaxy modeling |
| 13 | + - `chapter_3_search_chaining/` — Search chaining, prior passing, automated pipelines |
| 14 | + - `chapter_4_pixelizations/` — Pixelized reconstruction, inversions, regularization |
| 15 | + - `chapter_optional/` — Alternative searches and advanced topics |
| 16 | + - `simulators/` — Simulator scripts that generate the tutorial datasets at runtime |
| 17 | +- `notebooks/` — Jupyter versions, generated from `scripts/` (do not edit directly) |
| 18 | +- `config/` — PyAutoGalaxy configuration YAML |
| 19 | +- `dataset/` — Empty in the repo; written at runtime by the simulator scripts |
| 20 | +- `output/` — Model-fit results (generated at runtime, not committed) |
| 21 | + |
| 22 | +## Running Scripts |
| 23 | + |
| 24 | +Scripts are run **from the repo root** so relative paths to `dataset/` and `output/` resolve. A |
| 25 | +tutorial that needs a dataset invokes the matching `scripts/simulators/` script via `subprocess` if |
| 26 | +the dataset folder is absent — no manual simulate-then-run step. |
| 27 | + |
| 28 | +```bash |
| 29 | +python scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.py |
| 30 | +``` |
| 31 | + |
| 32 | +Fast mode for integration: `PYAUTO_TEST_MODE=1` skips sampling (`=2` also bypasses; combine with |
| 33 | +`PYAUTO_SKIP_FIT_OUTPUT=1 PYAUTO_SKIP_VISUALIZATION=1 PYAUTO_SKIP_CHECKS=1 PYAUTO_FAST_PLOTS=1` for a |
| 34 | +fast smoke run). **Dataset realism:** `PYAUTO_SMALL_DATASETS` is deliberately **not** used in |
| 35 | +HowToGalaxy — tutorials assume the full-resolution simulated datasets (unlike the workspaces, which |
| 36 | +cap grids/masks). |
| 37 | + |
| 38 | +## Testing |
| 39 | + |
| 40 | +On CI, every PR is gated on Python **3.12 and 3.13** by `smoke_tests.yml` (runs |
| 41 | +`python .github/scripts/run_smoke.py`, driven by `smoke_tests.txt` + `config/build/env_vars.yaml` — |
| 42 | +the definition of green), `navigator_check.yml` (PyAutoBuild's reusable navigator-catalogue check; |
| 43 | +see *Notebooks vs Scripts*), and `url_check.yml` (link checking). The smoke and navigator jobs check |
| 44 | +out **PyAutoBuild** as a sibling and run the PyAuto* libraries from the **same-named branch** of each |
| 45 | +source repo, so a HowToGalaxy PR is validated against matching library branches. |
| 46 | + |
| 47 | +## Sandboxed / restricted runs |
| 48 | + |
| 49 | +If `numba` or `matplotlib` cannot write to the default cache locations, point them at writable dirs: |
| 50 | + |
| 51 | +```bash |
| 52 | +NUMBA_CACHE_DIR=/tmp/numba_cache MPLCONFIGDIR=/tmp/matplotlib python scripts/chapter_1_introduction/tutorial_1_grids_and_galaxies.py |
| 53 | +``` |
| 54 | + |
| 55 | +## Notebooks vs Scripts |
| 56 | + |
| 57 | +Notebooks in `notebooks/` are **generated** from the `.py` scripts via PyAutoBuild. **Always edit the |
| 58 | +`.py` scripts, never the `.ipynb` directly.** The `# %%` marker alternates code and markdown cells. |
| 59 | +Regenerate from the repo root: |
| 60 | + |
| 61 | +```bash |
| 62 | +PYTHONPATH=../PyAutoBuild/autobuild python3 ../PyAutoBuild/autobuild/generate.py howtogalaxy |
| 63 | +``` |
| 64 | + |
| 65 | +The `howtogalaxy` project target is registered in PyAutoBuild (`run_all.py`, `navigator.py`, |
| 66 | +`config/`). The navigator catalogue — `llms-full.txt` + `workspace_index.json` — is what |
| 67 | +`navigator_check.yml` gates; it is rebuilt by the same PyAutoBuild generate/merge flow that builds |
| 68 | +the notebooks. Commit regenerated notebooks and catalogue alongside the script changes. |
| 69 | + |
| 70 | +## Bulk-edit safety |
| 71 | + |
| 72 | +When editing the same region across many scripts in one pass, only rewrite the targeted region. |
| 73 | +**Never produce a whole-file write unless you have read the entire current file** — a whole-file |
| 74 | +write from a header skim silently deletes every section below the header. |
| 75 | + |
| 76 | +## Scientific Context |
| 77 | + |
| 78 | +When a tutorial benefits from framing a galaxy concept against a real scientific application — |
| 79 | +light profiles + MGE, regularisation, pixelisation, bulge/halo decomposition, kinematics — pull from |
| 80 | +the `autolens_assistant` literature wiki at https://github.com/PyAutoLabs/autolens_assistant |
| 81 | +(`wiki/literature/` — concepts, entities, sources). If cloned as a sibling, read it locally at |
| 82 | +`../autolens_assistant/wiki/literature/`. It is currently lensing-focused, but several galaxy-modelling |
| 83 | +concepts (source reconstruction, bulge/halo decomposition) are directly useful. |
| 84 | + |
| 85 | +## Related Repos |
| 86 | + |
| 87 | +- `../PyAutoGalaxy` — source library. |
| 88 | +- `../autogalaxy_workspace` — the user-facing workspace (tutorials point here as the next destination). |
| 89 | +- `../PyAutoBuild` — notebook generation + CI tooling. |
| 90 | +- `../autolens_assistant` — science-assistant workspace (literature wiki; see *Scientific Context*). |
| 91 | + |
| 92 | +## Task Workflows |
| 93 | + |
| 94 | +**`[API Update]` issues:** find every renamed/moved/removed/changed public API, update each tutorial |
| 95 | +script (preserving the teaching prose), run `python .github/scripts/run_smoke.py`, and fix `[FAIL]` |
| 96 | +entries until the summary passes; regenerate notebooks + catalogue after. **General issues:** edit |
| 97 | +only files in `scripts/` (never `notebooks/`), preserve docstrings and explanations, test, then |
| 98 | +regenerate. Flag any change that affects `autogalaxy_workspace` or the source libraries in your PR. |
| 99 | + |
| 100 | +## Clean state |
| 101 | + |
| 102 | +Never rewrite history on a repo with a remote (no `git init` over a tracked tree, no force-push to |
| 103 | +`main`, no rebasing pushed shared branches). To reset a dirty tree the only correct sequence is: |
| 104 | + |
| 105 | +```bash |
| 106 | +git fetch origin |
| 107 | +git reset --hard origin/main |
| 108 | +git clean -fd |
| 109 | +``` |
0 commit comments