oncodsl / Read docs /PROMPT_program_graph.md
govindbalki's picture
Upload folder using huggingface_hub
0fff343 verified
|
Raw
History Blame Contribute Delete
6.82 kB
# Prompt β€” Program graph + paste-to-draw tool (with format help & copy)
Build/refine the Lab's "Program graph" feature: render any DSL program as a node-graph (React Flow), with a paste-to-draw mini-tool as the primary way to view a program, a detailed format guide, and easy ways to obtain a program's text. Presentation/read-only β€” do not change the GP science or the airgap. It MUST look like it belongs to the existing Lab (same cards, palette, fonts, InfoTip). React Flow is an allowed frontend dependency.
## 0. READ FIRST (don't assume)
Open a real run and read the ACTUAL shapes: GET /runs/{id}/result and one candidate object. Confirm the exact `program_repr` text format and how structure is represented (which operators appear, how genes are grouped). Build the parser around what you actually see, and make the Format guide (Section 4) describe the REAL operators/aggregations β€” the lists below are the expected set; verify and adjust to match.
- If per-set / tree structure isn't recoverable from the payload, add a structured field (opaque IDs ONLY), keep every existing field, and extend the airgap test.
## 1. PRINCIPLES
- Airgap absolute: graphs show opaque g##### IDs until an explicit reveal; pasted programs are opaque-only.
- Keep the page light: ONE graph at a time in a single graph area β€” the winning program by default, replaced by whatever is drawn next. Never render a graph per candidate.
- ONE shared parser: `program_repr` text β†’ render model, used by the winner render, the paste tool, AND tile clicks. Do not write two parsers. The parser must tolerate the documented format with or without spaces (trim/normalise input).
## 2. RENDERING (React Flow, aligned with the app)
- Wrap in the SAME section card the other sections use (1px #ECEAE4 border, #FCFBF8 fill, ~14–16px radius, generous padding) with a bold #23303A heading "Program graph", the existing <InfoTip> "?" beside it, and a one-line #6E7F8C caption.
- Palette tokens only: bg #FAFAF7, card #FCFBF8, ink #23303A, muted #6E7F8C, border #ECEAE4, accent #3A6B7E, highlight #BC6B2E. Same font stack; render opaque gene IDs in the SAME monospace as the run id.
- Custom node styles (match the app's cards): verbs (Select, Reduce, Combine, Fit) = #FCFBF8 rounded box, 1px #3A6B7E border, #23303A label, optional #6E7F8C subtitle. Data nouns (M / "Expression matrix") = subtle grey pill (#F1EFEA fill, #ECEAE4 border). Scores = amber pill (#FBF1E6 fill, #BC6B2E border). Output node (label matches the objective β€” "MSI-H probability" or "association") = filled #BC6B2E, white text. Edges = thin #B9B6AE smoothstep with arrowheads; no animated edges.
- Tier containers when a program combines scores: light teal group box (#F1F6F7 fill, thin #3A6B7E border, "Tier-1" label) per sub-score, wrapped in a dashed #BC6B2E "Tier-2 program" box. A single-score program needs no dashed wrapper.
- TURN OFF React Flow default chrome: no <Background> (plain #FAFAF7/transparent canvas); hide connection handles (.react-flow__handle { opacity:0 }); remove node selection outline/box-shadow; no MiniMap; omit <Controls> or restyle to the muted palette; proOptions={{ hideAttribution: true }}; use fitView. Deterministic left-to-right layout (manual x/y) β€” no extra auto-layout library.
- The graph ALWAYS roots in the DSL primitives (M β†’ Select β†’ Reduce β†’ … β†’ output) and draws ARBITRARY trees of the real operators β€” not a fixed skeleton.
## 3. PASTE-TO-DRAW (primary feature)
- Inside the card: a monospace textarea labelled "Paste a program", a "Draw" button, and the single graph area below.
- On Draw, parse the textarea with the shared parser and render into the graph area, identically styled.
- Invalid/unparseable input β†’ a friendly inline message in muted text (#6E7F8C), no crash.
- Pasted programs render with opaque IDs only; Reveal/evaluate is NOT available for arbitrary pasted text (only for actual-run winners) β€” state this in the hint.
- The textarea PLACEHOLDER is the well-formed example below (note: every Reduce wraps a Select).
## 4. FORMAT & EXAMPLES (detailed; collapsed-by-default panel under the textarea, plus the "?")
Document the syntax with this content (adjust operator names to the real grammar from Section 0):
- What a program is: a recipe that turns gene expression into ONE score per patient.
- The pieces:
- `M` β€” the expression matrix (all patients Γ— genes); the starting data.
- `Select(M, [g#####, ...])` β€” pick a group of genes β†’ a smaller matrix.
- `Reduce(<matrix>, <agg>)` β€” collapse that group into one score per patient. `<agg>` = mean | median | max | min | var.
- `Combine(<scoreA>, <scoreB>, <op>)` β€” merge two scores into one. `<op>` = add | sub | mul | div (safe) | mean.
- Output: one score per patient, used to separate the groups.
- Rules: gene IDs are the opaque `g#####` IDs shown on the tiles and in the result; list a Select's genes in [square brackets], comma-separated; spaces are optional; every Reduce should wrap a Select(...) so it reduces a chosen group, not the whole matrix.
- Annotated example (also the placeholder):
`Combine( Reduce(Select(M,[g05347,g00048]), mean), Reduce(Select(M,[g06271]), max), sub )`
β†’ "average g05347 & g00048 β†’ scoreA; take the max of g06271 β†’ scoreB; final score = scoreA βˆ’ scoreB."
## 5. HOW TO GET A PASTEABLE PROGRAM
Make it trivial to obtain a program in this exact text form:
- Result panel: a "Copy program" button next to the winning program that copies its `program_repr` to the clipboard (navigator.clipboard; degrade gracefully if unavailable β€” e.g. a select-the-text fallback).
- Population tiles: clicking a tile loads its program into the textarea AND draws it; ALSO add a small copy icon on each tile (or on hover) that copies that tile's `program_repr`.
- A one-line muted hint under the textarea (always visible): "Paste a program here, or click any tile to load it. Use Copy to grab a program's text."
- Every copied/loaded string is the raw `program_repr` (opaque IDs only) β€” the exact string the parser accepts β€” so copy β†’ paste round-trips and draws identically.
## 6. REVEAL
- After "Reveal & evaluate" (run winner only), swap opaque IDs for real gene names in every Select node, highlighting matched reference genes in #BC6B2E. Do not attempt reveal on arbitrary pasted programs.
## 7. WHERE
- Result panel: render the WINNING program's graph by default.
- Population tiles drive the same single graph area (load on click) β€” no separate per-tile graphs.
## CONSTRAINTS
- Airgap test green (including any new structured field); existing endpoints / Streamlit / live curve untouched.
- One shared parser; one graph area; parser tolerant of spacing.
- The graph, paste tool, format panel, and copy buttons are Client Components ("use client").