fresh-cbm 0.2.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.
- fresh_cbm-0.2.0/LICENSE +201 -0
- fresh_cbm-0.2.0/PKG-INFO +117 -0
- fresh_cbm-0.2.0/README.md +93 -0
- fresh_cbm-0.2.0/fresh_cbm/__init__.py +237 -0
- fresh_cbm-0.2.0/fresh_cbm/benchmark.py +176 -0
- fresh_cbm-0.2.0/fresh_cbm/build.py +203 -0
- fresh_cbm-0.2.0/fresh_cbm/effects.py +177 -0
- fresh_cbm-0.2.0/fresh_cbm/family.py +163 -0
- fresh_cbm-0.2.0/fresh_cbm/manifest.schema.json +135 -0
- fresh_cbm-0.2.0/fresh_cbm/release.py +79 -0
- fresh_cbm-0.2.0/fresh_cbm/schema.py +55 -0
- fresh_cbm-0.2.0/fresh_cbm/validate.py +79 -0
- fresh_cbm-0.2.0/fresh_cbm/verify.py +125 -0
- fresh_cbm-0.2.0/fresh_cbm.egg-info/PKG-INFO +117 -0
- fresh_cbm-0.2.0/fresh_cbm.egg-info/SOURCES.txt +34 -0
- fresh_cbm-0.2.0/fresh_cbm.egg-info/dependency_links.txt +1 -0
- fresh_cbm-0.2.0/fresh_cbm.egg-info/entry_points.txt +6 -0
- fresh_cbm-0.2.0/fresh_cbm.egg-info/requires.txt +15 -0
- fresh_cbm-0.2.0/fresh_cbm.egg-info/top_level.txt +1 -0
- fresh_cbm-0.2.0/pyproject.toml +81 -0
- fresh_cbm-0.2.0/setup.cfg +4 -0
- fresh_cbm-0.2.0/tests/test_api_docstrings.py +65 -0
- fresh_cbm-0.2.0/tests/test_benchmark.py +98 -0
- fresh_cbm-0.2.0/tests/test_build.py +115 -0
- fresh_cbm-0.2.0/tests/test_check_workflow.py +809 -0
- fresh_cbm-0.2.0/tests/test_cli.py +75 -0
- fresh_cbm-0.2.0/tests/test_client.py +221 -0
- fresh_cbm-0.2.0/tests/test_dashboard.py +217 -0
- fresh_cbm-0.2.0/tests/test_effects.py +96 -0
- fresh_cbm-0.2.0/tests/test_family.py +64 -0
- fresh_cbm-0.2.0/tests/test_properties.py +110 -0
- fresh_cbm-0.2.0/tests/test_release.py +43 -0
- fresh_cbm-0.2.0/tests/test_schema.py +47 -0
- fresh_cbm-0.2.0/tests/test_validate.py +87 -0
- fresh_cbm-0.2.0/tests/test_verify.py +63 -0
- fresh_cbm-0.2.0/tests/test_workflow.py +19 -0
fresh_cbm-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 UBC FRESH Lab
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
fresh_cbm-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fresh-cbm
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Exact cached libcbm stand-state tables for WS4/FEMIC carbon
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: numpy>=1.26
|
|
10
|
+
Requires-Dist: pandas>=2.2
|
|
11
|
+
Requires-Dist: pyarrow>=15
|
|
12
|
+
Requires-Dist: jsonschema>=4.20
|
|
13
|
+
Provides-Extra: test
|
|
14
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
15
|
+
Requires-Dist: pytest-cov>=5; extra == "test"
|
|
16
|
+
Requires-Dist: numpydoc>=1.7; extra == "test"
|
|
17
|
+
Requires-Dist: hypothesis>=6.100; extra == "test"
|
|
18
|
+
Requires-Dist: types-jsonschema; extra == "test"
|
|
19
|
+
Requires-Dist: pandas-stubs; extra == "test"
|
|
20
|
+
Requires-Dist: ruff>=0.5; extra == "test"
|
|
21
|
+
Requires-Dist: mypy>=1.10; extra == "test"
|
|
22
|
+
Requires-Dist: build>=1.2; extra == "test"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# fresh-cbm
|
|
26
|
+
|
|
27
|
+
Exact cached libcbm stand-state tables and lookup client for WS4/FEMIC carbon
|
|
28
|
+
analyses.
|
|
29
|
+
|
|
30
|
+
`fresh-cbm` stores the deterministic per-hectare carbon accounts produced by
|
|
31
|
+
libcbm for a declared package and treatment family. Consumers can look up a
|
|
32
|
+
stand state instead of rebuilding a CBM model for every analysis.
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
|
|
36
|
+
Published Sphinx site:
|
|
37
|
+
|
|
38
|
+
https://ubc-fresh.github.io/fresh-cbm/
|
|
39
|
+
|
|
40
|
+
Start with the cache format, building, and validation guides.
|
|
41
|
+
|
|
42
|
+
## Status
|
|
43
|
+
|
|
44
|
+
Phase P0 (workflow bootstrap and documentation) is complete. `ROADMAP.md` is the
|
|
45
|
+
plan of record; P1 is planned.
|
|
46
|
+
|
|
47
|
+
## Quick start
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
python -m pip install -e ".[test]"
|
|
51
|
+
fresh-cbm-build --help
|
|
52
|
+
fresh-cbm-validate --help
|
|
53
|
+
fresh-cbm-package --help
|
|
54
|
+
fresh-cbm-bench --help
|
|
55
|
+
fresh-cbm-verify --help
|
|
56
|
+
python -m pytest
|
|
57
|
+
python scripts/dashboard.py
|
|
58
|
+
sphinx-build -b html docs _build/html -W
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The builder and validator require WS4 (`ws4[carbon]`). Pass `--ws4-path` or put
|
|
62
|
+
the WS4 source root on `PYTHONPATH`; the client and tests do not.
|
|
63
|
+
|
|
64
|
+
## Available cache
|
|
65
|
+
|
|
66
|
+
`v0.1.0-tsa41` is the first published table:
|
|
67
|
+
|
|
68
|
+
- 5,273 TSA41 track/age states
|
|
69
|
+
- declared family: untreated + one `CC` event at offsets `0..49`
|
|
70
|
+
- 50 years, 26 carbon accounts, float64
|
|
71
|
+
- 2.85 GB
|
|
72
|
+
- 55 release assets
|
|
73
|
+
- validation: 102 sampled state/offset rows, max absolute error 0
|
|
74
|
+
|
|
75
|
+
Release:
|
|
76
|
+
https://github.com/UBC-FRESH/fresh-cbm/releases/tag/v0.1.0-tsa41
|
|
77
|
+
|
|
78
|
+
`v0.1.0-tsa08` is the second package cache:
|
|
79
|
+
|
|
80
|
+
- 3,761 TSA08 track/age states
|
|
81
|
+
- untreated + `CC@0..49`
|
|
82
|
+
- 50 years, 26 accounts, float64
|
|
83
|
+
- 2.03 GB
|
|
84
|
+
- build 2h05; validation 102 rows, max absolute error 0
|
|
85
|
+
|
|
86
|
+
Release:
|
|
87
|
+
https://github.com/UBC-FRESH/fresh-cbm/releases/tag/v0.1.0-tsa08
|
|
88
|
+
|
|
89
|
+
## Benchmarks
|
|
90
|
+
|
|
91
|
+
`fresh-cbm-bench` measures load, lookup, projection, and storage. On the published
|
|
92
|
+
TSA41 cache, projection over 148,828 blocks took **2.33 s**; TSA08 over 371,565
|
|
93
|
+
blocks took **4.96 s**. See `docs/guides/benchmarks.rst`.
|
|
94
|
+
|
|
95
|
+
## How this project works
|
|
96
|
+
|
|
97
|
+
This project follows the UBC-FRESH dev workflow. Work is planned as phases,
|
|
98
|
+
tasks, and subtasks in `ROADMAP.md`, mirrored in GitHub issues, and recorded in
|
|
99
|
+
`CHANGE_LOG.md`. The agent contract is `AGENTS.md`. Read `AGENTS.md` and
|
|
100
|
+
`ROADMAP.md` before changing anything.
|
|
101
|
+
|
|
102
|
+
## Repository map
|
|
103
|
+
|
|
104
|
+
| Path | Purpose |
|
|
105
|
+
| --- | --- |
|
|
106
|
+
| `AGENTS.md` | Operating contract for coding agents |
|
|
107
|
+
| `ROADMAP.md` | Plan of record and issue tracker map |
|
|
108
|
+
| `CHANGE_LOG.md` | Dated narrative of changes |
|
|
109
|
+
| `docs/` | Sphinx site, published to GitHub Pages |
|
|
110
|
+
| `notes/` | Decisions and focused plans |
|
|
111
|
+
| `fresh_cbm/` | Python client, manifest schema, family contract, and effect projection |
|
|
112
|
+
| `scripts/` | Builder, validator, workflow validator, and dashboard |
|
|
113
|
+
| `tests/` | pytest suite |
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
Apache-2.0. See `LICENSE`.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# fresh-cbm
|
|
2
|
+
|
|
3
|
+
Exact cached libcbm stand-state tables and lookup client for WS4/FEMIC carbon
|
|
4
|
+
analyses.
|
|
5
|
+
|
|
6
|
+
`fresh-cbm` stores the deterministic per-hectare carbon accounts produced by
|
|
7
|
+
libcbm for a declared package and treatment family. Consumers can look up a
|
|
8
|
+
stand state instead of rebuilding a CBM model for every analysis.
|
|
9
|
+
|
|
10
|
+
## Documentation
|
|
11
|
+
|
|
12
|
+
Published Sphinx site:
|
|
13
|
+
|
|
14
|
+
https://ubc-fresh.github.io/fresh-cbm/
|
|
15
|
+
|
|
16
|
+
Start with the cache format, building, and validation guides.
|
|
17
|
+
|
|
18
|
+
## Status
|
|
19
|
+
|
|
20
|
+
Phase P0 (workflow bootstrap and documentation) is complete. `ROADMAP.md` is the
|
|
21
|
+
plan of record; P1 is planned.
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
python -m pip install -e ".[test]"
|
|
27
|
+
fresh-cbm-build --help
|
|
28
|
+
fresh-cbm-validate --help
|
|
29
|
+
fresh-cbm-package --help
|
|
30
|
+
fresh-cbm-bench --help
|
|
31
|
+
fresh-cbm-verify --help
|
|
32
|
+
python -m pytest
|
|
33
|
+
python scripts/dashboard.py
|
|
34
|
+
sphinx-build -b html docs _build/html -W
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The builder and validator require WS4 (`ws4[carbon]`). Pass `--ws4-path` or put
|
|
38
|
+
the WS4 source root on `PYTHONPATH`; the client and tests do not.
|
|
39
|
+
|
|
40
|
+
## Available cache
|
|
41
|
+
|
|
42
|
+
`v0.1.0-tsa41` is the first published table:
|
|
43
|
+
|
|
44
|
+
- 5,273 TSA41 track/age states
|
|
45
|
+
- declared family: untreated + one `CC` event at offsets `0..49`
|
|
46
|
+
- 50 years, 26 carbon accounts, float64
|
|
47
|
+
- 2.85 GB
|
|
48
|
+
- 55 release assets
|
|
49
|
+
- validation: 102 sampled state/offset rows, max absolute error 0
|
|
50
|
+
|
|
51
|
+
Release:
|
|
52
|
+
https://github.com/UBC-FRESH/fresh-cbm/releases/tag/v0.1.0-tsa41
|
|
53
|
+
|
|
54
|
+
`v0.1.0-tsa08` is the second package cache:
|
|
55
|
+
|
|
56
|
+
- 3,761 TSA08 track/age states
|
|
57
|
+
- untreated + `CC@0..49`
|
|
58
|
+
- 50 years, 26 accounts, float64
|
|
59
|
+
- 2.03 GB
|
|
60
|
+
- build 2h05; validation 102 rows, max absolute error 0
|
|
61
|
+
|
|
62
|
+
Release:
|
|
63
|
+
https://github.com/UBC-FRESH/fresh-cbm/releases/tag/v0.1.0-tsa08
|
|
64
|
+
|
|
65
|
+
## Benchmarks
|
|
66
|
+
|
|
67
|
+
`fresh-cbm-bench` measures load, lookup, projection, and storage. On the published
|
|
68
|
+
TSA41 cache, projection over 148,828 blocks took **2.33 s**; TSA08 over 371,565
|
|
69
|
+
blocks took **4.96 s**. See `docs/guides/benchmarks.rst`.
|
|
70
|
+
|
|
71
|
+
## How this project works
|
|
72
|
+
|
|
73
|
+
This project follows the UBC-FRESH dev workflow. Work is planned as phases,
|
|
74
|
+
tasks, and subtasks in `ROADMAP.md`, mirrored in GitHub issues, and recorded in
|
|
75
|
+
`CHANGE_LOG.md`. The agent contract is `AGENTS.md`. Read `AGENTS.md` and
|
|
76
|
+
`ROADMAP.md` before changing anything.
|
|
77
|
+
|
|
78
|
+
## Repository map
|
|
79
|
+
|
|
80
|
+
| Path | Purpose |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| `AGENTS.md` | Operating contract for coding agents |
|
|
83
|
+
| `ROADMAP.md` | Plan of record and issue tracker map |
|
|
84
|
+
| `CHANGE_LOG.md` | Dated narrative of changes |
|
|
85
|
+
| `docs/` | Sphinx site, published to GitHub Pages |
|
|
86
|
+
| `notes/` | Decisions and focused plans |
|
|
87
|
+
| `fresh_cbm/` | Python client, manifest schema, family contract, and effect projection |
|
|
88
|
+
| `scripts/` | Builder, validator, workflow validator, and dashboard |
|
|
89
|
+
| `tests/` | pytest suite |
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
Apache-2.0. See `LICENSE`.
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"""Exact libcbm stand-state cache client."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, cast
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
import pandas as pd
|
|
12
|
+
|
|
13
|
+
from .family import ChainFamily
|
|
14
|
+
from .schema import load_manifest
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True)
|
|
18
|
+
class StateCache:
|
|
19
|
+
"""A loaded exact stand-state table.
|
|
20
|
+
|
|
21
|
+
Parameters
|
|
22
|
+
----------
|
|
23
|
+
root : pathlib.Path
|
|
24
|
+
Cache directory containing ``manifest.json``, ``index.parquet``, and
|
|
25
|
+
``values/``.
|
|
26
|
+
manifest : dict
|
|
27
|
+
Parsed manifest.
|
|
28
|
+
index : pandas.DataFrame
|
|
29
|
+
State index in row order.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
root: Path
|
|
33
|
+
manifest: dict[str, Any]
|
|
34
|
+
index: pd.DataFrame
|
|
35
|
+
|
|
36
|
+
@classmethod
|
|
37
|
+
def load(cls, root: str | Path, *, validate: bool = True) -> StateCache:
|
|
38
|
+
"""Load a cache directory.
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
root : path-like
|
|
43
|
+
Cache directory.
|
|
44
|
+
validate : bool, optional
|
|
45
|
+
Check the index, file set, and array shapes. Defaults to True.
|
|
46
|
+
|
|
47
|
+
Returns
|
|
48
|
+
-------
|
|
49
|
+
StateCache
|
|
50
|
+
The loaded cache.
|
|
51
|
+
"""
|
|
52
|
+
path = Path(root)
|
|
53
|
+
manifest = load_manifest(path / "manifest.json")
|
|
54
|
+
index = pd.read_parquet(path / "index.parquet")
|
|
55
|
+
cache = cls(root=path, manifest=manifest, index=index)
|
|
56
|
+
if validate:
|
|
57
|
+
cache.validate()
|
|
58
|
+
return cache
|
|
59
|
+
|
|
60
|
+
def validate(self) -> None:
|
|
61
|
+
"""Check the index, file set, offsets, and array shapes.
|
|
62
|
+
|
|
63
|
+
Raises
|
|
64
|
+
------
|
|
65
|
+
ValueError
|
|
66
|
+
When the cache is incomplete or inconsistent with its manifest.
|
|
67
|
+
"""
|
|
68
|
+
required = {"state_id", "track_id", "track_name", "age"}
|
|
69
|
+
missing = required - set(self.index.columns)
|
|
70
|
+
if missing:
|
|
71
|
+
raise ValueError(f"cache index is missing columns: {sorted(missing)}")
|
|
72
|
+
states = int(self.manifest["states"])
|
|
73
|
+
if len(self.index) != states:
|
|
74
|
+
raise ValueError(f"cache index has {len(self.index)} rows but manifest says {states}")
|
|
75
|
+
years = self.years
|
|
76
|
+
accounts = len(self.accounts)
|
|
77
|
+
expected = (states, years + 1, accounts)
|
|
78
|
+
family = self.chain_family
|
|
79
|
+
offsets = self.manifest["offsets"]
|
|
80
|
+
if not isinstance(offsets, list):
|
|
81
|
+
raise ValueError("manifest offsets must be a list")
|
|
82
|
+
if family is not None:
|
|
83
|
+
if tuple(int(value) for value in offsets) != family.offsets:
|
|
84
|
+
raise ValueError("chain_family offsets do not match manifest offsets")
|
|
85
|
+
if bool(self.manifest["empty"]) != family.allow_empty:
|
|
86
|
+
raise ValueError("chain_family empty policy does not match manifest")
|
|
87
|
+
files = self.manifest["files"]
|
|
88
|
+
if not isinstance(files, list):
|
|
89
|
+
raise ValueError("manifest files must be a list")
|
|
90
|
+
for name in files:
|
|
91
|
+
if not isinstance(name, str):
|
|
92
|
+
raise ValueError("manifest file names must be strings")
|
|
93
|
+
path = self.root / name
|
|
94
|
+
if not path.is_file():
|
|
95
|
+
raise ValueError(f"cache file is missing: {name}")
|
|
96
|
+
array = np.load(path, mmap_mode="r")
|
|
97
|
+
if array.shape != expected:
|
|
98
|
+
raise ValueError(f"{name} has shape {array.shape}; expected {expected}")
|
|
99
|
+
|
|
100
|
+
def verify_checksums(self, path: str | Path | None = None) -> None:
|
|
101
|
+
"""Verify files against a SHA256SUMS manifest.
|
|
102
|
+
|
|
103
|
+
Parameters
|
|
104
|
+
----------
|
|
105
|
+
path : path-like or None, optional
|
|
106
|
+
Checksum file. Defaults to ``SHA256SUMS`` in the cache root.
|
|
107
|
+
|
|
108
|
+
Raises
|
|
109
|
+
------
|
|
110
|
+
ValueError
|
|
111
|
+
When a file is missing or a digest does not match.
|
|
112
|
+
"""
|
|
113
|
+
source = Path(path) if path is not None else self.root / "SHA256SUMS"
|
|
114
|
+
if not source.is_file():
|
|
115
|
+
raise ValueError(f"checksum file is missing: {source}")
|
|
116
|
+
for line in source.read_text(encoding="utf-8").splitlines():
|
|
117
|
+
if not line.strip():
|
|
118
|
+
continue
|
|
119
|
+
digest, name = line.split(" ", 1)
|
|
120
|
+
target = self.root / name
|
|
121
|
+
if not target.is_file():
|
|
122
|
+
raise ValueError(f"checksum target is missing: {name}")
|
|
123
|
+
actual = hashlib.sha256(target.read_bytes()).hexdigest()
|
|
124
|
+
if actual != digest:
|
|
125
|
+
raise ValueError(f"checksum mismatch: {name}")
|
|
126
|
+
|
|
127
|
+
@property
|
|
128
|
+
def chain_family(self) -> ChainFamily | None:
|
|
129
|
+
"""Return the declared chain family, if the manifest has one.
|
|
130
|
+
|
|
131
|
+
Returns
|
|
132
|
+
-------
|
|
133
|
+
ChainFamily or None
|
|
134
|
+
The family record, or None for a legacy manifest without one.
|
|
135
|
+
"""
|
|
136
|
+
raw = self.manifest.get("chain_family")
|
|
137
|
+
return None if raw is None else ChainFamily.from_manifest(raw)
|
|
138
|
+
|
|
139
|
+
@property
|
|
140
|
+
def accounts(self) -> tuple[str, ...]:
|
|
141
|
+
"""Return the cached account names."""
|
|
142
|
+
values = self.manifest["accounts"]
|
|
143
|
+
if not isinstance(values, list):
|
|
144
|
+
raise ValueError("manifest accounts must be a list")
|
|
145
|
+
return tuple(str(value) for value in values)
|
|
146
|
+
|
|
147
|
+
@property
|
|
148
|
+
def years(self) -> int:
|
|
149
|
+
"""Return the stored horizon length in years."""
|
|
150
|
+
return int(self.manifest["years"])
|
|
151
|
+
|
|
152
|
+
def _row(self, track_id: int, age: int) -> int:
|
|
153
|
+
"""Return the index row for a track and age."""
|
|
154
|
+
rows = self.index
|
|
155
|
+
match = rows[
|
|
156
|
+
(rows["track_id"].astype(int) == int(track_id)) & (rows["age"].astype(int) == int(age))
|
|
157
|
+
]
|
|
158
|
+
if len(match) != 1:
|
|
159
|
+
raise KeyError(f"state not in cache: track={track_id} age={age}")
|
|
160
|
+
return int(match.iloc[0]["state_id"])
|
|
161
|
+
|
|
162
|
+
def array(self, chain_offset: int = -1) -> np.ndarray:
|
|
163
|
+
"""Return the memmapped values for one chain offset.
|
|
164
|
+
|
|
165
|
+
Parameters
|
|
166
|
+
----------
|
|
167
|
+
chain_offset : int, optional
|
|
168
|
+
Single ``CC`` event offset; ``-1`` is untreated.
|
|
169
|
+
|
|
170
|
+
Returns
|
|
171
|
+
-------
|
|
172
|
+
numpy.ndarray
|
|
173
|
+
The cached values with shape ``(states, years + 1, accounts)``.
|
|
174
|
+
"""
|
|
175
|
+
name = "empty.npy" if chain_offset < 0 else f"offset_{chain_offset:02d}.npy"
|
|
176
|
+
return cast(np.ndarray, np.load(self.root / "values" / name, mmap_mode="r"))
|
|
177
|
+
|
|
178
|
+
def lookup_state(self, state_id: int, chain_offset: int = -1) -> np.ndarray:
|
|
179
|
+
"""Return one state's ``(years + 1, accounts)`` array.
|
|
180
|
+
|
|
181
|
+
Parameters
|
|
182
|
+
----------
|
|
183
|
+
state_id : int
|
|
184
|
+
Row in ``index.parquet``.
|
|
185
|
+
chain_offset : int, optional
|
|
186
|
+
Single ``CC`` event offset; ``-1`` is untreated.
|
|
187
|
+
|
|
188
|
+
Returns
|
|
189
|
+
-------
|
|
190
|
+
numpy.ndarray
|
|
191
|
+
The cached accounts.
|
|
192
|
+
"""
|
|
193
|
+
return np.asarray(self.array(chain_offset)[int(state_id)])
|
|
194
|
+
|
|
195
|
+
def lookup(self, track_id: int, age: int, chain_offset: int = -1) -> np.ndarray:
|
|
196
|
+
"""Return one state's ``(years + 1, accounts)`` array.
|
|
197
|
+
|
|
198
|
+
Parameters
|
|
199
|
+
----------
|
|
200
|
+
track_id : int
|
|
201
|
+
Dataset track id.
|
|
202
|
+
age : int
|
|
203
|
+
Initial stand age.
|
|
204
|
+
chain_offset : int, optional
|
|
205
|
+
Single ``CC`` event offset; ``-1`` is untreated.
|
|
206
|
+
|
|
207
|
+
Returns
|
|
208
|
+
-------
|
|
209
|
+
numpy.ndarray
|
|
210
|
+
The cached accounts.
|
|
211
|
+
"""
|
|
212
|
+
return self.lookup_state(self._row(track_id, age), chain_offset)
|
|
213
|
+
|
|
214
|
+
def account(self, track_id: int, age: int, chain_offset: int, account: str) -> np.ndarray:
|
|
215
|
+
"""Return one account series for a state.
|
|
216
|
+
|
|
217
|
+
Parameters
|
|
218
|
+
----------
|
|
219
|
+
track_id : int
|
|
220
|
+
Dataset track id.
|
|
221
|
+
age : int
|
|
222
|
+
Initial stand age.
|
|
223
|
+
chain_offset : int
|
|
224
|
+
Single ``CC`` event offset; ``-1`` is untreated.
|
|
225
|
+
account : str
|
|
226
|
+
Account name.
|
|
227
|
+
|
|
228
|
+
Returns
|
|
229
|
+
-------
|
|
230
|
+
numpy.ndarray
|
|
231
|
+
The account values over all stored years.
|
|
232
|
+
"""
|
|
233
|
+
try:
|
|
234
|
+
column = self.accounts.index(account)
|
|
235
|
+
except ValueError as exc:
|
|
236
|
+
raise KeyError(f"account not in cache: {account}") from exc
|
|
237
|
+
return self.lookup(track_id, age, chain_offset)[:, column]
|