https://github.com/astro-tools/gmat-sweep
Run parameter sweeps and Monte Carlo dispersions over GMAT missions in parallel from Python.
https://github.com/astro-tools/gmat-sweep
aerospace astrodynamics dask gmat gmatpy joblib mission-analysis monte-carlo nasa-gmat pandas parallel parameter-sweep python ray reproducibility
Last synced: about 1 month ago
JSON representation
Run parameter sweeps and Monte Carlo dispersions over GMAT missions in parallel from Python.
- Host: GitHub
- URL: https://github.com/astro-tools/gmat-sweep
- Owner: astro-tools
- License: mit
- Created: 2026-05-03T21:04:52.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-05-03T22:06:29.000Z (about 1 month ago)
- Last Synced: 2026-05-04T00:14:54.111Z (about 1 month ago)
- Topics: aerospace, astrodynamics, dask, gmat, gmatpy, joblib, mission-analysis, monte-carlo, nasa-gmat, pandas, parallel, parameter-sweep, python, ray, reproducibility
- Language: Python
- Homepage:
- Size: 294 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# gmat-sweep
[](https://github.com/astro-tools/gmat-sweep/actions/workflows/ci.yml)
[](https://astro-tools.github.io/gmat-sweep/)
[](https://pypi.org/project/gmat-sweep/)
[](https://pypi.org/project/gmat-sweep/)
[](LICENSE)
Run parameter sweeps and Monte Carlo dispersions over GMAT missions in parallel from Python.
## What this is
A parallel orchestrator on top of [`gmat-run`](https://github.com/astro-tools/gmat-run)'s
single-run primitive. Point `gmat-sweep` at a working `.script` and either a parameter
grid, an explicit run table, or a perturbation distribution, and it fans the run set
across subprocess workers, aggregates each run's `ReportFile` (and any `EphemerisFile`
or `ContactLocator` outputs) into multi-indexed pandas DataFrames, and writes a JSON
Lines manifest alongside the results so any sweep is reproducible bit-for-bit. Killed
sweeps reload from the manifest and re-run only the missing or failed runs.
The four entry points cover the common shapes:
- [`sweep(grid=...)`](https://astro-tools.github.io/gmat-sweep/parameter-spec/#full-factorial-expansion)
— full-factorial grid over one or more dotted-path fields.
- [`sweep(samples=DataFrame)`](https://astro-tools.github.io/gmat-sweep/parameter-spec/#explicit-row-sweeps)
— explicit-row sweep where you pre-build the run set (Halton, Sobol, custom design).
- [`monte_carlo(perturb=...)`](https://astro-tools.github.io/gmat-sweep/monte-carlo/)
— stochastic dispersion with named distributions and a deterministic seed contract.
- [`latin_hypercube(perturb=...)`](https://astro-tools.github.io/gmat-sweep/parameter-spec/#monte-carlo-vs-latin-hypercube)
— stratified sampling for variance reduction at small `n`.
## What this is not
- **Not** a single-run runner — that's [`gmat-run`](https://github.com/astro-tools/gmat-run);
every `gmat-sweep` worker calls into it.
- **Not** a way to build GMAT missions from scratch in Python — see
[`gmatpyplus`](https://github.com/weasdown/gmatpyplus).
- **Not** a `.script` text generator — see [`pygmat`](https://pypi.org/project/pygmat/).
- **Not** an optimiser. Gradient-, Bayesian-, and population-based optimisation
(CasADi, pagmo2, scikit-optimize) is a different problem; `gmat-sweep` may serve as the
parallel evaluator inside one, but it ships no optimiser of its own.
- **Not** a distributed cluster runner yet. The default `LocalJoblibPool` saturates one
machine; `DaskPool` and `RayPool` for multi-machine sweeps are scoped for v0.3.
## Requirements
- Python 3.10, 3.11, or 3.12.
- [`gmat-run`](https://github.com/astro-tools/gmat-run) ≥ 0.3 — installed as a transitive
dependency from PyPI. `gmat-sweep` never imports `gmatpy` directly; the import happens
inside each worker subprocess on first call.
- A local GMAT install. `gmat-sweep` does not ship GMAT binaries; it relies on `gmat-run`'s
install discovery, which honours `$GMAT_ROOT` or finds a build under a conventional path.
Download GMAT from the
[SourceForge release page](https://sourceforge.net/projects/gmat/files/GMAT/) — see
[`gmat-run`'s install guide](https://astro-tools.github.io/gmat-run/install-gmat/) for the
unpack-and-discover steps.
### Supported GMAT versions
| GMAT release | Status | CI |
|---|---|---|
| R2026a | Primary development target | Exercised on every PR (Ubuntu + Windows + macOS, Python 3.10/3.11/3.12) |
| R2025a | Supported | Exercised on every PR (Ubuntu + Windows + macOS, Python 3.10/3.11/3.12) |
R2023a and R2024a were never released by the upstream GMAT project; R2025a and R2026a are
the only releases supported.
## Installation
```bash
pip install gmat-sweep
```
The `[examples]` extra pulls in matplotlib for the example notebooks:
```bash
pip install gmat-sweep[examples]
```
## Quick start
```python
from gmat_sweep import sweep
df = sweep(
"mission.script",
grid={"Sat.SMA": [7000, 7100, 7200]},
workers=8,
)
print(df)
```
That call runs `mission.script` three times — once per `Sat.SMA` value — each in a fresh
subprocess, and returns a `(run_id, time)`-MultiIndexed `pandas.DataFrame` containing
the rows from every run's `ReportFile` plus a `__status` column flagging
`ok` / `failed` / `skipped`. A single failed run lands as a `failed` row with the captured
GMAT stderr in the manifest — never as a silent zero-row DataFrame and never as an
unhandled exception that aborts the whole sweep.
For a stochastic dispersion, swap [`sweep`](https://astro-tools.github.io/gmat-sweep/api/#gmat_sweep.sweep)
for [`monte_carlo`](https://astro-tools.github.io/gmat-sweep/monte-carlo/) and pass a
`perturb` mapping of named distributions:
```python
from gmat_sweep import monte_carlo
df = monte_carlo(
"mission.script",
n=1000,
perturb={"Sat.SMA": ("normal", 7100.0, 50.0)},
workers=8,
seed=42,
)
```
Returns the same DataFrame shape as `sweep()`. Per-run sub-seeds derive from `seed` via
`numpy.random.SeedSequence.spawn`, so the draw is bit-reproducible and a resumed sweep
samples the same values for any given `run_id`. See the
[Monte Carlo guide](https://astro-tools.github.io/gmat-sweep/monte-carlo/) for the full
determinism contract and [`latin_hypercube`](https://astro-tools.github.io/gmat-sweep/parameter-spec/#monte-carlo-vs-latin-hypercube)
for the stratified-sampling variant.
By default the per-run Parquet files and the manifest land in a temporary directory
whose lifetime is tied to the returned DataFrame. Pass `out=Path(...)` to keep them —
that's also what enables [resuming a killed sweep](https://astro-tools.github.io/gmat-sweep/resume/)
via `Sweep.from_manifest(...).resume()` or `gmat-sweep resume `.
A `gmat-sweep` console script is also installed for shell-script and CI use:
```bash
gmat-sweep run --grid Sat.SMA=7000:7200:3 --workers 8 --out ./sweep mission.script
gmat-sweep monte-carlo --n 1000 --perturb 'Sat.SMA=normal:7100:50' --seed 42 --out ./mc mission.script
gmat-sweep resume --script mission.script --workers 8 ./mc/manifest.jsonl
gmat-sweep show ./sweep/manifest.jsonl
```
See the [CLI reference in the docs](https://astro-tools.github.io/gmat-sweep/cli/)
for every subcommand and the full mini-grammar.
## Outputs
Every sweep emits two artefacts:
- The returned **DataFrame** — `(run_id, time)`-MultiIndexed, one column per `ReportFile`
channel plus the `__status` column. Built lazily from per-run Parquet files via
pyarrow's dataset API, so a 10,000-run sweep does not have to fit in memory at once.
- A **JSON Lines manifest** (`manifest.jsonl`) — append-only, fsync'd after every entry.
Records the canonical script SHA-256, software-version fingerprint, full parameter
spec, and per-run status, timing, output paths, and captured stderr. A `Ctrl-C`
mid-sweep leaves the manifest in a parseable state. See the
[manifest schema](https://astro-tools.github.io/gmat-sweep/manifest-schema/) for the
full contract.
## Documentation
Full docs at ****, including a
[getting-started guide](https://astro-tools.github.io/gmat-sweep/getting-started/),
the [parameter spec reference](https://astro-tools.github.io/gmat-sweep/parameter-spec/),
the [manifest schema](https://astro-tools.github.io/gmat-sweep/manifest-schema/),
the [supported-version matrix](https://astro-tools.github.io/gmat-sweep/supported-versions/),
the [FAQ](https://astro-tools.github.io/gmat-sweep/faq/),
and the [API reference](https://astro-tools.github.io/gmat-sweep/api/).
Runnable example notebooks:
- [Single-axis SMA scan](https://astro-tools.github.io/gmat-sweep/examples/01_sma_scan/) —
fifty runs across `np.linspace(7000, 8000, 50)` of `Sat.SMA`, parallel-dispatched and
overlaid on a single altitude-vs-time plot.
- [Two-axis epoch × time-of-flight grid](https://astro-tools.github.io/gmat-sweep/examples/02_epoch_arrival_grid/) —
cartesian product over `Sat.Epoch` and a script-level `Variable TOF`, contoured by
per-run miss distance.
- [Surviving a kill](https://astro-tools.github.io/gmat-sweep/examples/03_killed_sweep_recovery/) —
launch a sweep, send `SIGINT` mid-run, walk through inspecting the partial manifest
with `gmat-sweep show`, then complete the sweep with `Sweep.from_manifest(...).resume()`.
- [Monte Carlo dispersion](https://astro-tools.github.io/gmat-sweep/examples/04_monte_carlo_dispersion/) —
1000-run Monte Carlo around a nominal injection burn over a four-axis perturbation
cube, with arrival-miss histogram and a 3-σ covariance ellipse.
- [Latin hypercube vs Monte Carlo](https://astro-tools.github.io/gmat-sweep/examples/05_latin_hypercube/) —
64-run Latin hypercube alongside a 64-run plain Monte Carlo on the same perturbation,
pair-plotting the unit-cube samples to make the stratification visible.
## Roadmap
| Release | Scope |
|---|---|
| **v0.2** *(current)* | `monte_carlo()` and `latin_hypercube()` plus explicit-row `samples=DataFrame` sweeps. Programmatic resume via `Sweep.from_manifest(...).resume()`. Ephemeris and contact aggregation across runs. CLI gains `monte-carlo`, `latin-hypercube`, `explicit`, and `resume` subcommands. Manifest frozen as a stable v1 schema with a documented compatibility policy. macOS added to CI. Coverage gate raised to 85%. |
| **v0.3** *(next)* | `DaskPool` (extra `[dask]`) and `RayPool` (extra `[ray]`) for multi-machine sweeps. Cluster-recipe pages for Slurm `srun`, Kubernetes pod-per-worker, and Ray autoscaling. Benchmark page comparing backends on a 1000-run reference sweep. Throughput regression tests. `gmat-sweep show` gains a rich detail mode for inspecting per-run timing and stderr. |
Past releases live in [`CHANGELOG.md`](CHANGELOG.md).
## Development
To work on `gmat-sweep` itself:
```bash
git clone https://github.com/astro-tools/gmat-sweep.git
cd gmat-sweep
uv sync --all-groups
```
See [CONTRIBUTING.md](CONTRIBUTING.md) for the full branch / PR / test workflow.
## Licence
MIT. See [LICENSE](LICENSE).