Skip to main content

xsweep

Content-agnostic parameter sweeps for xarray: lift an expensive point function into a gridded, cached, resumable computation.

Documentation and examples

Some functions cannot be vectorised along the dims you want to sweep: a Monte-Carlo solver, an iterative scheme whose stopping point depends on the data, an external engine that takes one configuration at a time. numpy has nothing to offer there, and the loop you write instead quietly grows a cache, a resume path, a deduplication table and a way to guess how long it will all take.

xsweep is that loop, written once.

import numpy as np, xarray as xr
from xsweep import sweep, SweepPolicy


@sweep("loop(tau, ssa) -> reflectance()", store="runs/layer.zarr", version="1")
def layer(tau: float, ssa: float) -> float:
    return monte_carlo(tau, ssa, n_photons=int(1e6))  # subprocess, GPU kernel, ...


space = xr.Dataset(
    {"tau": ("tau", np.linspace(0.1, 3.0, 40)), "ssa": ("ssa", [0.9, 0.95, 1.0])}
)

print(layer.explain(space))  # what it will cost, zero calls
result = layer(space)  # reflectance(tau: 40, ssa: 3)

Re-running that sweep makes zero calls. Interrupt it and relaunch: only the missing points are recomputed.

The three ideas

Semantics come from xarray, not from a second description. Variables sharing a dim vary together; variables on distinct dims multiply. A 1000 x 1000 map is a million zipped points, not a trillion product ones.

The contract describes the call, not the data. loop is one value per call, vec a whole axis, const context handed over unchanged, and the arrow names what one call produces. The same contract reads a parameter study and a satellite scene.

Cache, output and resume are the same artefact. Results stream into a zarr store with a status sidecar, which gives memoisation, bounded memory, resumability and safe parallel writes at once. Deduplication, batch sizes and executors are cost decisions on top, and a release gate enforces that they never move a value.

Install

pip install xsweep

Python 3.11+, with xarray, zarr and numpy. Dask is an optional executor backend and no core path imports it.

To work on xsweep itself: pixi install && pixi run -e dev all.

Documentation

Everything lives on the site: https://walcark.github.io/xsweep/

Status

v0. Motivating consumers: adjeff (Smart-G sweeps, replacing its internal SweepBundle and UniqueIndex), radtrans (the engine-agnostic half of its sweep layer), and short sensitivity studies in Earth observation.

License

Apache License 2.0.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xsweep-0.4.0.tar.gz (274.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xsweep-0.4.0-py3-none-any.whl (52.6 kB view details)

Uploaded Python 3

File details

Details for the file xsweep-0.4.0.tar.gz.

File metadata

  • Download URL: xsweep-0.4.0.tar.gz
  • Upload date:
  • Size: 274.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for xsweep-0.4.0.tar.gz
Algorithm Hash digest
SHA256 d702a324674e7017a365623e416bbf130d4d13147b0e64617b6a42c0aab3677f
MD5 c6af7758a77fd44faae297add28c54c6
BLAKE2b-256 32da935a72e24db49d8d7685a1cd3e365c9c71dd06d7de6b3cf594904f5b0c52

See more details on using hashes here.

Provenance

The following attestation bundles were made for xsweep-0.4.0.tar.gz:

Publisher: publish.yml on walcark/xsweep

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xsweep-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: xsweep-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 52.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for xsweep-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7379a89a2ecbd337c74c50f411da79a556aea76f031c4a44907607ebc25197d6
MD5 19d671c7eef008f73edf99d678e875bc
BLAKE2b-256 4913dd0d9dd1c9e250108e2d2a006a39d6baf04a6d16ab8249e137ba240cb4e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for xsweep-0.4.0-py3-none-any.whl:

Publisher: publish.yml on walcark/xsweep

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.4.1

2 files

This release

0.4.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page