Skip to main content

A Python-based deterministic execution engine for DAGs. Treats every operation as a pure function with aggressive caching, deduplication, and bit-for-bit reproducibility.

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.

Invariant was motivated by the need for deterministic graphics pipelines: icons, badges, dynamic UI components, and data visualizations where aggressive caching and bit-for-bit reproducibility matter. Critically, layouts can be described without a final size—size is injected at execution time and everything else is derived via the expression language. The engine itself is domain-agnostic; domain implementations like Invariant GFX provide graphics ops and plug in via the op registry.

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
  • Ephemeral nodes: Set cache=False to skip caching for frequently-changing outputs and their downstream dependents
  • Immutability: Artifacts are frozen once created
  • Determinism: Operations rely only on explicit inputs
  • Serializable graphs: Versioned JSON wire format for storage, transmission, and interoperability

Installation

# From PyPI
pip install invariant-core

# From source
git clone https://github.com/kws/invariant-core
cd invariant
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
docs/serialization.md Normative reference for graph JSON wire format (Node, SubGraphNode, ref, cel)
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.5.1.tar.gz (258.2 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.5.1-py3-none-any.whl (41.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: invariant_core-0.5.1.tar.gz
  • Upload date:
  • Size: 258.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for invariant_core-0.5.1.tar.gz
Algorithm Hash digest
SHA256 396fd862fb6c6325d3478ac00e1e0ad2fcf8251397e35d91bef2eac8153fdad4
MD5 2df8ee769320845dbc8edb7d3a59f081
BLAKE2b-256 1e27844e5f15b5ac3f2bea549e6415b1bdc61a514db913047da97bff0f11b84a

See more details on using hashes here.

Provenance

The following attestation bundles were made for invariant_core-0.5.1.tar.gz:

Publisher: release.yml on kws/invariant-core

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

File details

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

File metadata

  • Download URL: invariant_core-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 41.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for invariant_core-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b7a0bbf1208ca3e63ca5eeeae5036d9eb24a3ec4a466c8e9ac63590ea82fc30
MD5 e22593b41c3be1f23f9e2ccbd1499db5
BLAKE2b-256 b03477bb26a96b35a88461b6e4f7c8024cc0b93ed2b54d9d301cbc88bd27c500

See more details on using hashes here.

Provenance

The following attestation bundles were made for invariant_core-0.5.1-py3-none-any.whl:

Publisher: release.yml on kws/invariant-core

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

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