Write a manifest

Write a manifest#

Build the small JSON document that describes a compiled kernel, and watch raptor refuse every way of getting it wrong.

Time: ~5 min · Runs on: CPU, no GPU needed · You need: raptor-core; read first: What the contracts buy you

Colab or Kaggle: run this first cell (it installs the packages and downloads the helper files this notebook uses). Elsewhere it only checks the imports.

Hide code cell source

# Colab setup, generated by python -m raptor_docs.nb colab_setup (do not edit).
import os

try:
    import google.colab  # noqa: F401
    HOSTED = True  # a Colab runtime
except ImportError:
    HOSTED = "KAGGLE_KERNEL_RUN_TYPE" in os.environ  # a Kaggle kernel

if HOSTED:
    import importlib.metadata, pathlib, re, shutil, subprocess, sys, urllib.request

    gpu = bool(shutil.which("nvidia-smi")) and subprocess.run(["nvidia-smi", "-L"], capture_output=True).returncode == 0
    extra = ""
    if gpu:
        # the CUDA major the runtime already has: a CuPy that is installed, else torch's, else the driver's
        major = None
        for m in ("13", "12"):
            try:
                importlib.metadata.version(f"cupy-cuda{m}x")
                major = m
                break
            except importlib.metadata.PackageNotFoundError:
                pass
        if major is None:
            try:
                import torch
                major = "13" if str(torch.version.cuda).startswith("13") else None
            except ImportError:
                pass
        if major is None:
            smi = re.search(r"CUDA Version: (\d+)", subprocess.run(["nvidia-smi"], capture_output=True, text=True).stdout)
            major = "13" if smi and int(smi.group(1)) >= 13 else "12"
        extra = f"[cuda{major}]"
        print(f"GPU found: installing the {extra} extras to match this runtime.")
    pre = ["--pre"] if os.environ.get("RAPTOR_PRE") else []  # optional: test a release candidate
    ref = os.environ.get("RAPTOR_REF", "main")  # optional: fetch the helper files from this git ref
    if pre or "RAPTOR_REF" in os.environ:
        print(f"Pre-release test: installing with --pre, helper files from {ref}.")
    # our packages with --upgrade, so a runtime that kept an older release gets the current one
    subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", "--upgrade", *pre, "raptor-core"])
    subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", "matplotlib"])
    base = os.environ.get("RAPTOR_RAW_BASE", "https://raw.githubusercontent.com")  # optional: a local mirror
    top = os.environ.get("RAPTOR_WORKDIR") or ("/kaggle/working" if "KAGGLE_KERNEL_RUN_TYPE" in os.environ else "/content")
    root = pathlib.Path(top) / "raptor"
    for rel in (
        "docs/content/_shared/nb_diagrams.py",
        "docs/content/_shared/themed_figure.py",
    ):
        (root / rel).parent.mkdir(parents=True, exist_ok=True)
        urllib.request.urlretrieve(f"{base}/amasat01/raptor/{ref}/{rel}", root / rel)
    (root / "docs/content/tutorials").mkdir(parents=True, exist_ok=True)
    os.chdir(root / "docs/content/tutorials")
    if not gpu:
        print("Running on the CPU (no GPU in this runtime). For a GPU: " + ("Settings → Accelerator → GPU T4 x2." if "KAGGLE_KERNEL_RUN_TYPE" in os.environ else "Runtime → Change runtime type → T4 GPU."))

try:
    import raptor  # noqa: F401
except ImportError as err:
    raise ImportError(
        "raptor not found. Install with `pip install matplotlib raptor-core`."
    ) from err

Hide code cell source

import sys; sys.path.insert(0, "../_shared")
from nb_diagrams import manifest_key_gloss
manifest_key_gloss()
Chart: A v2 manifest's top-level keys, in their contractual order

The code#

raptor.schema.validate_manifest checks the manifest dict’s shape — never whether the artifact it names actually exists or runs. The cells below walk through what counts as a valid shape, one rule at a time, starting with the simplest manifest that passes:

from raptor.schema import validate_manifest

v1 = {
    "schema_version": 1,
    # pattern: which kind of kernel this is; "pure" = no side effects
    "pattern": "pure",
    "aether_abi": "aether-abi/1",
    # format "ptx": NVIDIA's GPU assembly format
    "plugins": [{"name": "two_body_step", "format": "ptx"}],
}
validate_manifest(v1)
print("v1 OK")
v1 OK

No exception, and nothing printed but the OK — a v1 manifest carries none of schema v2’s execution-axis keys.

Schema v2 adds the execution axis — exec_targets/exec_access — as two more top-level keys, still validated the same way:

v2 = {
    "schema_version": 2,
    "pattern": "pure",
    "aether_abi": "aether-abi/2",
    "exec_targets": ["host", "device"],
    # sample_local: touches only this one sample's own data
    "exec_access": "sample_local",
    "plugins": [{"name": "two_body_step", "format": "ptx"}],
}
validate_manifest(v2)
print("v2 OK")
v2 OK

Both versions load today: v2 is additive, never a replacement for v1.

Three ways to get it wrong, and the exact refusal each one gets. First: a v1 document may not carry a v2 execution key.

bad_v1 = dict(v1, exec_targets=["host"])
try:
    validate_manifest(bad_v1)
except ValueError as exc:
    print("rejected (v1 + exec key):", exc)
rejected (v1 + exec key): '<document>': schema v1 must not carry execution key(s) ['exec_targets'] (the execution axis is schema-v2-only; set schema_version=2 and aether_abi='aether-abi/2' to use it)

The version tag alone decides which keys are legal — exec_targets on a v1 document is a breach, not an upgrade hint.

Second: the top-level keys are contractual in order — plugins may not come before the execution axis:

reordered = {
    "schema_version": 2, "pattern": "pure", "aether_abi": "aether-abi/2",
    "plugins": v2["plugins"], "exec_targets": v2["exec_targets"],
    "exec_access": v2["exec_access"],
}
try:
    validate_manifest(reordered)
except ValueError as exc:
    print("rejected (wrong key order):", exc)
rejected (wrong key order): manifest top-level key order violates the key-order contract: got ['schema_version', 'pattern', 'aether_abi', 'plugins', 'exec_targets', 'exec_access'], expected ['schema_version', 'pattern', 'aether_abi', 'exec_targets', 'exec_access', 'plugins']

Same keys, same values, wrong order — rejected, because the order itself is part of the contract.

Third: a schema version this loader (the code that reads and checks a manifest) does not understand is refused outright — forward-strict (refuses anything newer than it knows, rather than guessing what it means), never a silent best-effort parse:

too_new = dict(v1, schema_version=7)
try:
    validate_manifest(too_new)
except ValueError as exc:
    print("rejected (future version):", exc)
rejected (future version): '<document>' was built for plugin schema v7, but this loader supports v3; upgrade eagle to load it

A future version is a hard refusal, not a guess at what it might mean.

What just happened#

  • A manifest is validated for shape — key order, version, and the execution axis’s vocabulary — not for whether the artifact it names actually exists or runs.

  • Getting any one of those three things wrong raises a ValueError that names exactly what was wrong, rather than silently loading a best-effort guess.

  • schema_version 1 and 2 both load today — v2 only adds flat keys for where and how a kernel body may run; it never replaces v1.

In practice you will not hand-write this dict: hawk’s own writer, hawk.artifact.write_manifest, emits one in the correct order from a compiled kernel directly (see hawk’s Your first kernel).

Try this#

Drop the aether_abi key from v2 entirely and validate it again — absence is fine (the field is optional); only a wrong tag for the declared version is refused.

Next#

Implement a protocol covers the other half of the contract: the shapes an engine or kernel provider must have. Deeper: Interoperability.