pymetrix-labbook 0.1.0a1__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.
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .pytest_cache/
5
+ .pytest_tmp/
6
+ .venv/
7
+ build/
8
+ dist/
9
+ .ipynb_checkpoints/
10
+ hs_err_pid*.log
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Geoffrey Heenan
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.5
2
+ Name: pymetrix-labbook
3
+ Version: 0.1.0a1
4
+ Summary: A research lab book for pymetrix: an append-only, hash-chained record of the work, kept in the project and verified by replay
5
+ Project-URL: Homepage, https://github.com/GeoffHeenan/pymetrix
6
+ Project-URL: Source, https://github.com/GeoffHeenan/pymetrix/tree/main/packages/pymetrix-labbook
7
+ Project-URL: Issues, https://github.com/GeoffHeenan/pymetrix/issues
8
+ Project-URL: Changelog, https://github.com/GeoffHeenan/pymetrix/blob/main/CHANGELOG.md
9
+ Author: Geoffrey Heenan
10
+ License-Expression: BSD-3-Clause
11
+ License-File: LICENSE
12
+ Requires-Python: >=3.11
13
+ Requires-Dist: pymetrix>=0.1.0a10
14
+ Provides-Extra: audit
15
+ Requires-Dist: mcp>=2.3; extra == 'audit'
16
+ Provides-Extra: test
17
+ Requires-Dist: pytest>=9.0.3; extra == 'test'
18
+ Description-Content-Type: text/markdown
19
+
20
+ # pymetrix-labbook
21
+
22
+ A research lab book for pymetrix, as a plugin: an append-only, hash-chained record of the work, kept inside the
23
+ project and checked by replay. It records what a project's history does not keep: steps that were undone,
24
+ cancelled, failed or removed, as well as the steps kept. A reviewer can then see the paths not taken, not only the
25
+ one reported. The design is in pymetrix's `docs/design/research-audit.md`; this is its first stage.
26
+
27
+ ```bash
28
+ pip install -e packages/pymetrix-labbook # from the repository (not on PyPI yet)
29
+ ```
30
+
31
+ Once installed, it records every session (scripts, notebooks, the desktop app and the MCP server) with no set-up.
32
+ Each project saved then carries its lab book in `attachments/labbook/labbook.jsonl`.
33
+
34
+ ```bash
35
+ pymetrix-labbook verify study.pymx # check the lab book; exit code 1 if it fails
36
+ pymetrix-labbook show study.pymx # list its entries
37
+ ```
38
+
39
+ ```python
40
+ from pymetrix_labbook import verify
41
+
42
+ result = verify("study.pymx") # result.ok, result.errors, result.warnings, result.notes, result.checked
43
+ print(result)
44
+ ```
45
+
46
+ ## The project brief, notes and objectives
47
+
48
+ Before the work, record what it sets out to do. Steps run inside `objective(...)` are linked to what they address:
49
+
50
+ ```python
51
+ from pymetrix_labbook import brief, note, objective
52
+
53
+ brief(session, "Consumption and income", "How much of a rise in income is consumed?",
54
+ objectives={"O1": "Estimate the marginal propensity to consume"},
55
+ hypotheses={"H1": {"statement": "The MPC is below one", "supports": "a coefficient on y under 1"}},
56
+ primary_outcomes=["the coefficient on y"], data={"sources": "national accounts, 2024 vintage"})
57
+ with objective("O1", "H1"):
58
+ session.run(FitEquation("c ~ y", name="fit"))
59
+ note(session, "Kept the full sample: no breaks found", about="O1")
60
+ ```
61
+
62
+ - **Amendments, never edits:** calling `brief` again restates the brief with a `reason`; both stay in the chain.
63
+ - **No brief:** `skip_brief(session, reason)` records that there is none, and why.
64
+ - **A private brief:** `commit_brief(session, "brief.json", ...)` writes the brief, with a random salt, to a file you
65
+ keep private, and puts only its hash in the lab book. Register the hash with a time-stamping service (OSF, an RFC
66
+ 3161 authority) to prove when it was written. At publication, `reveal_brief(session, "brief.json")` discloses it;
67
+ `verify` checks it matches the commitment and counts it as written when committed. In the app: the brief form's
68
+ "Keep it private" box, and **Reveal…**.
69
+ - **In the app:** the Lab book panel (View → Lab book) shows the brief, or a prompt to write one; **Brief…**,
70
+ **Skip…** and **Note…** write the entries; ticking an objective links the steps run while it is ticked; the
71
+ brief's checks and the latest entries update as you work.
72
+ - **What `verify` adds:** a brief written after the work began, objectives with no analysis, analyses linked to no
73
+ objective (exploratory, labelled as such), and hypotheses added only after results on them existed.
74
+
75
+ ## The pre-registered analysis plan
76
+
77
+ For confirmatory work, lock the exact specifications before reading the data:
78
+
79
+ ```python
80
+ from pymetrix_labbook import lock_plan
81
+
82
+ lock_plan(session, [FitEquation("c ~ y", name="fit")], data=["data"], sample="1990Q1-2019Q4", hypotheses=["H1"])
83
+ ```
84
+
85
+ Each later step is labelled **planned** (its code matches a specification, whatever its result is called) or
86
+ **exploratory**. Changing a locked plan needs a reason. `verify` reports the deviations: planned data read before
87
+ the plan was locked, planned specifications not run, exploratory steps since, and each change with the work done
88
+ before it. In the app: **Plan…** in the Lab book panel, which offers the session's steps to copy into the plan.
89
+
90
+ ## What was tried
91
+
92
+ Every fit of an outcome counts, kept, undone or failed: the lab book says how many specifications were tried.
93
+
94
+ ```python
95
+ from pymetrix_labbook import specification_curve, tried
96
+
97
+ tried(session, "fit") # 'fit is 1 of 23 specifications fitted for c (31 fits, lab book entries 2-58)'
98
+ specification_curve(session, "c", "y", highlight="fit").savefig("curve.png")
99
+ ```
100
+
101
+ `verify` lists the count for each outcome. In the app, the panel's checks show the counts and the line for the
102
+ selected result, and **Specification curve…** draws the specification curve.
103
+
104
+ In an exported report, tick **Plugins' notes** (Export report, Advanced; `ExportReport(..., plugin_notes=True)`):
105
+ a "What was tried" section gives this line for each result. The line comes from the session's record, so the
106
+ report's recorded script does not write it again.
107
+
108
+ ## Auditing with an AI assistant
109
+
110
+ `pymetrix-labbook audit study.pymx` serves read-only tools over the project's lab book to an assistant (Claude
111
+ Desktop, VS Code and other MCP clients), for a reviewer, journal or funder:
112
+
113
+ ```json
114
+ {"mcpServers": {"audit": {"command": "pymetrix-labbook", "args": ["audit", "C:/review/study.pymx"]}}}
115
+ ```
116
+
117
+ The tools: `summary`, `entries` (by kind, outcome or range), `brief`, `deviations` (against the brief and plan),
118
+ `specifications` (each fit of an outcome) and `verify_report`. They read the project file and never write it. The
119
+ assistant is told to cite entries, to flag patterns for a person to judge, and never to give a verdict. It is
120
+ separate from the researcher's own assistant, so the auditor is independent of the audited. Needs
121
+ `pip install "pymetrix-labbook[audit]"`.
122
+
123
+ ## What `verify` checks
124
+
125
+ 1. **The chain:** each entry holds the hash of the one before it, so a changed, removed, inserted or reordered
126
+ entry is found, and named.
127
+ 2. **Coverage:** pymetrix's save log records which recording plugins were active at each save. A save made
128
+ without the lab book, after it began, shows as a gap.
129
+ 3. **The steps:** the project's steps are those the lab book recorded at its last save, so a project changed
130
+ outside pymetrix, or given another project's lab book, is found.
131
+ 4. **The replay:** the project is opened, which runs its steps again. Each current result is compared with the
132
+ fingerprint recorded when it was made: estimates to 10 significant digits, and datasets' values exactly.
133
+
134
+ It lists what it cannot check, rather than passing over it:
135
+ - work done before the lab book was installed;
136
+ - typed code not run because it is not trusted;
137
+ - steps whose plugin is missing;
138
+ - results not computed yet.
139
+
140
+ ## What an entry holds
141
+
142
+ The time, the event and the code of each step, and who acted: the person at the machine (their login, through the
143
+ app or Python) or an AI agent (the MCP client, as it names itself, through pymetrix's MCP server). For each step, also:
144
+ - the names and versions it read;
145
+ - for what it wrote: the type, a fingerprint and the number of observations.
146
+
147
+ Who acted is hashed with the rest of the entry, so it cannot be changed afterwards. `verify` counts each actor's
148
+ steps, and `show` lists them beside each entry.
149
+
150
+ For a fitted model, also its outcome, sample and estimated coefficients with their standard errors. Entries hold
151
+ no data values, so a lab book can go to a reviewer without the data.
152
+
153
+ ## Limits
154
+
155
+ The lab book proves what happened while it was installed, not that nothing happened elsewhere. Work done outside
156
+ pymetrix, or before installing it, leaves no entries. The save log makes gaps visible, but cannot fill them.
157
+ External time-stamping and signed data releases, which narrow this, are later stages of the design.
158
+
159
+ License: BSD-3-Clause.
@@ -0,0 +1,140 @@
1
+ # pymetrix-labbook
2
+
3
+ A research lab book for pymetrix, as a plugin: an append-only, hash-chained record of the work, kept inside the
4
+ project and checked by replay. It records what a project's history does not keep: steps that were undone,
5
+ cancelled, failed or removed, as well as the steps kept. A reviewer can then see the paths not taken, not only the
6
+ one reported. The design is in pymetrix's `docs/design/research-audit.md`; this is its first stage.
7
+
8
+ ```bash
9
+ pip install -e packages/pymetrix-labbook # from the repository (not on PyPI yet)
10
+ ```
11
+
12
+ Once installed, it records every session (scripts, notebooks, the desktop app and the MCP server) with no set-up.
13
+ Each project saved then carries its lab book in `attachments/labbook/labbook.jsonl`.
14
+
15
+ ```bash
16
+ pymetrix-labbook verify study.pymx # check the lab book; exit code 1 if it fails
17
+ pymetrix-labbook show study.pymx # list its entries
18
+ ```
19
+
20
+ ```python
21
+ from pymetrix_labbook import verify
22
+
23
+ result = verify("study.pymx") # result.ok, result.errors, result.warnings, result.notes, result.checked
24
+ print(result)
25
+ ```
26
+
27
+ ## The project brief, notes and objectives
28
+
29
+ Before the work, record what it sets out to do. Steps run inside `objective(...)` are linked to what they address:
30
+
31
+ ```python
32
+ from pymetrix_labbook import brief, note, objective
33
+
34
+ brief(session, "Consumption and income", "How much of a rise in income is consumed?",
35
+ objectives={"O1": "Estimate the marginal propensity to consume"},
36
+ hypotheses={"H1": {"statement": "The MPC is below one", "supports": "a coefficient on y under 1"}},
37
+ primary_outcomes=["the coefficient on y"], data={"sources": "national accounts, 2024 vintage"})
38
+ with objective("O1", "H1"):
39
+ session.run(FitEquation("c ~ y", name="fit"))
40
+ note(session, "Kept the full sample: no breaks found", about="O1")
41
+ ```
42
+
43
+ - **Amendments, never edits:** calling `brief` again restates the brief with a `reason`; both stay in the chain.
44
+ - **No brief:** `skip_brief(session, reason)` records that there is none, and why.
45
+ - **A private brief:** `commit_brief(session, "brief.json", ...)` writes the brief, with a random salt, to a file you
46
+ keep private, and puts only its hash in the lab book. Register the hash with a time-stamping service (OSF, an RFC
47
+ 3161 authority) to prove when it was written. At publication, `reveal_brief(session, "brief.json")` discloses it;
48
+ `verify` checks it matches the commitment and counts it as written when committed. In the app: the brief form's
49
+ "Keep it private" box, and **Reveal…**.
50
+ - **In the app:** the Lab book panel (View → Lab book) shows the brief, or a prompt to write one; **Brief…**,
51
+ **Skip…** and **Note…** write the entries; ticking an objective links the steps run while it is ticked; the
52
+ brief's checks and the latest entries update as you work.
53
+ - **What `verify` adds:** a brief written after the work began, objectives with no analysis, analyses linked to no
54
+ objective (exploratory, labelled as such), and hypotheses added only after results on them existed.
55
+
56
+ ## The pre-registered analysis plan
57
+
58
+ For confirmatory work, lock the exact specifications before reading the data:
59
+
60
+ ```python
61
+ from pymetrix_labbook import lock_plan
62
+
63
+ lock_plan(session, [FitEquation("c ~ y", name="fit")], data=["data"], sample="1990Q1-2019Q4", hypotheses=["H1"])
64
+ ```
65
+
66
+ Each later step is labelled **planned** (its code matches a specification, whatever its result is called) or
67
+ **exploratory**. Changing a locked plan needs a reason. `verify` reports the deviations: planned data read before
68
+ the plan was locked, planned specifications not run, exploratory steps since, and each change with the work done
69
+ before it. In the app: **Plan…** in the Lab book panel, which offers the session's steps to copy into the plan.
70
+
71
+ ## What was tried
72
+
73
+ Every fit of an outcome counts, kept, undone or failed: the lab book says how many specifications were tried.
74
+
75
+ ```python
76
+ from pymetrix_labbook import specification_curve, tried
77
+
78
+ tried(session, "fit") # 'fit is 1 of 23 specifications fitted for c (31 fits, lab book entries 2-58)'
79
+ specification_curve(session, "c", "y", highlight="fit").savefig("curve.png")
80
+ ```
81
+
82
+ `verify` lists the count for each outcome. In the app, the panel's checks show the counts and the line for the
83
+ selected result, and **Specification curve…** draws the specification curve.
84
+
85
+ In an exported report, tick **Plugins' notes** (Export report, Advanced; `ExportReport(..., plugin_notes=True)`):
86
+ a "What was tried" section gives this line for each result. The line comes from the session's record, so the
87
+ report's recorded script does not write it again.
88
+
89
+ ## Auditing with an AI assistant
90
+
91
+ `pymetrix-labbook audit study.pymx` serves read-only tools over the project's lab book to an assistant (Claude
92
+ Desktop, VS Code and other MCP clients), for a reviewer, journal or funder:
93
+
94
+ ```json
95
+ {"mcpServers": {"audit": {"command": "pymetrix-labbook", "args": ["audit", "C:/review/study.pymx"]}}}
96
+ ```
97
+
98
+ The tools: `summary`, `entries` (by kind, outcome or range), `brief`, `deviations` (against the brief and plan),
99
+ `specifications` (each fit of an outcome) and `verify_report`. They read the project file and never write it. The
100
+ assistant is told to cite entries, to flag patterns for a person to judge, and never to give a verdict. It is
101
+ separate from the researcher's own assistant, so the auditor is independent of the audited. Needs
102
+ `pip install "pymetrix-labbook[audit]"`.
103
+
104
+ ## What `verify` checks
105
+
106
+ 1. **The chain:** each entry holds the hash of the one before it, so a changed, removed, inserted or reordered
107
+ entry is found, and named.
108
+ 2. **Coverage:** pymetrix's save log records which recording plugins were active at each save. A save made
109
+ without the lab book, after it began, shows as a gap.
110
+ 3. **The steps:** the project's steps are those the lab book recorded at its last save, so a project changed
111
+ outside pymetrix, or given another project's lab book, is found.
112
+ 4. **The replay:** the project is opened, which runs its steps again. Each current result is compared with the
113
+ fingerprint recorded when it was made: estimates to 10 significant digits, and datasets' values exactly.
114
+
115
+ It lists what it cannot check, rather than passing over it:
116
+ - work done before the lab book was installed;
117
+ - typed code not run because it is not trusted;
118
+ - steps whose plugin is missing;
119
+ - results not computed yet.
120
+
121
+ ## What an entry holds
122
+
123
+ The time, the event and the code of each step, and who acted: the person at the machine (their login, through the
124
+ app or Python) or an AI agent (the MCP client, as it names itself, through pymetrix's MCP server). For each step, also:
125
+ - the names and versions it read;
126
+ - for what it wrote: the type, a fingerprint and the number of observations.
127
+
128
+ Who acted is hashed with the rest of the entry, so it cannot be changed afterwards. `verify` counts each actor's
129
+ steps, and `show` lists them beside each entry.
130
+
131
+ For a fitted model, also its outcome, sample and estimated coefficients with their standard errors. Entries hold
132
+ no data values, so a lab book can go to a reviewer without the data.
133
+
134
+ ## Limits
135
+
136
+ The lab book proves what happened while it was installed, not that nothing happened elsewhere. Work done outside
137
+ pymetrix, or before installing it, leaves no entries. The save log makes gaps visible, but cannot fill them.
138
+ External time-stamping and signed data releases, which narrow this, are later stages of the design.
139
+
140
+ License: BSD-3-Clause.
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pymetrix-labbook"
7
+ dynamic = ["version"]
8
+ description = "A research lab book for pymetrix: an append-only, hash-chained record of the work, kept in the project and verified by replay"
9
+ readme = "README.md"
10
+ license = "BSD-3-Clause"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.11"
13
+ authors = [{ name = "Geoffrey Heenan" }]
14
+ dependencies = ["pymetrix>=0.1.0a10"] # with the extension API 1.5 (who acted); report notes need 1.6
15
+
16
+ [project.urls]
17
+ Homepage = "https://github.com/GeoffHeenan/pymetrix"
18
+ Source = "https://github.com/GeoffHeenan/pymetrix/tree/main/packages/pymetrix-labbook"
19
+ Issues = "https://github.com/GeoffHeenan/pymetrix/issues"
20
+ Changelog = "https://github.com/GeoffHeenan/pymetrix/blob/main/CHANGELOG.md"
21
+
22
+ [project.optional-dependencies]
23
+ audit = ["mcp>=2.3"] # pymetrix-labbook audit: the read-only MCP server for an auditor's assistant
24
+ test = ["pytest>=9.0.3"]
25
+
26
+ [project.scripts]
27
+ pymetrix-labbook = "pymetrix_labbook.cli:main"
28
+
29
+ # importing the package registers its observer; it describes itself as a plugin too
30
+ [project.entry-points."pymetrix.plugins"]
31
+ labbook = "pymetrix_labbook:register"
32
+ [project.entry-points."pymetrix.observers"]
33
+ labbook = "pymetrix_labbook:register"
34
+
35
+ [tool.hatch.version]
36
+ path = "src/pymetrix_labbook/_version.py"
37
+
38
+ [tool.hatch.build.targets.wheel]
39
+ packages = ["src/pymetrix_labbook"]
@@ -0,0 +1,58 @@
1
+ """A research lab book for pymetrix (``pymetrix-labbook``): an append-only, hash-chained record of the work, kept in
2
+ the project and checked by ``verify``. See pymetrix's docs/design/research-audit.md.
3
+
4
+ Installed, it records every session (scripts, notebooks, the app, the MCP server) with no further set-up: each step
5
+ run, failed, cancelled, undone or removed, and each project opened or saved. ``verify(path)``, or
6
+ ``pymetrix-labbook verify project.pymx`` at a command line, checks the chain, the save log, the steps and a replay.
7
+ ``brief``, ``note`` and ``objective`` record the project's scope and objectives before the work, the reasoning behind
8
+ choices, and what each step addresses.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from ._version import __version__
14
+ from pymetrix.extension import PluginInfo, SessionObserver
15
+
16
+ PLUGIN = PluginInfo(
17
+ name="pymetrix-labbook",
18
+ version=__version__,
19
+ license="BSD-3-Clause",
20
+ maintainer="Geoffrey Heenan",
21
+ description="A research lab book: an append-only, hash-chained record of every step, kept in the project and "
22
+ "verified by replay",
23
+ )
24
+
25
+ from .brief import brief, commit_brief, current_brief, note, objective, reveal_brief, skip_brief # noqa: E402
26
+ from .chain import Chain, ChainProblem # noqa: E402
27
+ from .plan import current_plan, lock_plan # noqa: E402
28
+ from .tried import specification_curve, tried # noqa: E402
29
+ from .recorder import fingerprint, lab_book, observe # noqa: E402
30
+ from .verify import Verification, verify # noqa: E402
31
+
32
+ _registered = False
33
+
34
+
35
+ def register() -> None:
36
+ """The entry point: register the observer that writes the lab book (once)."""
37
+ global _registered
38
+ if _registered:
39
+ return
40
+ from pymetrix.extension import plugin_context, register as add
41
+
42
+ import pymetrix.extension as extension
43
+ from pymetrix.extension import AppPanel
44
+
45
+ from .app import create_panel
46
+ from .tried import report_note
47
+
48
+ with plugin_context(PLUGIN):
49
+ add("observers", SessionObserver("labbook", observe), name="labbook")
50
+ add("panels", AppPanel("Lab book", create_panel, area="right"), name="labbook_panel") # View → Lab book
51
+ if hasattr(extension, "ReportNote"): # extension API 1.6: reports carry "1 of 23 fitted"
52
+ add("report_notes", extension.ReportNote("tried", "What was tried", report_note), name="tried")
53
+ _registered = True
54
+
55
+
56
+ __all__ = ["PLUGIN", "Chain", "ChainProblem", "Verification", "brief", "commit_brief", "current_brief", "current_plan",
57
+ "fingerprint", "lab_book", "lock_plan", "note", "objective", "observe", "register", "reveal_brief", "skip_brief",
58
+ "specification_curve", "tried", "verify"]
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0a1"