Skip to main content

From Play to Proof. Run experiments, then crystallize your findings.

Project description

Crystallize

From Play to Proof.

Run experiments. Start exploring, then crystallize your findings with a hypothesis.

pip install crystallize-ml

Quick Start

Exploratory Mode

Just play around. No ceremony.

from crystallize import run

def play_game(config, ctx):
    # Your logic here
    winner = "treatment" if config["power"] > 5 else "baseline"
    ctx.record("win", 1 if winner == "treatment" else 0)
    return {"winner": winner}

results = run(
    fn=play_game,
    configs={
        "weak": {"power": 2},
        "strong": {"power": 10},
    },
    replicates=5,
)

Output:

⚠  Exploratory mode — perfect for playing around.
   When ready to prove something: hypothesis="a.x > b.x"

Results:
  weak:
    win: [0, 0, 0, 0, 0] → μ=0.00
  strong:
    win: [1, 1, 1, 1, 1] → μ=1.00

Confirmatory Mode

You noticed something. Now prove it.

results = run(
    fn=play_game,
    configs={
        "weak": {"power": 2},
        "strong": {"power": 10},
    },
    replicates=20,
    hypothesis="strong.win > weak.win",
    seed=42,
)

Output:

✓ Confirmatory mode
  Hypothesis: strong.win > weak.win
  Seed: 42

✓ Hypothesis SUPPORTED
  strong.win (μ=1.00, n=20) > weak.win (μ=0.00, n=20)
  Effect size: 1.00, p=0.000

The API

from crystallize import run

results = run(
    fn=my_function,           # Your function: fn(config) or fn(config, ctx)
    configs={...},            # {"name": {config_dict}, ...}
    replicates=10,            # How many times to run each config
    seed=42,                  # For reproducibility
    hypothesis="a.x > b.x",   # Triggers confirmatory mode
    on_event=callback,        # For live UIs (viewer integration)
    progress=True,            # Show progress bar
)

Recording Metrics

def my_function(config, ctx):
    result = do_something(config)

    # Record metrics for analysis
    ctx.record("accuracy", result.accuracy)
    ctx.record("latency", result.latency, tags={"unit": "ms"})

    return result

Hypothesis Syntax

# Config A's metric > Config B's metric
hypothesis="treatment.accuracy > baseline.accuracy"

# Less than
hypothesis="fast.latency < slow.latency"

# Greater than or equal
hypothesis="new.score >= old.score"

Results

results = run(...)

# Raw return values
results.results["config_name"]  # [result1, result2, ...]

# Recorded metrics
results.metrics["config_name"]["metric_name"]  # [val1, val2, ...]

# Hypothesis result (if provided)
results.hypothesis_result.supported  # True/False
results.hypothesis_result.p_value    # Statistical significance

# Save results
results.to_json("results.json")

Live Updates

def on_event(event):
    if event["type"] == "metric":
        print(f"{event['config']}: {event['metric']} = {event['value']}")

results = run(
    fn=my_function,
    configs={...},
    on_event=on_event,
)

Philosophy

  1. No ceremony for exploration — Just run the function with configs
  2. Same code, more rigor — Add hypothesis= to crystallize, don't rewrite
  3. Hypothesis as pre-registration — Commit before seeing results
  4. Statistical output built-in — p-values, effect sizes, not just means

Install

# Basic (no statistical tests, just mean comparison)
pip install crystallize-ml

# With statistical tests (scipy)
pip install crystallize-ml[stats]

v0.x Legacy

Looking for the old framework with pipelines, treatments, and plugins? See the legacy/v0.x branch.

License

MIT

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

crystallize_ml-1.0.0a1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

crystallize_ml-1.0.0a1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file crystallize_ml-1.0.0a1.tar.gz.

File metadata

  • Download URL: crystallize_ml-1.0.0a1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for crystallize_ml-1.0.0a1.tar.gz
Algorithm Hash digest
SHA256 5c43c841db136017ff2e5b46e144ea54829872bbfb187d0941745a580261af2c
MD5 886e157d96c821ea3560c42058053d2b
BLAKE2b-256 0c543717e3c89119ca38fbd2a4ff6cc43da777c58f5ba36f51d5753b0f5c8d34

See more details on using hashes here.

Provenance

The following attestation bundles were made for crystallize_ml-1.0.0a1.tar.gz:

Publisher: publish_pypi.yml on brysontang/crystallize

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

File details

Details for the file crystallize_ml-1.0.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for crystallize_ml-1.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 7fffaf3d2dcd11e92b23a7e49f4ec757c76c653c7a806268c981a576e15cceee
MD5 bafab8838dd9dbfbb394e340d1db28a9
BLAKE2b-256 775be289dccd8482771ccd7b774b76a28ee92e5c5075cc80939ebb1f70df67bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for crystallize_ml-1.0.0a1-py3-none-any.whl:

Publisher: publish_pypi.yml on brysontang/crystallize

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