diff --git a/docs/developer/README.md b/docs/developer/README.md index ef89f6b0..cd406503 100644 --- a/docs/developer/README.md +++ b/docs/developer/README.md @@ -301,11 +301,11 @@ def transmission_runs(files: Sequence[FileInfo]) -> pd.DataFrame: for f in files if f.metadata.get('role') == 'transmission'] return pd.DataFrame.from_records(rows, columns=['key', 'run']).set_index('key') -manager = BatchManager(client, definitions=FolderDefinitions(folder), - sources={'transmission-runs': Source(transmission_runs, fills=('run',))}) -manager.create('transmission', title='Transmissions', source='transmission-runs', - follow=True) -manager.step() # called by a timer of the application +manager = BatchManager(client, definitions=FolderDefinitions(folder)) +intake = Intake(manager, sources={'transmission-runs': RowSource(transmission_runs, fills=('run',))}) +intake.create('transmission', title='Transmissions', source='transmission-runs', + follow=True) +intake.step() # called by a timer of the application ``` A step never changes a row that the table has. The results are read from the records under the label, so a restarted application reduces no row that has a result. A record under the label with a row's key as member, from any batch, is that row's result. diff --git a/docs/developer/adr/0011-a-person-makes-the-batches-of-a-workspace.md b/docs/developer/adr/0011-a-person-makes-the-batches-of-a-workspace.md index 3f37682d..378abf30 100644 --- a/docs/developer/adr/0011-a-person-makes-the-batches-of-a-workspace.md +++ b/docs/developer/adr/0011-a-person-makes-the-batches-of-a-workspace.md @@ -39,9 +39,9 @@ Problem 3 is not decided (see "Not decided"). ### The manager ```python -manager = BatchManager(client, sources={'sample-runs': SAMPLE_RUNS}, - definitions=FolderDefinitions(folder)) -label = manager.create('loki-iofq', title='Afternoon', source='sample-runs') +manager = BatchManager(client, definitions=FolderDefinitions(folder)) +intake = Intake(manager, sources={'sample-runs': SAMPLE_RUNS}) +label = intake.create('loki-iofq', title='Afternoon', source='sample-runs').label manager.headers() # {label: Header(title, description)}, sorted by label manager.batch(label) # the Batch: frame(), put(), state(), reduce(), cancel(), settings manager.change(label, title='Afternoon, 2 mm cells') @@ -58,7 +58,7 @@ What the application gives once, and what a person chooses for each batch: | Part | Given by | |---|---| | spec | a person, from the specs that the workspace binds (`client.specs()`); the name is kept, the version is the one bound, the highest if several are ([ADR 0009](0009-a-record-of-another-spec-stays-readable.md)) | -| source | a person, from the sources that the application registers by name (`BatchManager(sources=...)`), or none | +| source | a person, from the sources that the application registers by name (`Intake(sources=...)`), or none | | title, description | a person | | label | the manager | | first settings, `staged` | the application, for each spec (`BatchManager(settings=..., staged=...)`) | @@ -78,8 +78,7 @@ So the records of a removed batch never show as results of another batch. ``` definitions/labels/20261118-130204/header.json {"title": "Afternoon, 2 mm cells", "description": "..."} -definitions/labels/20261118-130204/... the settings and the table (ADR 0012), the source (ADR 0013) -definitions/following.json {"label": "20261118-130204"}, or {"label": null} +definitions/labels/20261118-130204/... the settings and the table (ADR 0012), the source and whether the batch follows (ADR 0013) definitions/corrections.json metadata of runs set by hand ``` @@ -92,18 +91,18 @@ Nothing checks that the batches cover every row or that they do not overlap. ### One batch follows -The manager keeps the label of the batch that follows, or none: +`Intake` keeps which batch follows, if any: ```python -manager.create(..., source='sample-runs', follow=True) # this batch follows, and no other -manager.following # its label, or None -manager.stop() # none follows -manager.step() # one step of Follow on it (ADR 0013) +intake.create(..., source='sample-runs', follow=True) # this batch follows, and no other +intake.following # its label, or None +intake.stop() # none follows +intake.step() # one step of Follow on it (ADR 0013) ``` -- One value means that at most one batch follows, with no rule to enforce. Making a batch that follows stops the batch that followed before. -- The manager keeps the value in the definitions, apart from any batch, so a restart resumes. Removing the batch that follows ends Follow. -- Whoever serves the pages owns the timer that calls `step`. The manager has no thread, no timer and no lock. +- Making a batch that follows stops the batch that followed before, first, so at most one batch follows. +- `Intake` keeps it in the definitions of the batch (`"follows"` in its `source.json`), so a restart resumes, and removing the batch that follows ends Follow, also for a batch made again with the label. +- Whoever serves the pages owns the timer that calls `step`. `Intake` has no thread, no timer and no lock. - The workspace has one lock: every request of every page and each step take it, so the batches, the manager and the corrections change in one request at a time. ### A page shows one batch, named in its URL diff --git a/docs/developer/adr/0012-a-batch-is-a-table.md b/docs/developer/adr/0012-a-batch-is-a-table.md index 50d93013..6a76a264 100644 --- a/docs/developer/adr/0012-a-batch-is-a-table.md +++ b/docs/developer/adr/0012-a-batch-is-a-table.md @@ -271,7 +271,7 @@ The code of this ADR and of ADR 0013 is written together, since Follow is in use - An empty cell depends on the settings, outside the table. The page shows it in grey as the value that the row takes. - A table file shows an empty cell where a row takes the setting, so it needs the settings file to say what a row was reduced with. - A cell emptied after its row was reduced counts its value as a setting: the row reads `earlier`, not `outdated`. -- A batch made from a source keeps the names that its source fills with it, in `source.json`, as they were when it was made; the batch, the command without the sources, and Follow read them there. A step asks the batch which names a row waits for. +- A batch made from a source keeps the names that its source fills with it, as the blanks of `settings.json`, as they were when it was made; the batch, the command without the sources, and Follow read them there. A step asks the batch which names a row waits for. - The table of a batch made from a source keeps a column for each name that its source fills: `put`, a table file loaded, and "Make this a setting" refuse to drop one. - `settings.json` holds every setting, those at the columns too, as a template without blanks. A file whose template has blanks, as one written before, reads the same: its blanks are not read, and it has no settings at the columns. - A row that only wrong metadata made stays until a person removes it, and a correction of a run changes no batch (the example above). diff --git a/docs/developer/adr/0013-follow-adds-the-rows-not-considered.md b/docs/developer/adr/0013-follow-adds-the-rows-not-considered.md index 14d53244..abadc934 100644 --- a/docs/developer/adr/0013-follow-adds-the-rows-not-considered.md +++ b/docs/developer/adr/0013-follow-adds-the-rows-not-considered.md @@ -42,8 +42,7 @@ def step(batch, source, considered): ### What is kept ``` -definitions/labels/20261118-130204/source.json {"source": "sample-runs", "considered": ["60337", "60338", "60339"]} -definitions/following.json the label of the batch that follows, or none (ADR 0011) +definitions/labels/20261118-130204/source.json {"source": "sample-runs", "considered": ["60337", "60338", "60339"], "follows": true} ``` - A key is *considered* by a batch once a row of that key was put into the batch from the source, or was filled and left out when the batch was made. @@ -72,7 +71,7 @@ What removes a bad run from the later rows is a correction of the run, which the ### A row waits until the source has filled it -A source says which columns it fills (`Source.fills`, such as `sample` and `sample_transmission`). A row is added once it has a value in each of these that is a column of the batch. Until then it is *waiting*: the source gives it again at every step, and the page says how many rows wait. +A source says which columns it fills (`RowSource.fills`, such as `sample` and `sample_transmission`). A row is added once it has a value in each of these that is a column of the batch. Until then it is *waiting*: the source gives it again at every step, and the page says how many rows wait. - A sample run measured before its transmission run is added when the transmission run is listed. - A row is added whatever its other columns hold. A column that the source does not fill is empty in a new row, and the row is incomplete if the template needs it. @@ -84,8 +83,8 @@ A source says which columns it fills (`Source.fills`, such as `sample` and `samp `create` lists the source once, and a person chooses the table of the batch from the rows that are filled: ```python -manager.create('loki-iofq', title='Afternoon', source='sample-runs', - choose=Range(first='60339'), columns=['thickness'], follow=True) +intake.create('loki-iofq', title='Afternoon', source='sample-runs', + choose=Range(first='60339'), columns=['thickness'], follow=True) # in create: given = rows_of(client, source) # one listing @@ -116,10 +115,10 @@ The rule is on the state of the rows, as in ADR 0011. So in a batch that follows No row moves from one batch to another. A person who wants the runs from 60400 on in a batch of their own makes it with Follow: ```python -label = manager.create('loki-iofq', title='Evening', source='sample-runs', - choose=Range(first='60400'), - settings=manager.batch('afternoon').settings, - follow=True) # the batch 'afternoon' stops following +intake.create('loki-iofq', title='Evening', source='sample-runs', + choose=Range(first='60400'), + settings=manager.batch('afternoon').settings, + follow=True) # the batch 'afternoon' stops following ``` The earlier batch keeps its rows, also those from 60400 on, until a person removes them. It has considered the keys it has seen, and takes no row that arrives later, since it cannot follow again. @@ -127,8 +126,8 @@ The earlier batch keeps its rows, also those from 60400 on, until a person remov A batch of only the rows that arrive later takes no row at making. Every row filled then is considered, so no row is reduced again: ```python -manager.create('loki-iofq', title='Night', source='sample-runs', - choose=Range(later=True), follow=True) +intake.create('loki-iofq', title='Night', source='sample-runs', + choose=Range(later=True), follow=True) ``` ### A batch follows from the time it is made, until it is stopped @@ -136,15 +135,15 @@ manager.create('loki-iofq', title='Night', source='sample-runs', Follow is chosen when a batch is made. A batch that follows can be stopped. A batch that does not follow cannot be made to follow. ```python -manager.create(..., source='sample-runs', follow=True) # follows; the batch that followed before stops -manager.following # its label -manager.stop() # none follows; that batch cannot follow again +intake.create(..., source='sample-runs', follow=True) # follows; the batch that followed before stops +intake.following # its label +intake.stop() # none follows; that batch cannot follow again ``` -- At most one batch follows, as in ADR 0011: the manager keeps its label in `following.json`, a restart resumes, and removing that batch ends Follow. Since `considered` is kept, the first step after a restart adds the rows that arrived in between. -- A batch made without a source cannot follow; `create` refuses `follow=True` without a source. -- A batch that follows has no last row. With one, the rows filled between the last row chosen and the making would be considered and never added, and the rows that arrive later would be. The range that a person picks is a value, `Range(first, last, later)`, which the manager reads: `create(follow=True)` with a `Range` that has a `last` is refused there. The page leaves the end of the range open while Follow is ticked, to say so before a person sends the form; the command does not follow. A `choose` that is a function may pick any rows, also with Follow: the rows were chosen in code, and the filled rows that it leaves out are considered, so Follow adds only the rows that arrive later. -- Nothing is kept that says a batch has followed. A batch is stopped when another label, or none, is in `following.json`, and no call writes its label there again. +- At most one batch follows, as in ADR 0011: `Intake` keeps whether a batch follows in its `source.json`, a restart resumes, and removing that batch ends Follow. Since `considered` is kept, the first step after a restart adds the rows that arrived in between. +- A batch made without a source cannot follow: only `intake.create`, which takes a source, takes `follow=True`. +- A batch that follows has no last row. With one, the rows filled between the last row chosen and the making would be considered and never added, and the rows that arrive later would be. The range that a person picks is a value, `Range(first, last, later)`, which `Intake` reads: `create(follow=True)` with a `Range` that has a `last` is refused there. The page leaves the end of the range open while Follow is ticked, to say so before a person sends the form; the command does not follow. A `choose` that is a function may pick any rows, also with Follow: the rows were chosen in code, and the filled rows that it leaves out are considered, so Follow adds only the rows that arrive later. +- Nothing is kept that says a batch has followed. A batch is stopped when its `source.json` says that it does not follow, and no call writes that it follows again. - So the next batch is one form, "New batch" with Follow, and a step never takes a row that another batch took since. - On the page, Follow is a state with one action, "Stop following", not a switch. @@ -175,7 +174,7 @@ A batch made from `sample-runs` with the rows from run 60339 on, with Follow. ## Consequences -- `Scope`, `Row.index`, `Source.index_type`, `Source.index_title`, `Header.scope`, `Header.source` and `manager.change(scope=...)` go. `Source.fills` stays, with a second use: it says when a row is filled. +- `Scope`, `Row.index`, `Source.index_type`, `Source.index_title`, `Header.scope`, `Header.source` and `manager.change(scope=...)` go. `RowSource.fills` stays, with a second use: it says when a row is filled. - The rule of a step is "ready and without a record". `RowState.changed_by_hand`, the columns `at` of `Automatic`, and the exception for cells set by hand go. - A row that only waits is not in the table. The page says how many rows wait, and a person can add them. - A transmission run measured again reaches no earlier row, and a correction of a run changes no row that the table has. diff --git a/docs/developer/tours/layers.html b/docs/developer/tours/layers.html index 0e03cfef..e58381d0 100644 --- a/docs/developer/tours/layers.html +++ b/docs/developer/tours/layers.html @@ -180,12 +180,12 @@

essapps, layer by layer

runs.setdefault(f.metadata['sample'], []).append(str(f.ref)) return pd.DataFrame({'runs': runs.values()}, index=list(runs)) -source = Source(angles, fills=('runs',), selector=Selector(role='sample')) -manager = BatchManager(client, sources={'angles': source}, - definitions=FolderDefinitions(folder)) -manager.create('stitch', title='reflectivity', source='angles', follow=True, - settings={'reference': file(run=500)}) -manager.step() # called every few seconds` }, +source = RowSource(angles, fills=('runs',), selector=Selector(role='sample')) +intake = Intake(BatchManager(client, definitions=FolderDefinitions(folder)), + sources={'angles': source}) +intake.create('stitch', title='reflectivity', source='angles', follow=True, + settings={'reference': file(run=500)}) +intake.step() # called every few seconds` }, { level: 11, caller: 'all', placement: 'service', planned: SERVICE, title: 'Many controllers, one history', body: `

All clients of a proposal share its history. A notebook can reference a transmission that the automatic reduction computed, and the app lists that record in its pickers.

Every client of a workspace reads the same values. The automatic reduction persists its outputs, so they outlive the workspace. A proposal has one workspace. Whether its users share the values in memory, or the service separates or bounds them per user, is open. Provenance follows each reference back to the files.

`, @@ -290,7 +290,7 @@

essapps, layer by layer

const CALLER_SMALL = [ h('Jupyter notebook', '', '
client.submit(IOFQ, ...)
'), h('Panel app', '', '
App(client)
'), - h('Automatic reduction', '', '
manager.step()
'), + h('Automatic reduction', '', '
intake.step()
'), ]; function layout(cfg, { box, arrow }) { @@ -405,8 +405,8 @@

essapps, layer by layer

caller: { notebook: `record = client.submit(SPEC, params={...})\nclient.output(record, ...)`, app: 'app = App(client)', - trigger: 'manager.step() # every few seconds', - all: '# each in its own process, with its own client\nclient.submit(SPEC, params={...})\nApp(client)\nmanager.step() # every few seconds', + trigger: 'intake.step() # every few seconds', + all: '# each in its own process, with its own client\nclient.submit(SPEC, params={...})\nApp(client)\nintake.step() # every few seconds', }, }; diff --git a/docs/developer/user-stories.md b/docs/developer/user-stories.md index a0e5e6bf..fcfa6bb2 100644 --- a/docs/developer/user-stories.md +++ b/docs/developer/user-stories.md @@ -112,7 +112,7 @@ Automatic reduction belongs to its sub-design ([automatic-reduction.md](automati The stories use these calls: ```python -source = Source(rows_of_files, fills=(...)) # rows_of_files: the files -> a DataFrame of rows +source = RowSource(rows_of_files, fills=(...)) # rows_of_files: the files -> a DataFrame of rows batch = Batch(client, SPEC, label=..., rows=rows_of(client, source), persist=True) done = step(batch, source, considered) # reads batch.settings at each step done.records # the step added the new rows of the source, and reduced the ready rows without a result; their records by key @@ -648,7 +648,7 @@ def per_run(files): # every raw file return pd.DataFrame({'sample': [f.ref.file for f in files]}, index=[str(f.metadata['run']) for f in files]) -PER_RUN = Source(per_run, fills=('sample',)) +PER_RUN = RowSource(per_run, fills=('sample',)) def iofq_batch(client): return Batch(client, IOFQ, label='iofq', rows=rows_of(client, PER_RUN), @@ -674,7 +674,7 @@ def angles(files): # a row per sampl return pd.DataFrame({'sample': list(runs), 'runs': [[f.ref.file for f in found] for found in runs.values()]}, index=keys) -source = Source(angles, fills=('runs',)) +source = RowSource(angles, fills=('runs',)) batch = Batch(client, STITCH, label='reflectivity', rows=rows_of(client, source), persist=True, settings={'reference': reference}) counts = {2: [1.0, 2.0], 3: [1.0, 1.0], 4: [4.0, 8.0]} diff --git a/packages/essapps/docs/batch.md b/packages/essapps/docs/batch.md index fa3c55da..0289410f 100644 --- a/packages/essapps/docs/batch.md +++ b/packages/essapps/docs/batch.md @@ -19,21 +19,26 @@ flowchart TD notebook["notebook, test"] end subgraph layer ["batch layer"] + intake["Intake"] manager["manager: BatchManager"] subgraph batch ["Batch"] settings table["batch table"] end step["step: auto.step"] - source["source: Source"] + source["source: RowSource"] end definitions["definitions"] client["Client: files, records"] callers --> batch callers --> manager + callers --> intake + intake --> manager + intake --> step + intake --> source + intake --> batch + intake --> definitions manager --> batch - manager --> step - manager --> source manager --> definitions step --> batch step --> source @@ -49,11 +54,12 @@ Nothing in the batch layer imports the page or the command. | Component | Code | Owns | |---|---|---| | table | `table.py` | the form of a batch table: dtypes, cells, cell to request value and back, `rows.json`, table files | -| source | `source.py`: `Source`, `rows_of` | the code of the application that makes rows from the files | +| row source | `source.py`: `RowSource`, `rows_of` | the code of the application that makes rows from the files | | batch | `reduction.py`: `Batch` | the settings and the batch table of one label: `put`, `state`, `reduce`, `cancel`, and `version`, which moves when the batch table, the settings or a record changes; the only part that submits to the client | | state | `state.py`: `RowState`, the rules | where each row stands; the rules are functions from the states of rows to keys | | step | `auto.py`: `step`, `Step` | one step of Follow on one batch: add rows of the source, reduce rows | -| manager | `manager.py`: `BatchManager` | the batches of a workspace: make, list, change, remove; which batch follows; `considered` | +| manager | `manager.py`: `BatchManager` | the batches of a workspace: make one from a table, list, change, remove; it knows no row source | +| `Intake` | `intake.py`: `Intake` | rows of a row source into a batch: make a batch from a source, offer and take its rows; which batch follows, and its step; `considered` | | definitions | `definition.py`: `DefinitionStore`, `FolderDefinitions` | what a workspace keeps besides files and records (table below) | ### Terms @@ -62,7 +68,9 @@ Nothing in the batch layer imports the page or the command. |---|---| | workspace | a `Client` (specs bound, files, records) and the definitions; one folder | | batch | one spec reduced for many samples: a header (title, description), a spec, settings and a batch table | -| label | the name of a batch outside the process: its folder in the definitions, the label of its records, its address on the page and for the command. `manager.batch(label)` gives the `Batch`, the object that changes and reduces it | +| label | the name of a batch, unique in a workspace: its folder in the definitions, the label of its records, its address on the page and for the command; `batch.label` | +| `Batch` | the object that holds the settings and the batch table of one label, and changes and reduces them | +| `Intake` | the object that holds the manager and the row sources, by name, and brings rows of a source into a batch; it keeps which batch follows | | setting | the value of a parameter for the batch: an entry of `batch.settings` | | batch table | the rows of a batch, one per reduction: one `pandas.DataFrame` (below) | | value of a parameter for a row | what the row is reduced with at that parameter (rule 2) | @@ -71,11 +79,14 @@ Nothing in the batch layer imports the page or the command. | state of a row | its result, the status of the result, its problems, and where its request differs from that of its result | | outdated | a result whose request differs from the row's request now, or that is of another spec | | earlier | a completed result whose request differs from the row's only at settings: at parameters that have no column, or where the row's cell is empty | -| source | code of the application that makes rows from the files (a `Source`) | -| filled, waits | a row of the source is filled once it has a value in each of `Source.fills`; until then it waits | +| row source | code of the application that makes rows from the files (a `RowSource`) | +| filled, waits | a row of the source is filled once it has a value in each of `RowSource.fills`; until then it waits | | considered | the keys of the source that a batch made from it has taken or left out | | Follow | a step every few seconds on one batch: add the rows of its source that are filled and not considered, then reduce the rows that are ready and have no result; chosen when the batch is made, until it is stopped | +`manager.create` and `intake.create` return the `Batch`, and `manager.batch(label)` gives it again. +Every other method that names a batch takes its label. + The batch table of the example below, as `batch.frame()` gives it: ```python @@ -88,7 +99,7 @@ The batch table of the example below, as `batch.frame()` gives it: | Part | What it is | |---|---| | the index, `key` | text that names the row, unique in the batch table; the member of the row's records | -| a parameter column | a column named as a parameter of the spec (`sample`, `sample_transmission`, `thickness`), with the dtype of that parameter: there a row may give its own value. `batch.columns` names them | +| a parameter column | a column named as a parameter of the spec (`sample`, `sample_transmission`, `thickness`), with the dtype of that parameter: there a row may give its own value. `batch.parameter_columns` names them | | a note column | any other column (`run`, `name`); shown, never part of a request | | a cell | plain data, such as `'run:60339'`, `2.0`, `['run:1', 'run:2']`, or empty | @@ -126,61 +137,70 @@ Other tables are always named with what they are of: 3. **The state is computed, never kept.** It is read from the records each time. Each rule (`ready`, `not_reduced`, `left_to_reduce`, `earlier_settings`, `to_reduce`) is a function from the states to keys. 4. **A step never changes a row that the batch table has.** It adds rows, and reduces rows that have no result. 5. **A batch is shown without its source and without the files.** A file that is not found is a problem of its row. -6. **The rules are in the batch layer.** A refusal is a `ValueError`. The page and the command show it and copy no rule. The batch layer has no lock and no timer. -7. **Follow is chosen when a batch is made.** A batch follows from `create(..., follow=True)` until `stop()`, its removal, or the making of another batch that follows. A batch that does not follow cannot be made to follow. +6. **The rules are in the batch layer.** A refusal is a `ValueError`. The page and the command show it and copy no rule of the batch layer. The page refuses only a request that no call of the batch layer can express, such as Follow without a row source. The batch layer has no lock and no timer. +7. **Follow is chosen when a batch is made.** A batch follows from `intake.create(..., follow=True)` until `intake.stop()`, its removal, or the making of another batch that follows. A batch that does not follow cannot be made to follow. ### What is kept on disk | File | Content | Writer | |---|---|---| | `definitions/labels/