Skip to main content

No project description provided

Project description

Invariant

A Python-based deterministic execution engine for directed acyclic graphs (DAGs). Invariant treats every operation as a pure function, providing aggressive caching, deduplication, and bit-for-bit reproducibility.

Features

  • Aggressive Caching: Artifacts are reused across runs if inputs match
  • Deduplication: Identical operations execute only once
  • Reproducibility: Bit-for-bit identical outputs across runs
  • Immutability: Artifacts are frozen once created
  • Determinism: Operations rely only on explicit inputs

Installation

# Clone the repository
git clone <repository-url>
cd invariant

# Install dependencies
uv sync

Quick Start

from invariant import Executor, Node, OpRegistry, cel, ref
from invariant.ops import stdlib
from invariant.store.memory import MemoryStore

# Create registry and register operations
registry = OpRegistry()
registry.register_package("stdlib", stdlib)

# Pipeline: compute (3 * 4) + (5 * 6), then scale the total
#
#   ab ──┐
#        ├── total ── scaled
#   cd ──┘
#
# Literal values flow directly into params — no wrapper nodes needed.
# ref()  passes a computed artifact to a downstream op.
# cel()  evaluates a CEL (Common Expression Language) expression against
#        upstream artifacts, useful for extracting or transforming values
#        without a dedicated op.
graph = {
    "ab": Node(
        op_name="stdlib:multiply",
        params={"a": 3, "b": 4},                    # literal inputs
        deps=[]
    ),
    "cd": Node(
        op_name="stdlib:multiply",
        params={"a": 5, "b": 6},                    # literal inputs
        deps=[]
    ),
    "total": Node(
        op_name="stdlib:add",
        params={"a": ref("ab"), "b": ref("cd")},    # ref() passes artifacts directly
        deps=["ab", "cd"]
    ),
    "scaled": Node(
        op_name="stdlib:multiply",
        params={"a": ref("total"), "b": cel("ab + cd")},  # cel() computes from upstreams
        deps=["ab", "cd", "total"]
    ),
}

# Execute the graph
store = MemoryStore()
executor = Executor(registry=registry, store=store)
results = executor.execute(graph)

print(results["ab"])      # 12
print(results["cd"])      # 30
print(results["total"])   # 42
print(results["scaled"])  # 42 * (12 + 30) = 1764

Architecture

Invariant separates graph definition from execution in two phases:

  1. Phase 1: Context Resolution - Builds input manifests for each node
  2. Phase 2: Action Execution - Executes operations or retrieves from cache

Documentation

Document Description
docs/architecture.md System overview, design philosophy, and reference test pipeline
docs/expressions.md Normative reference for ref(), cel(), ${...} parameter markers and the CEL expression language
docs/executor.md Normative reference for the two-phase execution model, caching, and artifact storage
examples/README.md Runnable examples with walkthroughs, DAG diagrams, and run instructions
AGENTS.md Quick-start guide for AI agents working with this codebase

Development

# Run tests
uv run pytest

# Run tests with coverage
uv run pytest --cov=src --cov-report=html

# Run linting
uv run ruff check src/ tests/

# Format code
uv run ruff format src/ tests/

License

MIT License - see LICENSE for details.

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

invariant_core-0.1.0.tar.gz (195.4 kB view details)

Uploaded Source

Built Distribution

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

invariant_core-0.1.0-py3-none-any.whl (30.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: invariant_core-0.1.0.tar.gz
  • Upload date:
  • Size: 195.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for invariant_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f8c1dbf2df647dc2f6f9f59420cacaf27d43b67ffa400c65449f502a2e33dee2
MD5 f952d797015139e2cf20a487bcf278dc
BLAKE2b-256 c0662f59c1d28351ef56107d7e4e90505c9780ddf817c21a99f418bd40984c69

See more details on using hashes here.

File details

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

File metadata

  • Download URL: invariant_core-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for invariant_core-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bae4b261489fdb49b527247d4080eb9a97f5d6b95d7701eea2f7859f42696f2c
MD5 6cedad6ea270a45521cf26e3370d3c0a
BLAKE2b-256 332a7b19c4f26ef7377629c3b9e029c1b798fdac2e4cd41e601c790f7f463cc2

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