labplan 0.1.0__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.
labplan-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
labplan-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: labplan
3
+ Version: 0.1.0
4
+ Summary: Plan the measurement, fit the model, keep the record - exact measurement planning, calibration and audit trails for any lab model
5
+ Author: Tanvir Mahmud Mahim
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/TaN-MM-Org/labplan
8
+ Project-URL: Issues, https://github.com/TaN-MM-Org/labplan/issues
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Topic :: Scientific/Engineering :: Physics
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: numpy>=1.22
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest>=7; extra == "test"
26
+ Dynamic: license-file
27
+
28
+ # labplan
29
+
30
+ [![tests](https://github.com/TaN-MM-Org/labplan/actions/workflows/ci.yml/badge.svg)](https://github.com/TaN-MM-Org/labplan/actions)
31
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
32
+
33
+ Every measurement campaign asks the same four questions. Can the
34
+ measurements I am about to take determine the numbers I care about --
35
+ and how well? Which settings are worth the instrument time? Once the
36
+ data exist, what are the numbers, with error bars that mean it? And a
37
+ year from now, can anyone trace exactly what was fitted, to which
38
+ data, by what? `labplan` answers all four for ANY instrument or
39
+ experiment you can describe with a Python function -- and refuses,
40
+ with an explanation, whenever the honest answer is "this design
41
+ cannot tell".
42
+
43
+ Nine research packages in this organization -- covering colour-centre
44
+ spins, squeezed light, spin-squeezed clocks, Raman maps,
45
+ single-photon emitters, superconducting detectors, band structure,
46
+ semiconductor heterostructures and photonic fabrication -- each grew
47
+ the same planning-and-calibration loop for its own physics. `labplan`
48
+ is that loop extracted, generalized, and hardened into a single
49
+ dependency-light package (NumPy only, Python 3.9-3.14): the tenth
50
+ package is the pattern itself.
51
+
52
+ ## Install
53
+
54
+ ```
55
+ pip install labplan # NumPy only
56
+ ```
57
+
58
+ ## The loop in one example
59
+
60
+ ```python
61
+ import numpy as np
62
+ from labplan import (Model, information, design, fit,
63
+ repeats_for, audit_record, report_text)
64
+
65
+ # 1. Your model: anything that predicts a reading from parameters
66
+ # and settings. Here, a sensor line y = gain * x + offset.
67
+ m = Model("sensor line",
68
+ lambda th, x: th[0] * x[:, 0] + th[1],
69
+ param_names=("gain", "offset"),
70
+ reference="sensor manual rev. 3, eq. (2)")
71
+
72
+ # 2. Before measuring: would 12 planned settings determine the
73
+ # parameters, and how well, at 0.05 units of reading noise?
74
+ x_planned = np.linspace(0.5, 5.0, 12)[:, None]
75
+ plan = information(m, theta=[2.0, 0.0], x=x_planned, sigmas=0.05)
76
+ print(plan["identifiable"], plan["sigma"])
77
+
78
+ # ... or let labplan pick the best 5 of the settings you can reach,
79
+ # and price a target error bar in repeats (a closed form):
80
+ pick = design(m, [2.0, 0.0], x_planned, n_pick=5, sigmas=0.05)
81
+ r, predicted = repeats_for({"gain": 0.01}, plan)
82
+
83
+ # 3. After measuring: fit, with the SAME matrix the plan promised.
84
+ res = fit(m, x_planned, y_measured, theta0=[1.0, 0.0], sigmas=0.05)
85
+ print(res.values, res.sigma, res.chi2)
86
+
87
+ # 4. Keep the record: what, to which data (sha256), by what, when.
88
+ rec = audit_record(res, operator="T. Mahim", note="bench 2, warm-up ok")
89
+ print(report_text(rec))
90
+ ```
91
+
92
+ The central promise: the planner's error bars and the fit's error
93
+ bars are the same matrix, so what is promised before the measurement
94
+ is what is reported after -- exactly, whenever the model describes
95
+ the data. The tests assert that equality to machine precision.
96
+
97
+ ## When the model might be wrong
98
+
99
+ Model-based error bars assume the model is right. For the day it is
100
+ not, `conformal_quantile` supplies distribution-free prediction
101
+ intervals from held-out calibration data, with an exact finite-sample
102
+ guarantee that holds whatever the model and whatever the noise (split
103
+ conformal prediction; Vovk, Gammerman and Shafer, Algorithmic
104
+ Learning in a Random World, Springer (2005); Lei et al., J. Am.
105
+ Stat. Assoc. 113, 1094 (2018); Angelopoulos and Bates,
106
+ arXiv:2107.07511):
107
+
108
+ ```python
109
+ from labplan import conformal_quantile, conformal_interval
110
+
111
+ q = conformal_quantile(abs_errors_heldout, alpha=0.1) # 90% level
112
+ lo, hi = conformal_interval(new_predictions, q)
113
+ ```
114
+
115
+ Its honest limits are stated in the docstring rather than hidden:
116
+ the guarantee is marginal, and it needs the calibration data to be
117
+ exchangeable with the new measurement -- last month's instrument
118
+ state does not certify next month's drift.
119
+
120
+ ## What is inside
121
+
122
+ - **`Model`**: your forward function with named parameters and a
123
+ mandatory `reference` -- provenance travels with every prediction,
124
+ the same rule every package in this organization applies.
125
+ - **`information` / `design` / `repeats_for`**: predicted error bars
126
+ from the design alone (the Fisher information of independent
127
+ Gaussian measurements; any statistics text, under "Cramer-Rao
128
+ bound"); greedy D-optimal selection of the most informative
129
+ settings (Pukelsheim, Optimal Design of Experiments, SIAM (2006));
130
+ and the exact 1/sqrt(repeats) law, inverted in closed form.
131
+ - **`fit`**: Levenberg-Marquardt weighted least squares in pure
132
+ NumPy, with exact known-noise covariance and a chi-squared check
133
+ when measurement errors are supplied, and residual-scaled error
134
+ bars (stated as such) when they are not.
135
+ - **`conformal_quantile` / `conformal_interval` / `coverage_exact`**:
136
+ distribution-free intervals with the exact finite-sample coverage
137
+ formula exposed for checking.
138
+ - **`audit_record` / `report_text`**: a JSON-serializable statement
139
+ of record -- model, source, values, error bars, goodness of fit,
140
+ identifiability, the sha256 of the exact data arrays, software
141
+ versions, UTC timestamp, operator -- and its human-readable
142
+ rendering.
143
+ - **`save_measurements_csv` / `load_measurements_csv`**: a plain,
144
+ checked file contract whose round trip is bit-exact.
145
+
146
+ ## Refusals, not guesses
147
+
148
+ A design that cannot tell the parameters apart is refused with an
149
+ explanation, in the planner, the fit and the design tool alike --
150
+ judged on a unit-free (correlation-scaled) information matrix, so
151
+ mixed units can never fake or hide a degeneracy. Too few points, a
152
+ non-converging fit, an uncertifiable conformal level, a malformed
153
+ data file: each refuses with the reason and, where one exists, the
154
+ remedy.
155
+
156
+ ## How it is checked
157
+
158
+ 14 tests (Python 3.9-3.14, run in CI on every push), every
159
+ statistical claim pinned to a closed form, an exact identity, or
160
+ seeded simulation against an exact formula -- never a stored number.
161
+ Highlights: on a linear model the fit covariance equals the textbook
162
+ closed form sigma^2 (X^T X)^-1 exactly, and the planner promises the
163
+ same matrix; 400 seeded Monte-Carlo experiments match the reported
164
+ error bars; an exactly degenerate model is refused via an exact rank
165
+ argument; the greedy design obeys the rank-one determinant identity,
166
+ reproduces its own rule, never loses to a random subset, and -- for
167
+ the two-point line design -- matches the classical optimum found by
168
+ exhaustion; the repeat law is asserted by tiling the design; the
169
+ conformal quantile is the exact rank formula and seeded simulation
170
+ matches the exact closed-form coverage inside the published
171
+ two-sided guarantee; the audit record survives JSON round trip
172
+ exactly and its digest pins the exact data; file round trips are
173
+ bit-exact.
174
+
175
+ ## Honest limits
176
+
177
+ Deliberate scope, designed out with reasons: the Gaussian
178
+ error-bar machinery is exact for independent Gaussian measurement
179
+ errors and first-order-accurate otherwise (the conformal tools are
180
+ the assumption-free complement, and their own limits are stated);
181
+ the greedy design is a transparent heuristic, not a proof of global
182
+ optimality; no physics ships in this package at all -- your model
183
+ and its `reference` carry the physics, and the nine physics packages
184
+ of this organization remain the place where specific instruments'
185
+ models live, each already wired into this same loop.
186
+
187
+ ## Support and governance
188
+
189
+ Written and maintained by Tanvir Mahmud Mahim (Department of
190
+ Electrical and Electronic Engineering, BRAC University), who reviews
191
+ every change and takes the final decision on scope and releases.
192
+ Design questions are discussed in the open in issues and pull
193
+ requests, and the standing rule of
194
+ [CONTRIBUTING.md](CONTRIBUTING.md) binds the maintainer exactly as it
195
+ binds contributors: a change that touches the statistics arrives with
196
+ a test, and a claim arrives with its source.
197
+
198
+ Support runs through the
199
+ [issue tracker](https://github.com/TaN-MM-Org/labplan/issues). Usage
200
+ questions are welcome alongside bug reports; a docstring that left a
201
+ unit or a convention unclear is treated as a documentation bug, not
202
+ user error. While the version is below 1.0 the API may still move
203
+ between minor versions; such changes are called out in the release
204
+ notes.
205
+
206
+ ## License
207
+
208
+ Apache-2.0.
@@ -0,0 +1,181 @@
1
+ # labplan
2
+
3
+ [![tests](https://github.com/TaN-MM-Org/labplan/actions/workflows/ci.yml/badge.svg)](https://github.com/TaN-MM-Org/labplan/actions)
4
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
5
+
6
+ Every measurement campaign asks the same four questions. Can the
7
+ measurements I am about to take determine the numbers I care about --
8
+ and how well? Which settings are worth the instrument time? Once the
9
+ data exist, what are the numbers, with error bars that mean it? And a
10
+ year from now, can anyone trace exactly what was fitted, to which
11
+ data, by what? `labplan` answers all four for ANY instrument or
12
+ experiment you can describe with a Python function -- and refuses,
13
+ with an explanation, whenever the honest answer is "this design
14
+ cannot tell".
15
+
16
+ Nine research packages in this organization -- covering colour-centre
17
+ spins, squeezed light, spin-squeezed clocks, Raman maps,
18
+ single-photon emitters, superconducting detectors, band structure,
19
+ semiconductor heterostructures and photonic fabrication -- each grew
20
+ the same planning-and-calibration loop for its own physics. `labplan`
21
+ is that loop extracted, generalized, and hardened into a single
22
+ dependency-light package (NumPy only, Python 3.9-3.14): the tenth
23
+ package is the pattern itself.
24
+
25
+ ## Install
26
+
27
+ ```
28
+ pip install labplan # NumPy only
29
+ ```
30
+
31
+ ## The loop in one example
32
+
33
+ ```python
34
+ import numpy as np
35
+ from labplan import (Model, information, design, fit,
36
+ repeats_for, audit_record, report_text)
37
+
38
+ # 1. Your model: anything that predicts a reading from parameters
39
+ # and settings. Here, a sensor line y = gain * x + offset.
40
+ m = Model("sensor line",
41
+ lambda th, x: th[0] * x[:, 0] + th[1],
42
+ param_names=("gain", "offset"),
43
+ reference="sensor manual rev. 3, eq. (2)")
44
+
45
+ # 2. Before measuring: would 12 planned settings determine the
46
+ # parameters, and how well, at 0.05 units of reading noise?
47
+ x_planned = np.linspace(0.5, 5.0, 12)[:, None]
48
+ plan = information(m, theta=[2.0, 0.0], x=x_planned, sigmas=0.05)
49
+ print(plan["identifiable"], plan["sigma"])
50
+
51
+ # ... or let labplan pick the best 5 of the settings you can reach,
52
+ # and price a target error bar in repeats (a closed form):
53
+ pick = design(m, [2.0, 0.0], x_planned, n_pick=5, sigmas=0.05)
54
+ r, predicted = repeats_for({"gain": 0.01}, plan)
55
+
56
+ # 3. After measuring: fit, with the SAME matrix the plan promised.
57
+ res = fit(m, x_planned, y_measured, theta0=[1.0, 0.0], sigmas=0.05)
58
+ print(res.values, res.sigma, res.chi2)
59
+
60
+ # 4. Keep the record: what, to which data (sha256), by what, when.
61
+ rec = audit_record(res, operator="T. Mahim", note="bench 2, warm-up ok")
62
+ print(report_text(rec))
63
+ ```
64
+
65
+ The central promise: the planner's error bars and the fit's error
66
+ bars are the same matrix, so what is promised before the measurement
67
+ is what is reported after -- exactly, whenever the model describes
68
+ the data. The tests assert that equality to machine precision.
69
+
70
+ ## When the model might be wrong
71
+
72
+ Model-based error bars assume the model is right. For the day it is
73
+ not, `conformal_quantile` supplies distribution-free prediction
74
+ intervals from held-out calibration data, with an exact finite-sample
75
+ guarantee that holds whatever the model and whatever the noise (split
76
+ conformal prediction; Vovk, Gammerman and Shafer, Algorithmic
77
+ Learning in a Random World, Springer (2005); Lei et al., J. Am.
78
+ Stat. Assoc. 113, 1094 (2018); Angelopoulos and Bates,
79
+ arXiv:2107.07511):
80
+
81
+ ```python
82
+ from labplan import conformal_quantile, conformal_interval
83
+
84
+ q = conformal_quantile(abs_errors_heldout, alpha=0.1) # 90% level
85
+ lo, hi = conformal_interval(new_predictions, q)
86
+ ```
87
+
88
+ Its honest limits are stated in the docstring rather than hidden:
89
+ the guarantee is marginal, and it needs the calibration data to be
90
+ exchangeable with the new measurement -- last month's instrument
91
+ state does not certify next month's drift.
92
+
93
+ ## What is inside
94
+
95
+ - **`Model`**: your forward function with named parameters and a
96
+ mandatory `reference` -- provenance travels with every prediction,
97
+ the same rule every package in this organization applies.
98
+ - **`information` / `design` / `repeats_for`**: predicted error bars
99
+ from the design alone (the Fisher information of independent
100
+ Gaussian measurements; any statistics text, under "Cramer-Rao
101
+ bound"); greedy D-optimal selection of the most informative
102
+ settings (Pukelsheim, Optimal Design of Experiments, SIAM (2006));
103
+ and the exact 1/sqrt(repeats) law, inverted in closed form.
104
+ - **`fit`**: Levenberg-Marquardt weighted least squares in pure
105
+ NumPy, with exact known-noise covariance and a chi-squared check
106
+ when measurement errors are supplied, and residual-scaled error
107
+ bars (stated as such) when they are not.
108
+ - **`conformal_quantile` / `conformal_interval` / `coverage_exact`**:
109
+ distribution-free intervals with the exact finite-sample coverage
110
+ formula exposed for checking.
111
+ - **`audit_record` / `report_text`**: a JSON-serializable statement
112
+ of record -- model, source, values, error bars, goodness of fit,
113
+ identifiability, the sha256 of the exact data arrays, software
114
+ versions, UTC timestamp, operator -- and its human-readable
115
+ rendering.
116
+ - **`save_measurements_csv` / `load_measurements_csv`**: a plain,
117
+ checked file contract whose round trip is bit-exact.
118
+
119
+ ## Refusals, not guesses
120
+
121
+ A design that cannot tell the parameters apart is refused with an
122
+ explanation, in the planner, the fit and the design tool alike --
123
+ judged on a unit-free (correlation-scaled) information matrix, so
124
+ mixed units can never fake or hide a degeneracy. Too few points, a
125
+ non-converging fit, an uncertifiable conformal level, a malformed
126
+ data file: each refuses with the reason and, where one exists, the
127
+ remedy.
128
+
129
+ ## How it is checked
130
+
131
+ 14 tests (Python 3.9-3.14, run in CI on every push), every
132
+ statistical claim pinned to a closed form, an exact identity, or
133
+ seeded simulation against an exact formula -- never a stored number.
134
+ Highlights: on a linear model the fit covariance equals the textbook
135
+ closed form sigma^2 (X^T X)^-1 exactly, and the planner promises the
136
+ same matrix; 400 seeded Monte-Carlo experiments match the reported
137
+ error bars; an exactly degenerate model is refused via an exact rank
138
+ argument; the greedy design obeys the rank-one determinant identity,
139
+ reproduces its own rule, never loses to a random subset, and -- for
140
+ the two-point line design -- matches the classical optimum found by
141
+ exhaustion; the repeat law is asserted by tiling the design; the
142
+ conformal quantile is the exact rank formula and seeded simulation
143
+ matches the exact closed-form coverage inside the published
144
+ two-sided guarantee; the audit record survives JSON round trip
145
+ exactly and its digest pins the exact data; file round trips are
146
+ bit-exact.
147
+
148
+ ## Honest limits
149
+
150
+ Deliberate scope, designed out with reasons: the Gaussian
151
+ error-bar machinery is exact for independent Gaussian measurement
152
+ errors and first-order-accurate otherwise (the conformal tools are
153
+ the assumption-free complement, and their own limits are stated);
154
+ the greedy design is a transparent heuristic, not a proof of global
155
+ optimality; no physics ships in this package at all -- your model
156
+ and its `reference` carry the physics, and the nine physics packages
157
+ of this organization remain the place where specific instruments'
158
+ models live, each already wired into this same loop.
159
+
160
+ ## Support and governance
161
+
162
+ Written and maintained by Tanvir Mahmud Mahim (Department of
163
+ Electrical and Electronic Engineering, BRAC University), who reviews
164
+ every change and takes the final decision on scope and releases.
165
+ Design questions are discussed in the open in issues and pull
166
+ requests, and the standing rule of
167
+ [CONTRIBUTING.md](CONTRIBUTING.md) binds the maintainer exactly as it
168
+ binds contributors: a change that touches the statistics arrives with
169
+ a test, and a claim arrives with its source.
170
+
171
+ Support runs through the
172
+ [issue tracker](https://github.com/TaN-MM-Org/labplan/issues). Usage
173
+ questions are welcome alongside bug reports; a docstring that left a
174
+ unit or a convention unclear is treated as a documentation bug, not
175
+ user error. While the version is below 1.0 the API may still move
176
+ between minor versions; such changes are called out in the release
177
+ notes.
178
+
179
+ ## License
180
+
181
+ Apache-2.0.
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "labplan"
7
+ version = "0.1.0"
8
+ description = "Plan the measurement, fit the model, keep the record - exact measurement planning, calibration and audit trails for any lab model"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = {text = "Apache-2.0"}
12
+ authors = [{name = "Tanvir Mahmud Mahim"}]
13
+ dependencies = ["numpy>=1.22"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Science/Research",
17
+ "License :: OSI Approved :: Apache Software License",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.9",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
25
+ "Topic :: Scientific/Engineering :: Physics",
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/TaN-MM-Org/labplan"
30
+ Issues = "https://github.com/TaN-MM-Org/labplan/issues"
31
+
32
+ [project.optional-dependencies]
33
+ test = ["pytest>=7"]
34
+
35
+ [tool.setuptools.packages.find]
36
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+