labnotes 0.0.11__tar.gz → 0.0.13__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {labnotes-0.0.11 → labnotes-0.0.13}/.gitignore +2 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/PKG-INFO +18 -17
- {labnotes-0.0.11 → labnotes-0.0.13}/README.md +17 -16
- labnotes-0.0.13/src/labnotes/cli.py +38 -0
- labnotes-0.0.13/src/labnotes/context.md +18 -0
- labnotes-0.0.13/src/labnotes/context_guide.py +22 -0
- labnotes-0.0.13/src/labnotes/load_config.py +14 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/models.py +8 -0
- labnotes-0.0.13/src/labnotes/read_config.py +23 -0
- labnotes-0.0.11/src/labnotes/cli.py → labnotes-0.0.13/src/labnotes/server.py +12 -41
- labnotes-0.0.11/src/labnotes/context.md +0 -27
- labnotes-0.0.11/src/labnotes/context_guide.py +0 -7
- labnotes-0.0.11/src/labnotes/dump_experiments.py +0 -15
- labnotes-0.0.11/src/labnotes/query_experiment.py +0 -24
- labnotes-0.0.11/src/labnotes/scope_runs.py +0 -14
- {labnotes-0.0.11 → labnotes-0.0.13}/CHANGELOG.md +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/MIGRATIONS.md +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/pyproject.toml +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/__init__.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/asset_url.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/cell_progress.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/count_runs.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/create_app.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/data_html.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/drain_watch.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/format_value.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/list_experiments.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/list_runs.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/load_experiment.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/notebook_kernel.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/open_experiments.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/open_runs.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/output_html.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/parse_run_view.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/pivot_cells.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/python_blocks.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/read_design.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/read_note.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/render_markdown.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/run_columns.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/saved_outputs.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/serve_app.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/sort_href.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/sql_quote.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/static/labnotes.css +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/static/row-link.js +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/static/run-cell.js +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/static/view-toggle.js +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/stop_idle_kernels.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/study_progress.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/summarize_design.py +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/templates/base.html +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/templates/experiment.html +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/templates/index.html +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/src/labnotes/templates/macros.html +0 -0
- {labnotes-0.0.11 → labnotes-0.0.13}/uv.lock +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: labnotes
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.13
|
|
4
4
|
Summary: Browse experiment designs, notes, and run data from a folder.
|
|
5
5
|
Project-URL: Repository, https://github.com/thekevinscott/labnotes
|
|
6
6
|
Author-email: Kevin Scott <me@thekevinscott.com>
|
|
@@ -22,12 +22,23 @@ Description-Content-Type: text/markdown
|
|
|
22
22
|
Browse experiment designs, notes, and run data from a folder.
|
|
23
23
|
|
|
24
24
|
```sh
|
|
25
|
-
uvx labnotes
|
|
25
|
+
uvx labnotes server
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
labnotes reads two folders, named in a `.labnotes.toml` at the project root:
|
|
29
|
+
|
|
30
|
+
```toml
|
|
31
|
+
experiments = "experiments"
|
|
32
|
+
data = "data"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Both keys are optional and default to the values above. Paths are relative to
|
|
36
|
+
`.labnotes.toml`, or absolute, or start with `~`. labnotes reads the file from
|
|
37
|
+
the working folder, or from the path given with `-c`.
|
|
38
|
+
|
|
39
|
+
- `experiments` holds one subfolder per experiment, each with a
|
|
29
40
|
`design.yaml` (with a `study` key) and any number of markdown notes.
|
|
30
|
-
-
|
|
41
|
+
- `data` holds the run data and a `.dirsql.toml` that declares a
|
|
31
42
|
`runs` table with a `study` column. An experiment's runs are the rows whose
|
|
32
43
|
`study` matches its design's.
|
|
33
44
|
|
|
@@ -43,19 +54,9 @@ of values), `runs_per_cell`, and `completed_run`, a SQL condition over the
|
|
|
43
54
|
`-h`/`--host` and `-p`/`--port` change where it listens; `-h 0.0.0.0` (or a
|
|
44
55
|
Tailscale IP) serves beyond localhost. Every other uvicorn option passes
|
|
45
56
|
through: `--reload`, `--workers`, `--proxy-headers`, `--root-path`, the
|
|
46
|
-
`--ssl-*` set, and the rest. `labnotes --help` lists them.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
## From the command line
|
|
51
|
-
|
|
52
|
-
Name an experiment to print what has run for it as JSON. Add SQL to query
|
|
53
|
-
that experiment's runs: `runs` holds only its runs, `main.runs` every run.
|
|
54
|
-
|
|
55
|
-
```sh
|
|
56
|
-
uvx labnotes models-effort "SELECT model, COUNT(*) AS n FROM runs GROUP BY 1" \
|
|
57
|
-
--experiments-folder experiments --data-folder data
|
|
58
|
-
```
|
|
57
|
+
`--ssl-*` set, and the rest. `labnotes server --help` lists them. `--experiments-folder`
|
|
58
|
+
and `--data-folder`, or `LABNOTES_EXPERIMENTS_FOLDER` and
|
|
59
|
+
`LABNOTES_DATA_FOLDER`, override `.labnotes.toml`.
|
|
59
60
|
|
|
60
61
|
## Agent skill
|
|
61
62
|
|
|
@@ -3,12 +3,23 @@
|
|
|
3
3
|
Browse experiment designs, notes, and run data from a folder.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
uvx labnotes
|
|
6
|
+
uvx labnotes server
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
labnotes reads two folders, named in a `.labnotes.toml` at the project root:
|
|
10
|
+
|
|
11
|
+
```toml
|
|
12
|
+
experiments = "experiments"
|
|
13
|
+
data = "data"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Both keys are optional and default to the values above. Paths are relative to
|
|
17
|
+
`.labnotes.toml`, or absolute, or start with `~`. labnotes reads the file from
|
|
18
|
+
the working folder, or from the path given with `-c`.
|
|
19
|
+
|
|
20
|
+
- `experiments` holds one subfolder per experiment, each with a
|
|
10
21
|
`design.yaml` (with a `study` key) and any number of markdown notes.
|
|
11
|
-
-
|
|
22
|
+
- `data` holds the run data and a `.dirsql.toml` that declares a
|
|
12
23
|
`runs` table with a `study` column. An experiment's runs are the rows whose
|
|
13
24
|
`study` matches its design's.
|
|
14
25
|
|
|
@@ -24,19 +35,9 @@ of values), `runs_per_cell`, and `completed_run`, a SQL condition over the
|
|
|
24
35
|
`-h`/`--host` and `-p`/`--port` change where it listens; `-h 0.0.0.0` (or a
|
|
25
36
|
Tailscale IP) serves beyond localhost. Every other uvicorn option passes
|
|
26
37
|
through: `--reload`, `--workers`, `--proxy-headers`, `--root-path`, the
|
|
27
|
-
`--ssl-*` set, and the rest. `labnotes --help` lists them.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
## From the command line
|
|
32
|
-
|
|
33
|
-
Name an experiment to print what has run for it as JSON. Add SQL to query
|
|
34
|
-
that experiment's runs: `runs` holds only its runs, `main.runs` every run.
|
|
35
|
-
|
|
36
|
-
```sh
|
|
37
|
-
uvx labnotes models-effort "SELECT model, COUNT(*) AS n FROM runs GROUP BY 1" \
|
|
38
|
-
--experiments-folder experiments --data-folder data
|
|
39
|
-
```
|
|
38
|
+
`--ssl-*` set, and the rest. `labnotes server --help` lists them. `--experiments-folder`
|
|
39
|
+
and `--data-folder`, or `LABNOTES_EXPERIMENTS_FOLDER` and
|
|
40
|
+
`LABNOTES_DATA_FOLDER`, override `.labnotes.toml`.
|
|
40
41
|
|
|
41
42
|
## Agent skill
|
|
42
43
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
|
|
5
|
+
from labnotes.context_guide import context_guide
|
|
6
|
+
from labnotes.load_config import load_config
|
|
7
|
+
from labnotes.read_config import CONFIG_FILE
|
|
8
|
+
from labnotes.server import server
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@click.group(
|
|
12
|
+
invoke_without_command=True,
|
|
13
|
+
help="Manage experiments in a folder. `labnotes context` prints a guide for"
|
|
14
|
+
" coding agents.",
|
|
15
|
+
)
|
|
16
|
+
@click.version_option(package_name="labnotes")
|
|
17
|
+
@click.option(
|
|
18
|
+
"-c",
|
|
19
|
+
"--config",
|
|
20
|
+
"config_path",
|
|
21
|
+
type=click.Path(path_type=Path, dir_okay=False, exists=True),
|
|
22
|
+
help=f"Project config. Default: {CONFIG_FILE} in the working folder, if there.",
|
|
23
|
+
)
|
|
24
|
+
@click.pass_context
|
|
25
|
+
def main(ctx: click.Context, config_path: Path | None) -> None:
|
|
26
|
+
if ctx.invoked_subcommand is None:
|
|
27
|
+
click.echo(ctx.get_help())
|
|
28
|
+
ctx.exit()
|
|
29
|
+
ctx.obj = config_path or Path.cwd() / CONFIG_FILE
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@main.command(help="Print a guide for coding agents.")
|
|
33
|
+
@click.pass_context
|
|
34
|
+
def context(ctx: click.Context) -> None:
|
|
35
|
+
click.echo(context_guide(load_config(ctx), Path.cwd()), nl=False)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
main.add_command(server)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
## Usage
|
|
2
|
+
|
|
3
|
+
labnotes reads two folders. The experiments folder has one subfolder per experiment, each with a `design.yaml` and markdown notes. The data folder holds run data and a `.dirsql.toml` declaring a `runs` table with a `study` column. A project that uses labnotes has a `.labnotes.toml` at its root; labnotes reads it from the working folder, so run labnotes from the project root, or pass `-c PATH`. The lines above this guide name the one found and the folders it resolves to, or say there is none. Its keys are optional:
|
|
4
|
+
|
|
5
|
+
```toml
|
|
6
|
+
experiments = "experiments" # the default
|
|
7
|
+
data = "data" # relative to .labnotes.toml, absolute, or ~
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
`--experiments-folder` and `--data-folder`, or `LABNOTES_EXPERIMENTS_FOLDER` and `LABNOTES_DATA_FOLDER`, override either key. Without a `.labnotes.toml`, pass both.
|
|
11
|
+
|
|
12
|
+
The run data lives in the data folder. Query it with [dirsql](https://dirsql.dev) and the data folder's `.dirsql.toml`, which declares the `runs` table:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
uvx dirsql -c data/.dirsql.toml "SELECT * FROM runs LIMIT 1" --format json
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`uvx labnotes server` serves the experiments and their runs as a local site.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from importlib.metadata import version
|
|
2
|
+
from importlib.resources import files
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from labnotes.read_config import CONFIG_FILE
|
|
6
|
+
from labnotes.models import LabnotesConfig
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def context_guide(config: LabnotesConfig | None, cwd: Path) -> str:
|
|
10
|
+
guide = files("labnotes").joinpath("context.md").read_text(encoding="utf-8")
|
|
11
|
+
if config is None:
|
|
12
|
+
project = (
|
|
13
|
+
f"No {CONFIG_FILE} in {cwd}. If this project uses labnotes, run it"
|
|
14
|
+
f" from the folder that holds {CONFIG_FILE}, or pass -c PATH."
|
|
15
|
+
)
|
|
16
|
+
else:
|
|
17
|
+
project = (
|
|
18
|
+
f"Config: {config.path}\n"
|
|
19
|
+
f"Experiments folder: {config.experiments_folder}\n"
|
|
20
|
+
f"Data folder: {config.data_folder}"
|
|
21
|
+
)
|
|
22
|
+
return f"labnotes {version('labnotes')}\n\n{project}\n\n{guide}"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
|
|
5
|
+
from labnotes.models import LabnotesConfig
|
|
6
|
+
from labnotes.read_config import read_config
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def load_config(ctx: click.Context) -> LabnotesConfig | None:
|
|
10
|
+
path: Path = ctx.find_root().obj
|
|
11
|
+
try:
|
|
12
|
+
return read_config(path) if path.is_file() else None
|
|
13
|
+
except ValueError as error:
|
|
14
|
+
raise click.ClickException(str(error)) from error
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from dataclasses import dataclass, field
|
|
2
|
+
from pathlib import Path
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
@dataclass(frozen=True)
|
|
@@ -7,3 +8,10 @@ class RunView:
|
|
|
7
8
|
descending: bool = False
|
|
8
9
|
status: str | None = None
|
|
9
10
|
filters: dict[str, str] = field(default_factory=dict)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class LabnotesConfig:
|
|
15
|
+
path: Path
|
|
16
|
+
experiments_folder: Path
|
|
17
|
+
data_folder: Path
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import tomllib
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from labnotes.models import LabnotesConfig
|
|
5
|
+
|
|
6
|
+
CONFIG_FILE = ".labnotes.toml"
|
|
7
|
+
DEFAULTS = {"experiments": "experiments", "data": "data"}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def read_config(path: Path) -> LabnotesConfig:
|
|
11
|
+
with path.open("rb") as file:
|
|
12
|
+
values = tomllib.load(file)
|
|
13
|
+
unknown = sorted(values.keys() - DEFAULTS.keys())
|
|
14
|
+
if unknown:
|
|
15
|
+
raise ValueError(f"{path}: unknown keys {', '.join(unknown)}")
|
|
16
|
+
folder = path.resolve().parent
|
|
17
|
+
folders = {}
|
|
18
|
+
for key, default in DEFAULTS.items():
|
|
19
|
+
value = values.get(key, default)
|
|
20
|
+
if not isinstance(value, str):
|
|
21
|
+
raise ValueError(f"{path}: {key} must be a string")
|
|
22
|
+
folders[key] = folder / Path(value).expanduser()
|
|
23
|
+
return LabnotesConfig(path.resolve(), folders["experiments"], folders["data"])
|
|
@@ -1,28 +1,18 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import json
|
|
3
1
|
import os
|
|
4
2
|
from pathlib import Path
|
|
5
3
|
|
|
6
4
|
import click
|
|
7
5
|
from uvicorn.main import main as uvicorn_main
|
|
8
6
|
|
|
9
|
-
from labnotes.
|
|
10
|
-
from labnotes.
|
|
11
|
-
from labnotes.query_experiment import query_experiment
|
|
7
|
+
from labnotes.load_config import load_config
|
|
8
|
+
from labnotes.read_config import CONFIG_FILE
|
|
12
9
|
from labnotes.serve_app import DATA_FOLDER, EXPERIMENTS_FOLDER, KERNEL_IDLE_MINUTES
|
|
13
10
|
|
|
14
11
|
# labnotes owns these; the rest of uvicorn's options pass straight through.
|
|
15
12
|
OWN_OPTIONS = {"app", "factory", "app_dir", "version", "host", "port"}
|
|
16
13
|
|
|
17
14
|
|
|
18
|
-
@click.command(
|
|
19
|
-
help="Browse experiments and their run data. With EXPERIMENT, print what has"
|
|
20
|
-
" run as JSON; with SQL too, query that experiment's runs. `labnotes context`"
|
|
21
|
-
" prints a guide for coding agents."
|
|
22
|
-
)
|
|
23
|
-
@click.version_option(package_name="labnotes")
|
|
24
|
-
@click.argument("experiment", required=False)
|
|
25
|
-
@click.argument("sql", required=False)
|
|
15
|
+
@click.command(help="Serve the experiments and their run data as a local site.")
|
|
26
16
|
@click.option(
|
|
27
17
|
"--experiments-folder",
|
|
28
18
|
type=click.Path(path_type=Path),
|
|
@@ -43,12 +33,6 @@ OWN_OPTIONS = {"app", "factory", "app_dir", "version", "host", "port"}
|
|
|
43
33
|
envvar=KERNEL_IDLE_MINUTES,
|
|
44
34
|
help="Stop a note's Python kernel after this long without a run.",
|
|
45
35
|
)
|
|
46
|
-
@click.option(
|
|
47
|
-
"--json",
|
|
48
|
-
"as_json",
|
|
49
|
-
is_flag=True,
|
|
50
|
-
help="Print experiments as JSON instead of serving.",
|
|
51
|
-
)
|
|
52
36
|
@click.option(
|
|
53
37
|
"-h",
|
|
54
38
|
"--host",
|
|
@@ -58,34 +42,21 @@ OWN_OPTIONS = {"app", "factory", "app_dir", "version", "host", "port"}
|
|
|
58
42
|
)
|
|
59
43
|
@click.option("-p", "--port", type=int, default=8000, show_default=True)
|
|
60
44
|
@click.pass_context
|
|
61
|
-
def
|
|
45
|
+
def server(
|
|
62
46
|
ctx: click.Context,
|
|
63
|
-
experiment: str | None,
|
|
64
|
-
sql: str | None,
|
|
65
47
|
experiments_folder: Path | None,
|
|
66
48
|
data_folder: Path | None,
|
|
67
49
|
kernel_idle_minutes: int,
|
|
68
|
-
as_json: bool,
|
|
69
50
|
**server_options: object,
|
|
70
51
|
) -> None:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
52
|
+
config = load_config(ctx)
|
|
53
|
+
if config is not None:
|
|
54
|
+
experiments_folder = experiments_folder or config.experiments_folder
|
|
55
|
+
data_folder = data_folder or config.data_folder
|
|
74
56
|
if experiments_folder is None or data_folder is None:
|
|
75
|
-
raise click.UsageError(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
result = asyncio.run(
|
|
79
|
-
query_experiment(experiments_folder, data_folder, experiment, sql)
|
|
80
|
-
)
|
|
81
|
-
except (LookupError, RuntimeError) as error:
|
|
82
|
-
raise click.ClickException(str(error)) from error
|
|
83
|
-
click.echo(json.dumps(result, indent=2))
|
|
84
|
-
return
|
|
85
|
-
if as_json:
|
|
86
|
-
experiments = asyncio.run(dump_experiments(experiments_folder, data_folder))
|
|
87
|
-
click.echo(json.dumps(experiments, indent=2))
|
|
88
|
-
return
|
|
57
|
+
raise click.UsageError(
|
|
58
|
+
f"--experiments-folder and --data-folder are required without a {CONFIG_FILE}."
|
|
59
|
+
)
|
|
89
60
|
# Through the environment so --reload and --workers child processes see them.
|
|
90
61
|
os.environ[EXPERIMENTS_FOLDER] = str(experiments_folder.resolve())
|
|
91
62
|
os.environ[DATA_FOLDER] = str(data_folder.resolve())
|
|
@@ -98,4 +69,4 @@ def main(
|
|
|
98
69
|
)
|
|
99
70
|
|
|
100
71
|
|
|
101
|
-
|
|
72
|
+
server.params += [p for p in uvicorn_main.params if p.name not in OWN_OPTIONS]
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
## Usage
|
|
2
|
-
|
|
3
|
-
labnotes reads two folders. The experiments folder has one subfolder per experiment, each with a `design.yaml` and markdown notes. The data folder holds run data and a `.dirsql.toml` declaring a `runs` table with a `study` column. Pass both on every call, or set `LABNOTES_EXPERIMENTS_FOLDER` and `LABNOTES_DATA_FOLDER`:
|
|
4
|
-
|
|
5
|
-
```sh
|
|
6
|
-
uvx labnotes --experiments-folder experiments --data-folder data --json
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
`--json` lists every experiment: its name, study, the design's fixed and varied conditions, the target run count, and how many runs have run and completed, overall and per cell.
|
|
10
|
-
|
|
11
|
-
### One experiment
|
|
12
|
-
|
|
13
|
-
Name an experiment to see what has run for it, as JSON:
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
uvx labnotes models-effort --experiments-folder experiments --data-folder data
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Add SQL to query its runs. `runs` holds only that experiment's runs, matched on the study in its `design.yaml`; `main.runs` holds every run in the data folder. The query goes through [dirsql](https://dirsql.dev), so it is SQLite and read-only:
|
|
20
|
-
|
|
21
|
-
```sh
|
|
22
|
-
uvx labnotes models-effort "SELECT model, effort, COUNT(*) AS n FROM runs GROUP BY 1, 2" --experiments-folder experiments --data-folder data
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
stdout is one JSON array of row objects. The columns are whatever the data folder's `.dirsql.toml` declares; `SELECT * FROM runs LIMIT 1` shows them. A run counts as completed when the design's `completed_run` SQL expression is true; the one-experiment JSON prints it, so reuse it in a `WHERE`.
|
|
26
|
-
|
|
27
|
-
An unknown experiment, an experiment without a `study`, or bad SQL prints an error to stderr and exits `1`. An experiment named `context` cannot be queried this way.
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
|
|
3
|
-
from labnotes.list_experiments import list_experiments
|
|
4
|
-
from labnotes.open_experiments import open_experiments
|
|
5
|
-
from labnotes.open_runs import open_runs
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
async def dump_experiments(
|
|
9
|
-
experiments_folder: Path, data_folder: Path
|
|
10
|
-
) -> list[dict[str, object]]:
|
|
11
|
-
experiments = open_experiments(experiments_folder)
|
|
12
|
-
runs = open_runs(data_folder)
|
|
13
|
-
await experiments.ready()
|
|
14
|
-
await runs.ready()
|
|
15
|
-
return await list_experiments(experiments, runs)
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
|
|
3
|
-
from labnotes.list_experiments import list_experiments
|
|
4
|
-
from labnotes.open_experiments import open_experiments
|
|
5
|
-
from labnotes.open_runs import open_runs
|
|
6
|
-
from labnotes.scope_runs import scope_runs
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
async def query_experiment(
|
|
10
|
-
experiments_folder: Path, data_folder: Path, name: str, sql: str | None
|
|
11
|
-
) -> object:
|
|
12
|
-
experiments = open_experiments(experiments_folder)
|
|
13
|
-
runs = open_runs(data_folder)
|
|
14
|
-
await experiments.ready()
|
|
15
|
-
await runs.ready()
|
|
16
|
-
listed = await list_experiments(experiments, runs)
|
|
17
|
-
experiment = next((row for row in listed if row["name"] == name), None)
|
|
18
|
-
if experiment is None:
|
|
19
|
-
raise LookupError(f"no experiment named {name!r}")
|
|
20
|
-
if sql is None:
|
|
21
|
-
return experiment
|
|
22
|
-
if experiment["study"] is None:
|
|
23
|
-
raise LookupError(f"{name!r} has no study in its design.yaml")
|
|
24
|
-
return await runs.query(scope_runs(sql, str(experiment["study"])))
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
|
|
3
|
-
from labnotes.sql_quote import quote_string
|
|
4
|
-
|
|
5
|
-
LEADING_WITH = re.compile(r"\s*WITH(\s+RECURSIVE)?\s+", re.IGNORECASE)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def scope_runs(sql: str, study: str) -> str:
|
|
9
|
-
runs = f"runs AS (SELECT * FROM main.runs WHERE study = {quote_string(study)})"
|
|
10
|
-
leading_with = LEADING_WITH.match(sql)
|
|
11
|
-
if leading_with is None:
|
|
12
|
-
return f"WITH {runs} {sql}"
|
|
13
|
-
recursive = " RECURSIVE" if leading_with.group(1) else ""
|
|
14
|
-
return f"WITH{recursive} {runs}, {sql[leading_with.end() :]}"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|