|
1 | | -# magnetics (analysis) |
| 1 | +# magnetics |
2 | 2 |
|
3 | | -Device-agnostic Python library for 3D magnetic-sensor analysis of tokamak MHD |
4 | | -instabilities. See `../docs/VISION.md` for context. |
| 3 | +Device-agnostic Python library **and** GUI for 3D magnetic-sensor analysis of |
| 4 | +tokamak MHD instabilities — quasi-stationary (locked) modes and rapidly-rotating |
| 5 | +modes. See [`docs/VISION.md`](docs/VISION.md) for context. |
5 | 6 |
|
6 | | -## Setup |
| 7 | +## Quick start (no dev setup) |
| 8 | + |
| 9 | +The GUI ships inside the package — no Node or build toolchain needed. |
| 10 | + |
| 11 | +```sh |
| 12 | +uvx magnetics # zero-install: uv provisions Python + runs it |
| 13 | +# or |
| 14 | +pip install magnetics # into an existing environment |
| 15 | +magnetics # start the app, open it in your browser |
| 16 | +``` |
| 17 | + |
| 18 | +`magnetics` starts the service and opens the GUI in your browser. Useful flags: |
| 19 | + |
| 20 | +```sh |
| 21 | +magnetics --port 8000 # fixed port (default: first free port from 8000) |
| 22 | +magnetics --no-browser # headless (e.g. on a server) |
| 23 | +magnetics --data-dir PATH # where shot data lives (see below) |
| 24 | +``` |
| 25 | + |
| 26 | +Two more console scripts come with the install: |
| 27 | + |
| 28 | +```sh |
| 29 | +magnetics-fetch --shot 184927 # pull a shot to the local data dir |
| 30 | +magnetics-service # start just the API/service (honors HOST/PORT) |
| 31 | +``` |
| 32 | + |
| 33 | +### Where shot data lives |
| 34 | + |
| 35 | +Fetched shots are cached persistently so you don't re-pull them. The location is, |
| 36 | +in order: |
| 37 | + |
| 38 | +1. `$MAGNETICS_DATA_DIR` (or `--data-dir`) if set — **the** knob to relocate it; |
| 39 | +2. the repo's `data/` dir when run from a source checkout; |
| 40 | +3. otherwise a per-user data dir (`~/.local/share/magnetics` on Linux, |
| 41 | + `~/Library/Application Support/magnetics` on macOS). |
| 42 | + |
| 43 | +**On a cluster,** set `MAGNETICS_DATA_DIR` to scratch/project space (home dirs are |
| 44 | +usually quota'd and shot files are large) — e.g. in your shell profile: |
| 45 | + |
| 46 | +```sh |
| 47 | +export MAGNETICS_DATA_DIR=$SCRATCH/magnetics |
| 48 | +``` |
| 49 | + |
| 50 | +## Development |
| 51 | + |
| 52 | +The Python project is the repo root (a uv project); the React GUI is in `gui/web/`. |
7 | 53 |
|
8 | 54 | ```sh |
9 | 55 | uv sync --group dev |
10 | 56 | uv run nbstripout --install # strip notebook outputs on commit (run once per clone) |
| 57 | +./run-dev.sh # live: FastAPI service + GUI dev server (hot reload) |
| 58 | +./run-dev.sh static # GUI only, static mock fixtures (offline frontend work) |
| 59 | +./run-dev.sh --prod # build the GUI and serve it on one port (preview the wheel) |
| 60 | + |
| 61 | +scripts/build-dist.sh # build the distributable wheel + sdist (GUI bundled) into dist/ |
| 62 | +scripts/build-dist.sh --smoke # …and smoke-test the wheel in a clean venv |
11 | 63 | ``` |
12 | 64 |
|
13 | | -## Layout |
| 65 | +### Running a built wheel in isolation |
| 66 | + |
| 67 | +To try a freshly built wheel the way an end user would — in a throwaway |
| 68 | +environment that touches neither your `.venv` nor the repo's `data/` — run it with |
| 69 | +`uvx --from` (the installed package lives in uv's cache, so it uses the per-user |
| 70 | +data dir, not this checkout): |
| 71 | + |
| 72 | +```sh |
| 73 | +uvx --from ./dist/magnetics-*.whl magnetics |
| 74 | +uvx --from ./dist/magnetics-*.whl magnetics --data-dir "$(mktemp -d)" # touch nothing persistent |
| 75 | +uvx --reinstall --from ./dist/magnetics-*.whl magnetics # after a rebuild at the same version |
| 76 | +``` |
| 77 | + |
| 78 | +### Layout |
14 | 79 |
|
15 | 80 | - `src/magnetics/core/` — pure, device-agnostic analysis (e.g. `spectral.py`). |
16 | | -- `tests/` — pytest suite; fixtures in `tests/fixtures/`. |
| 81 | +- `src/magnetics/service/` — FastAPI app; the built GUI is bundled at `service/webapp/`. |
| 82 | +- `gui/web/` — React + Vite + TypeScript frontend. |
| 83 | +- `tests/` — pytest suite (synthetic fixtures; no real tokamak data committed). |
17 | 84 | - `examples/` — runnable Jupyter notebooks. |
18 | 85 |
|
19 | | -## Common commands |
| 86 | +### Common commands |
20 | 87 |
|
21 | 88 | ```sh |
22 | | -uv run pytest # run tests |
| 89 | +uv run pytest # run the Python tests |
23 | 90 | uv run jupyter lab examples/ # open the example notebooks |
| 91 | +cd gui/web && npm test # run the frontend tests |
24 | 92 | ``` |
| 93 | + |
| 94 | +Releasing to PyPI is documented in [`docs/RELEASING.md`](docs/RELEASING.md). |
0 commit comments