Skip to main content

Declarative, prefix-reusing parameter sweeps over a step DAG.

Project description

dagsweep

Declarative, prefix-reusing parameter sweeps over a step DAG. Problem-agnostic: it knows nothing about your algorithms — only ports and variants.

You describe each step as a connector (named inputs/outputs, optional, with a list of variants to sweep). dagsweep wires the steps by port name, topologically orders them, and sweeps every combination — computing each shared prefix exactly once and reusing it for every child. The reuse is keyed on the chosen variant indices (a cheap token), never on a hash of the data, so large intermediate objects cost nothing to cache.

Why

A grid sweep A × B × C is a prefix tree: consecutive configurations share a long prefix. Hand-written nested loops capture that reuse but are rigid — a new step means editing the loop. dagsweep keeps the reuse but makes the structure declarative: add a step by appending one Step.

Example

from dagsweep import Step, Pipeline

pipe = Pipeline([
    Step("rank",  run_rank,  consumes=("rules", "measures"),
         produces="ranked", variants=rankers),
    Step("prune", run_prune, consumes=("ranked",),
         produces="pruned", variants=pruners),
    Step("clf",   run_clf,   consumes=("pruned",),
         produces="model",  variants=classifiers),
])

results = pipe.run(
    seed={"rules": rules, "measures": im},
    sink=lambda ctx: evaluate(ctx["model"]),
)
# [("BordaRank+M1Prune+OrdinalClassifier", <metric>), ...]  one record per leaf

rank runs once per ranker, prune once per (ranker, pruner), clf once per leaf — automatically.

The one rule: steps must be pure

fn(variant, *inputs) -> output must not mutate its inputs after returning them. The executor memoizes and shares outputs across configurations; mutating a shared output in place corrupts siblings. Purity is also what makes per-step parallelism safe (see Step.parallel, reserved).

Concepts

  • Port — a named value in the run context. A step produces one port and consumes zero or more. Ports not produced by any step are seeds, supplied to run.
  • Variant — one choice on a step's sweep axis. variants=(None,) is a step with no algorithm choice (a fixed transform).
  • Optional stepoptional=True: when the chosen variant is None the step is skipped and its output is taken from fallback. Put None in variants to sweep "with and without" the step.
  • Wiring is implicitconsumes/produces names form the DAG; declaration order does not matter, dependencies decide execution order.

Validation rejects duplicate writers, cycles, unreachable fallbacks, and missing seeds with clear errors.

Project details


Download files

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

Source Distribution

dagsweep-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

dagsweep-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file dagsweep-0.1.0.tar.gz.

File metadata

  • Download URL: dagsweep-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for dagsweep-0.1.0.tar.gz
Algorithm Hash digest
SHA256 10c449e288c2f7a49c8d6ee00c6ab187bde5669be46d388c99a2e0abc0f23976
MD5 f2e1fab2abc491deef1dee9cbad9331c
BLAKE2b-256 fe52f9d1368d715d9455922e5c76f44250f1faf2503f478a1ad7a545ca880982

See more details on using hashes here.

File details

Details for the file dagsweep-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dagsweep-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for dagsweep-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4db693f330feae4d324d09861ed804c055d93e1231499e6921398278bdaf4ac6
MD5 44b91ab6bf1b8e03f5e0296bff54f72f
BLAKE2b-256 7f8f75bb63c661501ffb98afbddf6c99d70ae31b00e7052bc6ea5fa83870317e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page