diff --git a/CHANGELOG.md b/CHANGELOG.md index 16c8684..4386878 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## 1.12.0 + +- **Papers drive the work; the record names no paper** (method rule 8, model section 4). A lab that writes + papers keeps one overview page of the whole trail and one page per active paper, written as that paper's + argument and opening with a scope table: audience, thesis, experiments included, excluded or superseded, and + open. The papers' open rows and their reviewers' criticisms say what is proposed, ordered, parked or dropped, + and a result revises the overview and every paper it touches. So far gives the current finding, never the + story of the bugs on the way. Adding, merging or retiring a paper is direction. +- **`[papers]` in `lab.toml`** names the overview and the active paper pages, as library paths. It is optional: + a lab without it is unchanged. With it, each paper page marks its scope cells `data-scope="included"`, + `"excluded"` and `"open"`, and `lab check` refuses an id that is not in the lab, a step under included that is + not done or is void, a step under open that is finished, a question or goal under open that is done, a parked + or dropped question or goal in either, and a goal, question or step listed in two rows of one page. It notes a + paper page committed before a result about something it lists under included or open. +- **`lab now` lists the papers**: each active paper with the open work its scope names, then the live steps + that no paper lists, by themselves or by their question or goal. +- The skills `lab-set-up`, `lab-work`, `lab-talk` and `lab-review` and the method changed: run `lab init` in a lab + after upgrading. + ## 1.11.1 - **A run in progress in another checkout no longer fails `lab check`.** A run stays in the `.lab/running` of the diff --git a/README.md b/README.md index 766f06f..a5af74e 100644 --- a/README.md +++ b/README.md @@ -56,5 +56,5 @@ where folio serves the lab, which brings `folio-kb` 0.5.0 or later, and list `la ## Read more - [docs/model.md](docs/model.md): the contract. What you read, how a number becomes a result, who decides, the commands, the files. -- [method/METHOD.md](method/METHOD.md): the seven rules every lab keeps. +- [method/METHOD.md](method/METHOD.md): the eight rules every lab keeps. - [skills/](skills/): lab-set-up, lab-work, lab-review, lab-talk and lab-mission. [agents/](agents/): the reviewer. diff --git a/docs/model.md b/docs/model.md index fb0e07d..f3d091e 100644 --- a/docs/model.md +++ b/docs/model.md @@ -255,7 +255,7 @@ in points. When a named result belongs to a replaced experiment, the page says s You decide two things: **direction** and **resources**. You decide them in a discussion with the agent, not by approving requests. -- **Direction.** The goals and the questions. +- **Direction.** The goals, the questions, and the papers they serve. - **Resources.** Everything outside the lab that it may touch: what it may use, how much, and what it may do there. @@ -376,6 +376,36 @@ is a resource and a cap, nothing else. A lower cap is the agent's to write. A hi rule, a new resource or a larger grant comes out of a decision: one that lists that experiment, or that resource, under `about:`. +**Papers drive the work; the record names no paper.** A lab that writes papers keeps two layers apart. The +record (`goals/`, `decisions/`, `runs/`) is the trail: every question, run, failed attempt and replaced +experiment, so that every number has an origin. No card names a paper, because papers change, split, merge +and are dropped while the record stays as it is and is read by each of them. Above the record, the lab's +library holds one **overview** page that keeps the whole trail in one place, whatever paper it serves: the +words on one running example, the workflow, every related-work row, every established finding, every +criticism and what answers it. Beside it, each **active paper** has its own page, written as that paper's +technical argument and nothing else: it never talks about the lab or how it works. A paper page opens, under +its thesis, with a **scope table** of five rows: the target audience and venues, the core thesis, the +experiments included (the clean runs each claim rests on), the experiments excluded or superseded (a run +that hit a harness bug, a subset a full run replaced, work that belongs to another paper), and the open +experiments the paper still needs. Then come its words on one running example, its pipeline, its +comparison with the published work of its community, its established results citing only included work, +the criticisms a reviewer in that community will raise with what answers each, and what remains to run. + +The control runs from the papers to the lab, not the other way. Which questions and experiments are +proposed, ordered, parked or dropped follows the open rows and the criticisms on the active paper pages: a +decision says which paper row it serves, and a step that serves none is a candidate to park or drop. When a +result lands, the overview and every paper it touches are revised; a run that a newer one supersedes moves +from included to excluded. Adding, merging or retiring a paper is direction, so it is decided with you. A +question's or an experiment's So far gives the current finding, not the story of the bugs on the way: the +replaced experiments and the reasons they were replaced keep that story. + +A lab opts in by naming the pages in `lab.toml` (section 9). Then `lab check` holds each scope table: +included lists only finished work that is not void, replaced or dropped, open only work still to do, nothing +parked or dropped is in either, and a goal, a question or a step sits in one row; a paper page committed +before a result about something it lists under included or open is noted. `lab now` lists each paper's open +experiments, and the live steps no paper lists, by themselves or +by their question or goal. + ## 5. What the agent uses - **To look:** `lab now`, `lab show `, `lab brief `, `lab since`, `lab define `. Each shows one level, @@ -449,7 +479,7 @@ Five skills: `lab-set-up`, `lab-work`, `lab-review`, `lab-talk` (tell you where a decision to you, record what was decided), and `lab-mission` (save, launch, resume and close a mission). One role: the reviewer. -Seven rules: +Eight rules: 1. Say what would refute it before you run. 2. A number counts only as a reviewed result of a locked plan. @@ -462,11 +492,13 @@ Seven rules: 6. Record what was decided and why, in the lab's words, and show the operator the text as recorded. Never record a decision that was not discussed with them. 7. Say what you are on. When you start on a card, log what you are doing and why now. +8. Papers drive the work; the record names no paper. The papers' open rows and criticisms say what to + propose, order, park or drop, and a result revises the overview and every paper it touches. `lab check` holds what can be held mechanically: ids and links, the goal's vocabulary being terms of the glossary, a title and a description on every card, short cards that write only their own front matter, a test on every line, a reason on every replacement, unchanged locks, sealed runs, results that still re-derive and were reviewed, use inside -the resources' amounts, a decision behind every goal, question and metered amount, an experiment +the resources' amounts, what each paper's scope table lists when the lab names its papers, a decision behind every goal, question and metered amount, an experiment behind every answer, the method and the skills as the kit installed them, and a history that only grows. What it cannot read as this page describes (a mistyped folder, a list written as one value, a file that is not text) is a problem it reports; no command stops on it. @@ -903,6 +935,33 @@ holds the line `launched`, else next, and `lab check` asks for the status to be reports a mission that breaks any of this, one whose `carries:` is not a decision, and a current mission whose decision is still open. +**Papers.** `lab.toml` names the library's paper pages in a table, as library paths (the path under +`content/`, as `see:` writes it): + +``` +[papers] +overview = "entries/where-the-results-stand" +active = ["entries/paper-a", "entries/paper-b"] +``` + +`overview` is the page that keeps the whole trail; it is never an active paper. Each page under `active` is +in the library and marks the three cells of its scope table that list work, `data-scope="included"`, +`data-scope="excluded"` and `data-scope="open"`, empty when it lists nothing: + +``` +Experiments includedG1.Q1.4, ... +``` + +A cell lists what its `/lab//` links name, written from the site's root; any other text in it is prose. A +cell whose closing tag is left out ends where the next cell or row begins. The rules hold for the ids written in +the cells. Under included, a step is done and not void, and a question or a goal is not parked or dropped; +under open, a step is open, waiting or running, and a question or a goal is not done, parked or dropped. A goal, +a question or a step has one row on a page: where another row needs to mention it, it is named in words, +without its link. A question written in one row and a step under it written in another is allowed: the open +question with its one finished step included is the usual case. A decision may be cited in any row. In +`lab now` and in the note on a stale page, a goal or a question written under included or open stands for +every step under it. A lab without `[papers]` has none of this. + **Worked-out states.** A goal is open until `reached: true` makes it done or `dropped:` drops it. A question is waiting while the decision it came from is open, then open, then done with its answer; it is parked while the last settled decision that parks or brings it back parks it. A step is waiting while diff --git a/method/METHOD.md b/method/METHOD.md index e5460f9..6613526 100644 --- a/method/METHOD.md +++ b/method/METHOD.md @@ -1,6 +1,6 @@ # The method -Seven rules every lab keeps. Each says what holds it: a command that refuses, a check, or a reviewer's +Eight rules every lab keeps. Each says what holds it: a command that refuses, a check, or a reviewer's judgement. The lab's own `AGENTS.md` adds only what is local. 1. **Say what would refute it before you run.** An experiment states what it compares, what would @@ -25,13 +25,14 @@ judgement. The lab's own `AGENTS.md` adds only what is local. 4. **Write for a reader who was not there.** Every page stands on its own: it says what each thing it mentions is, names each arm of an experiment and what it is, names another page by its exact title, and uses a term only as the glossary defines it, the one place a word is defined. A number is said once: it lives in its result row, and a card names it. A state is - worked out, never written, and So far says what was learned, never where a step stands. Every + worked out, never written, and So far says what is learned now, never where a step stands and never the story of + the bugs on the way: the replaced experiments keep that. Every card has one of the same states: open, waiting, running, parked, done, replaced or dropped. A number's label says what it counts and of how many, in one set of cases named once: "of the 20 checks the solver leaves open", not "of 20". *The numbers and the budgets are held by `lab check`; whether a page can be read cold is judged, and the reviewer reads for it.* 5. **Decide everything that is not direction or resources, and never wait idle.** Direction is the - goals and the questions. Resources are what `resources.toml` lists and how much. For those two, + goals, the questions and the active papers. Resources are what `resources.toml` lists and how much. For those two, open a decision that says what was seen, the options and what you recommend, and work on what it does not hold. What a decision settled needs no further yes. Everything else is yours: decide, record it, go on. A mission (`missions/`) carries out what a settled decision settled across sessions, and approves @@ -49,3 +50,11 @@ judgement. The lab's own `AGENTS.md` adds only what is local. should never have to ask you. When you start on a card or move to another, log it: `lab log doing "" ""`. The line stands on the front page until a result, a stuck line or a choice about the same card ends it. *Judged.* +8. **Papers drive the work; the record names no paper.** The record is the trail, and no card names a paper. + When the lab writes papers, its library keeps one overview of the whole trail, and one page per active + paper that is that paper's argument and nothing else. A paper page opens with its scope table: audience, + thesis, the experiments included, those excluded or superseded, and those still open. What you propose, + order, park or drop follows the papers' open rows and their reviewers' criticisms; when a result lands, + revise the overview and every paper it touches, and move what a newer run supersedes to excluded. Adding, + merging or retiring a paper is direction. *Held by `lab check` when `lab.toml` names the papers; otherwise + judged.* diff --git a/pyproject.toml b/pyproject.toml index bbce8d4..c26407e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] dynamic = ["readme"] name = "lab-kit-cli" -version = "1.11.1" +version = "1.12.0" description = "A research lab's record, its method, and the command that keeps both." license = "MIT" authors = [{ name = "Piergiuseppe Mallozzi" }] diff --git a/skills/lab-review/SKILL.md b/skills/lab-review/SKILL.md index 48f65e6..20148d3 100644 --- a/skills/lab-review/SKILL.md +++ b/skills/lab-review/SKILL.md @@ -44,7 +44,8 @@ A failed plan is fixed by its author and read again. the first sentence and folds the rest. A failed results review is final for that experiment. Say in the note what a replacement must do -differently. +differently. Its numbers can then be cited nowhere: if a paper page lists it under included, `lab check` +says so, and the author takes it off. When you read a plan, also read the card as someone who was not there. If an arm is named and not explained, or the card points at something it does not say, say so in the note: it does not fail the diff --git a/skills/lab-set-up/SKILL.md b/skills/lab-set-up/SKILL.md index d80a6c7..86bc7df 100644 --- a/skills/lab-set-up/SKILL.md +++ b/skills/lab-set-up/SKILL.md @@ -43,8 +43,14 @@ You set the lab up in one discussion with the operator, so that everything it se here first. 11. The site: the lab's `docs/` folder is a folio library whose charter lists `lab_kit.site` under `views:`. Set it up with folio's own skill if it is not there. - -12. Commit. Git is what holds the record: nothing is held before the first commit, and +12. If the lab will write papers, ask the operator which papers it aims at now, for whom and where (it is + direction, and may stay empty). Write the overview page (for example `entries/where-the-results-stand`) with folio's + write skill: the words on one running example, the workflow, the related work, and empty sections for the + findings and the criticisms. For each paper, write `entries/paper-`: its thesis, then the scope table + (target audience and venues, core thesis, experiments included, excluded or superseded, open), with the + last three cells marked `data-scope="included"`, `"excluded"` and `"open"`. Name them in `lab.toml` under + `[papers]` (`overview`, `active`). No card names a paper (method rule 8). +13. Commit. Git is what holds the record: nothing is held before the first commit, and `lab check --strict` says so. Done when `lab check --strict` passes and `lab now` shows each question as open. diff --git a/skills/lab-talk/SKILL.md b/skills/lab-talk/SKILL.md index 79932f1..e5ac42e 100644 --- a/skills/lab-talk/SKILL.md +++ b/skills/lab-talk/SKILL.md @@ -33,7 +33,9 @@ from the record, shortest first. A decision is a discussion, not a request for a comes up, give its definition from `lab define` in a few words. Never use a word in its everyday sense when it is also a lab term. Compare items in a table. - For "where are we": each goal in a line, each open question with what is known so far, what is - running, what is next, what there is to discuss. No more than a screen. + running, what is next, what there is to discuss. No more than a screen. When the lab names its papers, + lead with them: each active paper by its title, with what its open row still needs, then the steps + serving no paper. - `lab brief` is the question's page as text. Give it as it is, cut to what they asked. If what you want to say is not in it, the card is missing something: fix the card, then answer. - If the record does not say, say so. Never fill a gap from memory. @@ -64,6 +66,15 @@ that resource or that experiment under `about:` before it is decided: `lab new d --about `. What a locked decision is about cannot be changed afterwards, and a resource's new amount names the decision in `from`. +## Papers + +When the lab names its papers, they set the direction: the options you bring follow their open rows and +their reviewers' criticisms, and an order of work (`order:`) is built from the open rows, the paper the +operator cares about first. Adding, splitting, merging or retiring a paper is a decision like a question's: +`lab new decision ""`, with the paper named in Seen and Decided by its page's title. Then +change the pages and `[papers]` in `lab.toml` (the lab-work skill, The papers and the overview). A +retired paper's open work is parked or dropped in the same decision, or moved to another paper's open row. + ## When they decide something nobody raised `lab new decision "" --about `, fill **Seen** with what prompted it, then diff --git a/skills/lab-work/SKILL.md b/skills/lab-work/SKILL.md index 7c247b2..e92f14d 100644 --- a/skills/lab-work/SKILL.md +++ b/skills/lab-work/SKILL.md @@ -21,6 +21,11 @@ When a decision has set the order of the work, **Yours next** is already in that decision set it; follow it, and bring a change of order to the operator rather than skipping ahead. `lab show ` before you touch anything. +When the lab names its papers (`lab now` has a **Papers** section), read each active paper page's open row +and its criticisms before you choose what to propose: they say what the lab is for now. A step listed under +**Serving no active paper** is a candidate to park or drop, which you bring to the operator in a decision, +or it belongs on a paper's open row, which you add. + When `lab now` lists a current mission and you were started to run it, or the operator asks to save, launch or resume one, follow the lab-mission skill: it starts sessions on the steps, and each of them works as this skill says. @@ -96,6 +101,34 @@ the plan in fixed boxes, then the steps and the record. Write the card for that - **Options are named in words, never letters.** "Read `sll` apart", not "(a)". A decision's options are a list, each item opening with its name in bold. +## The papers and the overview + +When `lab.toml` names papers (`[papers]`), the library holds two kinds of page above the record (method +rule 8). The record itself never names a paper: no card, no title, no So far says "Paper A". + +- **The overview** (`overview`) keeps the whole trail, whatever paper it serves: the words on one running + example, the workflow, every related-work row, every established finding, every criticism and what answers + it, and what runs now. Nothing is left off it for being off a paper. +- **A paper page** (each of `active`) is that paper's technical argument, in its community's voice, and + never talks about the lab, its method or itself ("this page shows", "the lab's record"). It opens, under its + thesis, with the scope table: target audience and venues, core thesis, experiments included, experiments + excluded or superseded, open experiments. The last three cells carry `data-scope="included"`, + `"excluded"` and `"open"`, and list ids as links (`G1.Q1.4`). Then: its words + on one running example, its pipeline, the published work of its community compared, its established + results citing only included work, the criticisms its reviewers will raise (for each: what is true in + it, what the record shows, what remains to run), and last what remains to run. +- **A step or a question has one row on a page.** Where another row needs to mention it (excluded because + a newer run superseded it), name it in words, without its link. A decision may be cited anywhere. + +When a result lands: bring the overview's findings up to date, then each paper whose argument it touches. +If it supersedes an included run, move the old one to excluded and cite the new one. If it closes an open +row, move it to included, or to excluded if it is void or no longer serves the argument. A result's review +that fails makes the experiment void: take it off every included row. `lab check` refuses what a row may +not list, and notes a paper committed before a result about something it lists. + +Adding, splitting, merging or retiring a paper is direction: bring it to the operator (the lab-talk skill), +then change the pages and `[papers]`. A retired paper's page leaves `active` and stays in the library. + ## When to open a decision Open one when a question is answered or an experiment refutes what was expected, when a result @@ -109,7 +142,9 @@ parked question, and never take it up because it looks open: it is listed under 1. `lab new decision "" --about `. 2. On its card write **Seen** (what was observed, naming results), **Options** (a list of two or - three, each item an option with what it costs and what it changes) and **Recommendation**. Put under `holds:` only the + three, each item an option with what it costs and what it changes) and **Recommendation**. When the + lab names its papers, say which paper's open row or criticism each option serves, by the paper's exact + title; an option that serves none says so. Put under `holds:` only the experiments that should not start before it is settled. 3. Keep working on everything it does not hold. The lab-talk skill takes it to the operator and records what was decided. @@ -182,10 +217,13 @@ until that decision is settled; after that it needs no further yes. of typing its number: `{attack-success}`. It is shown the way its row says it reads. Bring the experiment's **So far** up to date, and rewrite the question's **So far** the same way, with full names: `{G1.Q1.2:attack-success}`. So far says what was learned, never where a step stands ("is running", "is next", "no result yet"): - the pages draw each step's state. `lab check` reports a question's So far that was last committed + the pages draw each step's state. It says what is known now, from the clean runs. When a newer + experiment fixes a harness bug or replaces an earlier setup, rewrite So far as the current finding; do + not retell the earlier bug, which the replaced experiment and its `because:` keep. `lab check` reports a question's So far that was last committed before a result under it, or one it names. Give each result a label that says what it counts and of how many, in a set of cases the lab names once ("of the 20 checks the solver leaves open"). 10. `lab log result "" ""`. +11. When the lab names its papers, revise them in the same sitting (next section). The outcome is worked out from the lines: you never write it. diff --git a/src/lab_kit/__init__.py b/src/lab_kit/__init__.py index dfa313b..2d5c844 100644 --- a/src/lab_kit/__init__.py +++ b/src/lab_kit/__init__.py @@ -1,2 +1,2 @@ """lab-kit: a research lab's record, its method, and the command that keeps both.""" -__version__ = "1.11.1" +__version__ = "1.12.0" diff --git a/src/lab_kit/checks.py b/src/lab_kit/checks.py index b057994..b10d338 100644 --- a/src/lab_kit/checks.py +++ b/src/lab_kit/checks.py @@ -3,7 +3,7 @@ import glob, os, re -from . import history, record as R, runs as runs_, write +from . import history, papers, record as R, runs as runs_, write KEYS = { # what a card's front matter may hold; a state is never among them "goal": {"title", "from", "reached", "dropped", "see"}, @@ -427,6 +427,9 @@ def see(where, page, who=""): for t in sorted({t for t in terms if terms.count(t) > 1}): bad("glossary", "GLOSSARY.md", f"{t!r} is defined twice") + # papers: each active paper's scope lists only what it may + papers.check(lab, bad, notes) + # clean: the plans and the store stay out of default searches ignore = R.read(f"{root}/.ignore") if os.path.exists(f"{root}/.ignore") else "" if "plan/" not in ignore or "runs/" not in ignore: diff --git a/src/lab_kit/papers.py b/src/lab_kit/papers.py new file mode 100644 index 0000000..27cdaee --- /dev/null +++ b/src/lab_kit/papers.py @@ -0,0 +1,228 @@ +"""Papers: the library's pages that argue for one target paper each, above a record that names no paper. + +A lab opts in with `[papers]` in `lab.toml`: `overview`, the page that keeps the whole trail, and `active`, the page +of each paper being written. Each paper page opens with a scope table whose cells are marked +`data-scope="included"`, `"excluded"` and `"open"`; the `/lab//` links inside a cell are what it lists. +`lab check` holds what a cell may list, and `lab now` says what each paper still has open and which live steps +serve no paper. +""" +from __future__ import annotations + +import os, re +from html.parser import HTMLParser + +from . import record as R + +ROWS = ("included", "excluded", "open") +LINK = re.compile(r"^/lab/(G\d+(?:\.Q\d+(?:\.\d+)?)?|D\d+)/?(?:[#?].*)?$") +LIVE = ("open", "waiting", "running") + + +class _Scope(HTMLParser): + """The page's title and, for each marked cell, the ids its links name, in order.""" + + def __init__(self): + super().__init__(convert_charrefs=True) + self.title, self.cells, self.marked, self.unknown = "", {r: [] for r in ROWS}, set(), [] + self._title, self._row, self._tag, self._depth, self._tables = False, None, None, 0, 0 + + def handle_starttag(self, tag, attrs): + a = dict(attrs) + if tag == "title": + self._title = True + if self._row and ("data-scope" in a or (self._depth == 1 and not self._tables and self._tag in ("td", "th") and tag in ("td", "th", "tr"))): + self._row = None # a cell whose closing tag is left out ends where the next cell or row begins + if self._row: + self._depth += tag == self._tag + self._tables += tag == "table" # a table inside the cell has rows and cells of its own + m = LINK.match(a.get("href") or "") if tag == "a" else None + if m and m.group(1) not in self.cells[self._row]: + self.cells[self._row].append(m.group(1)) + return + row = a.get("data-scope") + if row is None: + return + if row not in ROWS: + self.unknown.append(row) + return + self._row, self._tag, self._depth, self._tables = row, tag, 1, 0 + self.marked.add(row) + + def handle_endtag(self, tag): + if tag == "title": + self._title = False + if self._row and tag == "table" and self._tables: + self._tables -= 1 + if self._row and tag == self._tag: + self._depth -= 1 + if not self._depth: + self._row = None + + def handle_data(self, data): + if self._title: + self.title += data + + +def page_file(lab, path): + return os.path.join(lab.root, lab.cfg.get("library", "docs"), "content", path.strip("/"), "index.html") + + +def config(lab): + """(overview, active pages, problems). (None, [], []) when the lab keeps no papers.""" + p = lab.cfg.get("papers") + if p is None: + return None, [], [] + if not isinstance(p, dict): + return None, [], ["`[papers]` is a table that names `overview` and `active`"] + problems = [f"`[papers]` holds `{k}`; it names only `overview` and `active`" for k in sorted(set(p) - {"overview", "active"})] + overview, active = p.get("overview"), p.get("active", []) + if not isinstance(overview, str) or not overview.strip(): + problems.append("`[papers]` names its `overview`: the library page that keeps the whole trail, such as \"entries/where-the-results-stand\"") + overview = None + if not isinstance(active, list) or not all(isinstance(a, str) and a.strip() for a in active): + problems.append("`[papers]` lists its `active` paper pages as library paths, such as [\"entries/paper-a\"]") + active = [] + active = [a.strip("/") for a in active] + for path in ([overview] if overview else []) + active: + if ".." in path.split("/"): + problems.append(f"`[papers]` names {path}; a page is a path inside the library's content, without `..`") + for a in sorted({a for a in active if active.count(a) > 1}): + problems.append(f"`[papers]` lists {a} more than once") + return (overview.strip("/") if overview else None), list(dict.fromkeys(active)), problems + + +def read(lab): + """Each active paper page as read: path, title, its cells' ids, the rows it marks; `missing` when not there.""" + if getattr(lab, "_papers", None) is not None: + return lab._papers + _, active, _ = config(lab) + out = [] + for path in active: + f = page_file(lab, path) + if not os.path.exists(f): + out.append({"path": path, "title": path, "cells": {r: [] for r in ROWS}, "marked": set(), "unknown": [], "missing": True}) + continue + s = _Scope() + s.feed(R.read(f)) + out.append({"path": path, "title": " ".join(s.title.split()) or path, "cells": s.cells, "marked": s.marked, "unknown": s.unknown, "missing": False}) + lab._papers = out + return out + + +def _covered(lab, ident): + """The ids a cell's id stands for: itself, and every question and step under a goal or a question.""" + n = lab.nodes.get(ident) + if not n: + return {ident} + if n["type"] == "goal": + return {ident} | {q["id"] for q in n.get("questions", [])} | {x["id"] for q in n.get("questions", []) for x in q["items"]} + if n["type"] == "question": + return {ident} | {x["id"] for x in n["items"]} + return {ident} + + +def serving(lab): + """The live steps that no active paper lists under included or open, by themselves or by their question or goal.""" + named = set() + for p in read(lab): + for row in ("included", "open"): + for i in p["cells"][row]: + named |= _covered(lab, lab.folded.get(i, i)) + return [x for x in lab.items if x["state"] in LIVE and not {x["id"], x["question"], x.get("goal")} & named] + + +def _say(n): + return "void: its results review failed, so no page uses its numbers" if n.get("label") == "void" else n["state"] + + +def check(lab, bad, notes): + """What `lab check` holds about the papers: the table in `lab.toml`, each page's scope, and what each row lists.""" + overview, active, problems = config(lab) + for p in problems: + bad("papers", "lab.toml", p) + if overview is None and not active: + return + if overview and not os.path.exists(page_file(lab, overview)): + bad("papers", "lab.toml", f"`overview` names {overview}, which is not a page of the library") + if overview and overview in active: + bad("papers", "lab.toml", f"{overview} is the overview and an active paper: the overview keeps the whole trail, a paper only what it argues") + for p in read(lab): + where = lab.rel(page_file(lab, p["path"])) + if p["missing"]: + bad("papers", "lab.toml", f"`active` names {p['path']}, which is not a page of the library") + continue + for row in ROWS: + if row not in p["marked"]: + bad("papers", where, f"has no scope cell marked data-scope=\"{row}\": a paper page opens with its scope table, and each of included, excluded and open is a marked cell, empty if it lists nothing") + for row in p["unknown"]: + bad("papers", where, f"marks a cell data-scope=\"{row}\"; a scope cell is included, excluded or open") + rows = {row: [lab.folded.get(i, i) for i in p["cells"][row]] for row in ROWS} + for row, ids in rows.items(): + for i in ids: + n = lab.nodes.get(i) + if not n: + bad("papers", where, f"lists {i} under {row}, which is not a goal, a question, a step or a decision of the lab") + continue + if row == "included": + if n["type"] in R.STEPS and (n["state"] != "done" or n.get("label") == "void"): + to = "open" if n["state"] in LIVE else "excluded" + bad("papers", where, f"lists {i} under included, which is {_say(n)}: a paper includes only finished work that is not void, replaced or dropped; list it under {to}") + elif n["type"] in ("question", "goal") and n["state"] in ("parked", "dropped"): + bad("papers", where, f"lists {i} under included, which is {n['state']}: list it under excluded") + elif row == "open": + if n["type"] in R.STEPS and n["state"] not in LIVE: + to = "included or excluded" if n["state"] == "done" and n.get("label") != "void" else "excluded" + bad("papers", where, f"lists {i} under open, which is {_say(n)}: open holds only work still to do; list it under {to}") + elif n["type"] in ("question", "goal") and n["state"] in ("done", "parked", "dropped"): + bad("papers", where, f"lists {i} under open, which is {n['state']}: open holds only work still to do") + for a, b in (("included", "excluded"), ("included", "open"), ("open", "excluded")): + for i in sorted(i for i in set(rows[a]) & set(rows[b]) if lab.nodes.get(i, {}).get("type") != "decision"): # a decision may be cited wherever it explains a row + bad("papers", where, f"lists {i} under both {a} and {b}: a step or a question has one row; where another row needs it, name it in words, without its link") + for q, step, at in stale(lab): + notes.append(f"papers: {q} was last committed before the result of {step} ({at}): bring the paper's argument up to date with it") + + +def stale(lab): + """[(page, step, when)]: an active paper page last committed before the newest `result` line about a step it lists + under included or open, or under a question or goal it lists there. Nothing where git cannot tell.""" + from . import history + root, out = lab.root, [] + if not history.committed(root): + return out + for p in read(lab): + if p["missing"]: + continue + f = os.path.relpath(page_file(lab, p["path"]), root) + if (history.git(root, "status", "--porcelain", "--", f) or "").strip(): + continue # being brought up to date now + last = R.moment((history.git(root, "log", "-1", "--format=%cI", "--", f) or "").strip()) + if not last: + continue + mine = set() + for row in ("included", "open"): + for i in p["cells"][row]: + mine |= _covered(lab, lab.folded.get(i, i)) + newer = [l for l in lab.lines if l["kind"] == "result" and l["about"] in mine and l["time"] and (R.moment(l["at"]) or last) > last] + if newer: + out.append((p["path"], newer[-1]["about"], f"{newer[-1]['day']} {newer[-1]['time']}")) + return out + + +def now_lines(lab): + """The lines `lab now` gives the papers: each active paper with what it has open, then the steps no paper serves.""" + _, active, _ = config(lab) + if not active: + return [] + out = ["", "Papers (direction comes from their open rows and their criticisms)"] + for p in read(lab): + if p["missing"]: + out.append(f"- {p['path']}: not in the library") + continue + left = [lab.nodes[i] for i in (lab.folded.get(i, i) for i in p["cells"]["open"]) if i in lab.nodes and lab.nodes[i]["type"] != "decision"] + todo = ", ".join(f"{n['id']} {n['title']} ({n['state']})" for n in left) or "nothing" + out.append(f"- {p['title']} ({p['path']}): open {todo}") + idle = serving(lab) + if idle: + out += ["", "Serving no active paper (add to a paper's open row, or bring parking or dropping it to the operator)"] + out += [f"- {x['id']} {x['title']} ({x['state']})" for x in idle] + return out diff --git a/src/lab_kit/views.py b/src/lab_kit/views.py index 8fbf7ea..b863ad5 100644 --- a/src/lab_kit/views.py +++ b/src/lab_kit/views.py @@ -3,7 +3,7 @@ import os -from . import record as R +from . import papers, record as R def num(x): @@ -91,6 +91,7 @@ def _now(lab): key = x["label"] if x["state"] == "done" and x.get("label") else x["state"] counts[key] = counts.get(key, 0) + 1 out += [f"- {q['id']} ({state(q)}): {q['title']} [{', '.join(f'{n} {k}' for k, n in counts.items()) or 'nothing under it'}]"] + out += papers.now_lines(lab) aside = lab.set_aside() if any(aside.values()): out += ["", "Set aside"] + [f"- {q['id']} (parked by {lab.parked_by(q['id'])['id']}): {q['title']}" for q in aside["parked"]] diff --git a/tests/test_papers.py b/tests/test_papers.py new file mode 100644 index 0000000..8bee2c3 --- /dev/null +++ b/tests/test_papers.py @@ -0,0 +1,189 @@ +"""Papers drive the work: the record names no paper, and each active paper's page opens with a scope table whose +included, excluded and open cells `lab check` holds, and whose open row `lab now` puts before the agent.""" +import os + +from test_flow import experiment, lab, open_question, results +from test_integrity import WRITES, commit, done +from test_states import PAST, git_env + +PAGE = """ +{title} +
+

The error falls with the square root of the sample.

+
+ + + +
Experiments included{included}
Experiments excluded / superseded{excluded}
Open experiments{open}
+
+""" + + +def links(*ids): + return ", ".join(f'{i}' for i in ids) + + +def page(root, path, title="Paper A: The square-root law", included=(), excluded=(), open_=()): + d = os.path.join(root, "docs", "content", path) + os.makedirs(d, exist_ok=True) + open(f"{d}/index.html", "w").write(PAGE.format(title=title, included=links(*included), excluded=links(*excluded), open=links(*open_))) + + +def papers(root, overview="entries/where-the-results-stand", active=("entries/paper-a",)): + text = open(f"{root}/lab.toml").read().split("[papers]")[0] + open(f"{root}/lab.toml", "w").write(text + f'[papers]\noverview = "{overview}"\nactive = [{", ".join(chr(34) + a + chr(34) for a in active)}]\n') + + +def two_experiments(root): + """G1.Q1.1 done and confirmed, G1.Q1.2 done and void, G1.Q1.3 still open.""" + open_question(root) + first, d1, c1 = experiment(root, command=WRITES % "0.5") + lab(root, "lock", first) + lab(root, "run", first, "--wait", "--", *c1) + done(root, first, d1) + void, d2, c2 = experiment(root, title="Error at 100 and at 1600 flips", command=WRITES % "0.25") + lab(root, "lock", void) + lab(root, "run", void, "--wait", "--", *c2) + results(d2, "0.25") + lab(root, "review", void, "results", "fail", "The seed was fixed after a first look.") + later, _, _ = experiment(root, title="Error at 400 and at 1600 flips") + page(root, "entries/where-the-results-stand", title="Where the results stand") + return first, void, later + + +def test_a_lab_without_papers_is_unchanged(tmp_path): + root = str(tmp_path) + two_experiments(root) + assert "Papers" not in lab(root, "now") + assert "papers:" not in lab(root, "check", "--no-rederive") + + +def test_a_paper_includes_only_finished_work_and_lists_each_id_once(tmp_path): + root = str(tmp_path) + first, void, later = two_experiments(root) + papers(root) + page(root, "entries/paper-a", included=(first, void, later), excluded=(first,), open_=("G1.Q9.1",)) + out = lab(root, "check", "--no-rederive", ok=False) + assert f"lists {void} under included, which is void" in out and "list it under excluded" in out + assert f"lists {later} under included, which is open" in out and "list it under open" in out + assert f"lists {first} under both included and excluded" in out + assert "lists G1.Q9.1 under open, which is not a goal, a question, a step or a decision of the lab" in out + page(root, "entries/paper-a", included=(first,), excluded=(void,), open_=(first,)) + assert f"lists {first} under open, which is done" in lab(root, "check", "--no-rederive", ok=False) + page(root, "entries/paper-a", included=(first, "D1"), excluded=(void,), open_=(later,)) + assert "the record is sound" in lab(root, "check", "--no-rederive") + + +def test_the_papers_table_names_pages_that_are_there_each_with_its_scope(tmp_path): + root = str(tmp_path) + two_experiments(root) + papers(root, active=("entries/paper-a", "entries/paper-b", "entries/where-the-results-stand")) + os.makedirs(f"{root}/docs/content/entries/paper-a", exist_ok=True) + open(f"{root}/docs/content/entries/paper-a/index.html", "w").write("") + out = lab(root, "check", "--no-rederive", ok=False) + assert "`active` names entries/paper-b, which is not a page of the library" in out + assert "is the overview and an active paper" in out + assert 'has no scope cell marked data-scope="included"' in out and 'marks a cell data-scope="kept"' in out + papers(root, overview="entries/nowhere") + assert "`overview` names entries/nowhere, which is not a page of the library" in lab(root, "check", "--no-rederive", ok=False) + + +def test_a_card_never_names_a_paper(tmp_path): + root = str(tmp_path) + first, _, _ = two_experiments(root) + from test_flow import folder, front + front(f"{folder(root, first)}/experiment.md", paper="paper-a") + assert "`paper:` is not something a experiment card holds" in lab(root, "check", "--no-rederive", ok=False) + + +def test_now_puts_each_papers_open_row_first_and_names_what_serves_no_paper(tmp_path): + root = str(tmp_path) + first, void, later = two_experiments(root) + papers(root) + page(root, "entries/paper-a", included=(first,), excluded=(void,)) + now = lab(root, "now") + assert "Paper A: The square-root law (entries/paper-a): open nothing" in now + assert "Serving no active paper" in now and f"- {later} Error at 400 and at 1600 flips (open)" in now + page(root, "entries/paper-a", included=(first,), excluded=(void,), open_=(later,)) + now = lab(root, "now") + assert f"open {later} Error at 400 and at 1600 flips (open)" in now and "Serving no active paper" not in now + page(root, "entries/paper-a", included=(first,), excluded=(void,), open_=("G1.Q1",)) # a question stands for every step under it + assert "Serving no active paper" not in lab(root, "now") + + +def test_a_paper_older_than_a_result_it_lists_is_noted(tmp_path): + root = str(tmp_path) + first, void, later = two_experiments(root) + papers(root) + page(root, "entries/paper-a", included=(first,), excluded=(void,), open_=(later,)) + git_env(root, "init", "-q") + git_env(root, "add", "-A") + git_env(root, "commit", "-qm", "the paper", GIT_AUTHOR_DATE=PAST, GIT_COMMITTER_DATE=PAST) + lab(root, "log", first, "result", "The error halves.", "It converges as the theory says.") + commit(root, "the result") + out = lab(root, "check", "--no-rederive", ok=False) # the question's So far is stale too, which is a problem + assert f"note: papers: entries/paper-a was last committed before the result of {first}" in out + assert "papers:" not in out.split("note: papers:")[1].split("\n", 1)[1] # a note, never a problem + + +def test_every_rule_on_a_row_and_on_the_table_has_a_refusal(tmp_path): + root = str(tmp_path) + first, void, later = two_experiments(root) + papers(root) + from test_flow import folder, front + front(f"{folder(root, later)}/experiment.md", dropped="the first comparison answers the question") + lab(root, "answer", "G1.Q1", "yes", "It halves at 400 flips.") + page(root, "entries/paper-a", included=(first,), excluded=(void,), open_=("G1.Q1",)) + assert "lists G1.Q1 under open, which is done" in lab(root, "check", "--no-rederive", ok=False) + page(root, "entries/paper-a", included=("G1", first), excluded=(void,), open_=("G1",)) + assert "lists G1 under both included and open" in lab(root, "check", "--no-rederive", ok=False) + # a question written in one row and a step under it in another is allowed + page(root, "entries/paper-a", included=("G1.Q1",), excluded=(void, later), open_=()) + assert "papers:" not in lab(root, "check", "--no-rederive") + page(root, "entries/paper-a", included=(first,), excluded=("G1.Q1", void), open_=()) + assert "papers:" not in lab(root, "check", "--no-rederive") + for table, said in (('papers = "entries/paper-a"', "`[papers]` is a table"), + ('[papers]\noverview = "entries/where-the-results-stand"\nkept = 1', "`[papers]` holds `kept`"), + ('[papers]\noverview = 3', "`[papers]` names its `overview`"), + ('[papers]\noverview = "entries/where-the-results-stand"\nactive = "entries/paper-a"', "lists its `active` paper pages"), + ('[papers]\noverview = "entries/where-the-results-stand"\nactive = ["entries/paper-a", "entries/paper-a/"]', "lists entries/paper-a more than once"), + ('[papers]\noverview = "../outside"', "without `..`")): + text = open(f"{root}/lab.toml").read().split("[papers]")[0].split("papers =")[0] + open(f"{root}/lab.toml", "w").write(text + table + "\n") + assert said in lab(root, "check", "--no-rederive", ok=False), table + + +def test_a_parked_or_dropped_question_is_in_neither_included_nor_open(tmp_path): + root = str(tmp_path) + first, void, later = two_experiments(root) + from test_parked import park + card, d = park(root, "G1.Q1", "Set the first sizes aside", "") + lab(root, "decide", d, "--with", "Ada", "Set the first sizes aside until the sampler is fixed.") + papers(root) + page(root, "entries/paper-a", included=("G1.Q1",), excluded=(void,)) + assert "lists G1.Q1 under included, which is parked" in lab(root, "check", "--no-rederive", ok=False) + page(root, "entries/paper-a", excluded=(void,), open_=("G1.Q1",)) + assert "lists G1.Q1 under open, which is parked" in lab(root, "check", "--no-rederive", ok=False) + + +def test_a_cell_left_open_ends_where_the_next_cell_begins(tmp_path): + root = str(tmp_path) + first, void, later = two_experiments(root) + papers(root) + d = f"{root}/docs/content/entries/paper-a" + os.makedirs(d, exist_ok=True) + open(f"{d}/index.html", "w").write(f'Paper A
{links(first)}' + f'
{links(void)}
{links(later)}
') + assert "papers:" not in lab(root, "check", "--no-rederive") + assert f"open {later} Error at 400 and at 1600 flips (open)" in lab(root, "now") + + +def test_a_table_inside_a_scope_cell_is_read_as_part_of_it(tmp_path): + root = str(tmp_path) + first, void, later = two_experiments(root) + papers(root) + d = f"{root}/docs/content/entries/paper-a" + os.makedirs(d, exist_ok=True) + open(f"{d}/index.html", "w").write(f'' + f'
{links(first, void)}
{links(later)}
') + assert f"lists {void} under included, which is void" in lab(root, "check", "--no-rederive", ok=False)