feat(pipekit-ops): a readable recipe format with named steps

Open
#222 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python, yaml
Domain
api, backend

Research direction

Read packages/pipekit-ops/src/pipekit_ops/serial.py and _base/graph.py, focusing on dumps, loads, Graph.get_config, and Sequential serialization. Then inspect the package exports and serialization tests to see how state records and sandbox checks work. Done means the readable API round trips supported graphs, handles shared operators and nesting, and has tests and exports; YAML support and explicit step naming are design decisions still open in the issue.

Written by the indexing model from the issue text.

Description

area:code layer:0-primitives priority:p2 type:feature wave:1

Problem / Request

pipekit.dumps(graph) writes a record built for machines: operators in a list, nodes that point at operators and at each other by index. It round-trips, but nobody can read a recipe from it or edit one by hand. There is no readable format with named steps, though the serial.py docstring already promises YAML front ends in an optional extra (pipekit[yaml]), which no package ships.

User Story

As someone who keeps recipes in a repository, reviews them in pull requests and edits them by hand, I want a readable form of a Graph, with each step named and its inputs named, that loads back to the same Graph.

Motivation

Found while writing the GeoStack Kinds and Roles design page (jejjohnson/geostack#127), whose plume recipe has four steps. Its dumps today:

{
  "class": "Graph",
  "config": {
    "inputs": ["scene", "wind"],
    "nodes": [
      { "operator": 0, "parents": [{ "input": "scene" }] },
      { "operator": 1, "parents": [{ "node": 0 }] },
      { "operator": 2, "parents": [{ "input": "wind" }] },
      { "operator": 3, "parents": [{ "node": 0 }, { "node": 1 }, { "node": 2 }] }
    ],
    "operators": [
      { "class": "MethaneRetrieval", "config": { "window_nm": [2122.0, 2488.0] }, "module": "plume" },
      { "class": "PlumeSegmentation", "config": { "k": 3.0, "min_pixels": 20 }, "module": "plume" },
      { "class": "WindAt", "config": { "lat": 31.98, "lon": -103.52 }, "module": "plume" },
      { "class": "EmissionRate", "config": { "kappa": 6.56e-07 }, "module": "plume" }
    ],
    "outputs": { "emission": { "node": 3 } }
  },
  "module": "pipekit_ops._base.graph"
}

To see what EmissionRate takes, you count positions in nodes, then in operators. The page now shows a readable view built by a 20-line helper. It should be pipekit's: the same view in a notebook, a PR diff, a DVC params file and a GeoApps upload.

Proposed API

# readable records: plain dicts, no new dependency, in pipekit-ops
def to_readable(op: Operator) -> dict[str, Any]: ...
def from_readable(record: dict[str, Any]) -> Operator: ...      # same checks as loads
def from_readable_sandboxed(record: dict[str, Any]) -> Operator: ...  # allowlist, as loads_sandboxed

# YAML on top, in the optional extra the serial.py docstring names
def dumps_yaml(op: Operator) -> str: ...                         # pipekit[yaml]
def loads_yaml(text: str, *, sandboxed: bool = False) -> Operator: ...

Design Snapshot

The same recipe, readable:

graph:
  inputs: [scene, wind]
  steps:
    methane_retrieval:
      op: plume.MethaneRetrieval
      in: [scene]
      config: {window_nm: [2122.0, 2488.0]}
    plume_segmentation:
      op: plume.PlumeSegmentation
      in: [methane_retrieval]
      config: {k: 3.0, min_pixels: 20}
    wind_at:
      op: plume.WindAt
      in: [wind]
      config: {lat: 31.98, lon: -103.52}
    emission_rate:
      op: plume.EmissionRate
      in: [methane_retrieval, plume_segmentation, wind_at]
      config: {kappa: 6.56e-07}
  outputs:
    emission: emission_rate

Rules the format needs (the implementer decides the details, the tests pin them):

  • Step names. By default, the operator's class in snake case, with _2, _3, … when a class repeats. Explicit names are an open question: a name= on the symbolic call, or a names= mapping on Graph.
  • in. The positional inputs, in order; each is a declared input or an earlier step, by name. The order of steps is the topological order, as nodes is now.
  • op. module.Class, so the loader resolves it exactly as from_state does.
  • config nested, not inlined. Inlining the config next to op and in would break for any operator with a parameter called op or in.
  • Shared operators. The machine record lists an operator once when several nodes use it. The readable form needs to keep that: for example op: {same_as: methane_retrieval}.
  • Nesting. A Sequential inside a step reads as a list of {op, config}; a Graph inside a step reads as a nested graph:.
  • Round trip. from_readable(to_readable(g)).state == g.state for every Graph dumps accepts. Operators that set forbid_in_yaml refuse, as loads does.

References & Existing Code

  • packages/pipekit-ops/src/pipekit_ops/serial.py: dumps, loads, from_state_sandboxed, loads_sandboxed, and the docstring that names pipekit[yaml].
  • packages/pipekit-ops/src/pipekit_ops/_base/graph.py: Graph.get_config, the record the readable form maps to and from.
  • The motivating page: jejjohnson/geostack#127, docs/design/pages/kinds-and-roles.html, section "⑥ Recipe, and orchestration".

Implementation Steps

  • Add to_readable / from_readable / from_readable_sandboxed in packages/pipekit-ops/src/pipekit_ops/serial.py, mapping to and from the Graph.get_config record (and Sequential's), recursively.
  • Default step names, deduplicated; decide explicit names (call-site name= or Graph(names=…)).
  • Shared operators and nested containers, as above.
  • dumps_yaml / loads_yaml behind a [yaml] extra (PyYAML, safe_load only), or fix the serial.py docstring if YAML stays out of scope.
  • Export the new functions from pipekit_ops/__init__.py (and the umbrella, if that is where dumps is exported).

Definition of Done

  • Code lands at the intended path
  • Public API exported via src/<package>/__init__.py
  • Tests pass: make test
  • Lint + typecheck pass: make lint && make typecheck
  • Docstrings (Google-style) on all public symbols

Testing

  • Round trip: for a linear chain, a fan-in Graph, a Graph with a shared operator and a Graph nesting a Sequential, from_readable(to_readable(g)).state == g.state.
  • Step names: deduplicated when a class repeats; stable across runs.
  • A config with keys named op or in survives the round trip.
  • from_readable_sandboxed rejects a class outside the allowlist at any depth; forbid_in_yaml operators refuse.
  • YAML: loads_yaml(dumps_yaml(g)).state == g.state, and loads_yaml never constructs arbitrary Python objects (safe_load).

Documentation

  • The serialisation docs page: the readable form next to the JSON, with the recipe above as the example.

Relationships

  • Related: jejjohnson/geostack#127 (the design page that found it); #221, the multi-input signatures filed alongside this one.

Generated by Claude Code

Dominant language
Python
Stars
0
Forks
0
Avg merge
3h 50m
Merged PRs (30d)
143

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jejjohnson/pipekit

All issues in jejjohnson/pipekit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.