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.1.tar.gz (7.6 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.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dagsweep-0.1.1.tar.gz
  • Upload date:
  • Size: 7.6 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.1.tar.gz
Algorithm Hash digest
SHA256 13ef630fe3800faf9f6829ce5cfe315139263c0dd2188521344b1e68e468cc49
MD5 b0e4590f30854a73f48a6328cc42f0bd
BLAKE2b-256 61145a89149bd7fcd1fb019189527cf28a8583b8281160b97980bd255f892164

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dagsweep-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c688d9d12348696e223a80b50c6aca48ddb1dd71e9dbbcb52b7e3b7b6d692aa0
MD5 01bea9a6987406f0d11c9be0bafb4df4
BLAKE2b-256 7a23756d63989d5de229c359a5fc88bf8c382c06a15dcb53189523faa023447b

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