proofroot 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.
- proofroot-0.1.0/.gitignore +8 -0
- proofroot-0.1.0/LICENSE +202 -0
- proofroot-0.1.0/PKG-INFO +68 -0
- proofroot-0.1.0/README.md +49 -0
- proofroot-0.1.0/pyproject.toml +38 -0
- proofroot-0.1.0/src/proofroot/__init__.py +54 -0
- proofroot-0.1.0/src/proofroot/canonical.py +91 -0
- proofroot-0.1.0/src/proofroot/phase.py +74 -0
- proofroot-0.1.0/src/proofroot/rng.py +122 -0
- proofroot-0.1.0/tests/test_canonical.py +96 -0
- proofroot-0.1.0/tests/test_semantics.py +158 -0
- proofroot-0.1.0/tests/test_vectors.py +51 -0
- proofroot-0.1.0/vectors/canonical_vectors.json +132 -0
- proofroot-0.1.0/vectors/evidencecore_rng_v1.json +59 -0
- proofroot-0.1.0/vectors/generate_canonical_vectors.py +85 -0
- proofroot-0.1.0/vectors/generate_vectors.jl +87 -0
proofroot-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.
|
proofroot-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: proofroot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Language-neutral trust core for reproducible simulation: named RNG stream derivation, run phases, evidence tiers, canonical serialization.
|
|
5
|
+
Project-URL: Homepage, https://github.com/hzshen88/newlife
|
|
6
|
+
Project-URL: Repository, https://github.com/hzshen88/newlife
|
|
7
|
+
Project-URL: Documentation, https://github.com/hzshen88/newlife/tree/main/packages/proofroot
|
|
8
|
+
Author: hzshen88
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: canonical-serialization,provenance,reproducibility,rng-streams,trust-core
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# proofroot
|
|
21
|
+
|
|
22
|
+
Language-neutral trust core for reproducible simulation. Zero dependencies,
|
|
23
|
+
zero domain semantics.
|
|
24
|
+
|
|
25
|
+
## Install and use
|
|
26
|
+
|
|
27
|
+
Requires Python 3.12 or newer.
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
python -m pip install proofroot
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import random
|
|
35
|
+
|
|
36
|
+
from proofroot import EVIDENCECORE_RNG_V1, RngBank, canonical_bytes
|
|
37
|
+
|
|
38
|
+
bank = RngBank(
|
|
39
|
+
root_seed=42,
|
|
40
|
+
names=["mutation", "selection"],
|
|
41
|
+
rng_strategy=EVIDENCECORE_RNG_V1,
|
|
42
|
+
stream_factory=random.Random,
|
|
43
|
+
)
|
|
44
|
+
mutation_rng = bank.rng_stream("mutation")
|
|
45
|
+
print(bank.stream_seeds())
|
|
46
|
+
print(mutation_rng.random())
|
|
47
|
+
print(canonical_bytes({"answer": 42}))
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Everything every simulation community needs and none of what any single one
|
|
51
|
+
wants to own: named RNG stream seed derivation (`evidencecore-rng-v1`), bank
|
|
52
|
+
semantics invariants (declared streams, lowercase normalization, forward-only),
|
|
53
|
+
run phases, evidence tier vocabulary (exploration / confirmatory / unknown —
|
|
54
|
+
missing fields default to unknown, never to confirmatory), and a canonical
|
|
55
|
+
serialization spec (RFC 8785 structural rules; IEEE754 bit-pattern float
|
|
56
|
+
comparison) with cross-language test vectors.
|
|
57
|
+
|
|
58
|
+
**Charter boundary (frozen):** the cross-language contract ends at the derived
|
|
59
|
+
seed. Seed derivation is byte-defined over SHA-256 and portable; random
|
|
60
|
+
*sequences* depend on the host generator (Julia's Xoshiro, Python's choice)
|
|
61
|
+
and are recorded in the run manifest, not standardized.
|
|
62
|
+
|
|
63
|
+
**Oracle:** `EvidenceCore.jl` in the [ParaLife](https://github.com/hzshen88/paralife)
|
|
64
|
+
monorepo is the frozen oracle generating this package's cross-language test
|
|
65
|
+
vectors. ParaLife's legacy compatibility layers (legacy encodings, UPPER-CASE
|
|
66
|
+
phase spellings) are deliberately **not** ported here.
|
|
67
|
+
|
|
68
|
+
Design rationale: [proposal §5.10](https://github.com/hzshen88/newlife/blob/main/docs/design/proposal.md).
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# proofroot
|
|
2
|
+
|
|
3
|
+
Language-neutral trust core for reproducible simulation. Zero dependencies,
|
|
4
|
+
zero domain semantics.
|
|
5
|
+
|
|
6
|
+
## Install and use
|
|
7
|
+
|
|
8
|
+
Requires Python 3.12 or newer.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
python -m pip install proofroot
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
import random
|
|
16
|
+
|
|
17
|
+
from proofroot import EVIDENCECORE_RNG_V1, RngBank, canonical_bytes
|
|
18
|
+
|
|
19
|
+
bank = RngBank(
|
|
20
|
+
root_seed=42,
|
|
21
|
+
names=["mutation", "selection"],
|
|
22
|
+
rng_strategy=EVIDENCECORE_RNG_V1,
|
|
23
|
+
stream_factory=random.Random,
|
|
24
|
+
)
|
|
25
|
+
mutation_rng = bank.rng_stream("mutation")
|
|
26
|
+
print(bank.stream_seeds())
|
|
27
|
+
print(mutation_rng.random())
|
|
28
|
+
print(canonical_bytes({"answer": 42}))
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Everything every simulation community needs and none of what any single one
|
|
32
|
+
wants to own: named RNG stream seed derivation (`evidencecore-rng-v1`), bank
|
|
33
|
+
semantics invariants (declared streams, lowercase normalization, forward-only),
|
|
34
|
+
run phases, evidence tier vocabulary (exploration / confirmatory / unknown —
|
|
35
|
+
missing fields default to unknown, never to confirmatory), and a canonical
|
|
36
|
+
serialization spec (RFC 8785 structural rules; IEEE754 bit-pattern float
|
|
37
|
+
comparison) with cross-language test vectors.
|
|
38
|
+
|
|
39
|
+
**Charter boundary (frozen):** the cross-language contract ends at the derived
|
|
40
|
+
seed. Seed derivation is byte-defined over SHA-256 and portable; random
|
|
41
|
+
*sequences* depend on the host generator (Julia's Xoshiro, Python's choice)
|
|
42
|
+
and are recorded in the run manifest, not standardized.
|
|
43
|
+
|
|
44
|
+
**Oracle:** `EvidenceCore.jl` in the [ParaLife](https://github.com/hzshen88/paralife)
|
|
45
|
+
monorepo is the frozen oracle generating this package's cross-language test
|
|
46
|
+
vectors. ParaLife's legacy compatibility layers (legacy encodings, UPPER-CASE
|
|
47
|
+
phase spellings) are deliberately **not** ported here.
|
|
48
|
+
|
|
49
|
+
Design rationale: [proposal §5.10](https://github.com/hzshen88/newlife/blob/main/docs/design/proposal.md).
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "proofroot"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Language-neutral trust core for reproducible simulation: named RNG stream derivation, run phases, evidence tiers, canonical serialization."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "hzshen88" }]
|
|
10
|
+
keywords = ["reproducibility", "provenance", "rng-streams",
|
|
11
|
+
"canonical-serialization", "trust-core"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Intended Audience :: Science/Research",
|
|
15
|
+
"Natural Language :: English",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
18
|
+
]
|
|
19
|
+
dependencies = []
|
|
20
|
+
|
|
21
|
+
[build-system]
|
|
22
|
+
requires = ["hatchling"]
|
|
23
|
+
build-backend = "hatchling.build"
|
|
24
|
+
|
|
25
|
+
[tool.hatch.build.targets.wheel]
|
|
26
|
+
packages = ["src/proofroot"]
|
|
27
|
+
|
|
28
|
+
[tool.hatch.build.targets.wheel.force-include]
|
|
29
|
+
"vectors/canonical_vectors.json" = "proofroot/vectors/canonical_vectors.json"
|
|
30
|
+
"vectors/evidencecore_rng_v1.json" = "proofroot/vectors/evidencecore_rng_v1.json"
|
|
31
|
+
|
|
32
|
+
[dependency-groups]
|
|
33
|
+
dev = ["pytest>=8"]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/hzshen88/newlife"
|
|
37
|
+
Repository = "https://github.com/hzshen88/newlife"
|
|
38
|
+
Documentation = "https://github.com/hzshen88/newlife/tree/main/packages/proofroot"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""proofroot — language-neutral trust core for reproducible simulation.
|
|
2
|
+
|
|
3
|
+
Scope (frozen charter, see docs/design/proposal.md §5.10):
|
|
4
|
+
- D1 current encoding (`evidencecore-rng-v1`) named RNG stream seed derivation
|
|
5
|
+
- D4 bank semantics invariants (declared streams, lowercase normalization,
|
|
6
|
+
name regex, forward-only, seed snapshots as provenance)
|
|
7
|
+
- D2 RunPhase + terminal-state decision; D5 evidence tier vocabulary
|
|
8
|
+
(exploration/confirmatory/unknown; missing fields default to unknown,
|
|
9
|
+
never to confirmatory)
|
|
10
|
+
- Canonical serialization spec (RFC 8785 structural rules, IEEE754 bit-pattern
|
|
11
|
+
float comparison) + cross-language test vectors
|
|
12
|
+
|
|
13
|
+
Excluded on purpose: Effect-typed trace schemas, attribution/compare logic,
|
|
14
|
+
manifest assembly, and all domain semantics. Legacy ParaLife compatibility
|
|
15
|
+
layers (parcells-rng-v1, parreact-rng-v1, parworlds-rng-v1 string encodings,
|
|
16
|
+
legacy UPPER-CASE phase spellings) stay in ParaLife's EvidenceCore.jl and are
|
|
17
|
+
deliberately NOT ported here.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from .canonical import bits_to_float, canonical_bytes, float_to_bits
|
|
21
|
+
from .phase import (
|
|
22
|
+
EVIDENCE_TIER_CONFIRMATORY,
|
|
23
|
+
EVIDENCE_TIER_EXPLORATION,
|
|
24
|
+
EVIDENCE_TIER_UNKNOWN,
|
|
25
|
+
EVIDENCE_TIERS,
|
|
26
|
+
RunPhase,
|
|
27
|
+
is_terminal,
|
|
28
|
+
parse_phase,
|
|
29
|
+
resolve_evidence_tier,
|
|
30
|
+
)
|
|
31
|
+
from .rng import (
|
|
32
|
+
EVIDENCECORE_RNG_V1,
|
|
33
|
+
RngBank,
|
|
34
|
+
RngDerivationError,
|
|
35
|
+
derive_stream_seed,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
__all__ = [
|
|
39
|
+
"EVIDENCECORE_RNG_V1",
|
|
40
|
+
"bits_to_float",
|
|
41
|
+
"canonical_bytes",
|
|
42
|
+
"float_to_bits",
|
|
43
|
+
"EVIDENCE_TIER_CONFIRMATORY",
|
|
44
|
+
"EVIDENCE_TIER_EXPLORATION",
|
|
45
|
+
"EVIDENCE_TIER_UNKNOWN",
|
|
46
|
+
"EVIDENCE_TIERS",
|
|
47
|
+
"RunPhase",
|
|
48
|
+
"RngBank",
|
|
49
|
+
"RngDerivationError",
|
|
50
|
+
"derive_stream_seed",
|
|
51
|
+
"is_terminal",
|
|
52
|
+
"parse_phase",
|
|
53
|
+
"resolve_evidence_tier",
|
|
54
|
+
]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Canonical serialization spec + canonicalization function (§5.9).
|
|
2
|
+
|
|
3
|
+
The 0th asset of any cross-language byte-level trace comparison is a
|
|
4
|
+
canonical form that does not depend on the host language's float
|
|
5
|
+
formatting. Rules (docs/design/proposal.md §5.9):
|
|
6
|
+
|
|
7
|
+
- **Structural layer** — the ready-made parts of RFC 8785 (JCS): object keys
|
|
8
|
+
sorted, UTF-8 output, no insignificant whitespace. Key order is Unicode
|
|
9
|
+
*code point* order (the proposal pins this; note RFC 8785 itself sorts by
|
|
10
|
+
UTF-16 code units — the two differ only for keys mixing astral planes with
|
|
11
|
+
U+E000..U+FFFF, and proofroot's spec chooses code point order).
|
|
12
|
+
- **Floats bypass text representation instead of praying to shortest
|
|
13
|
+
round-trip**: numeric comparison fields in a trace carry the IEEE754 binary
|
|
14
|
+
64 bit pattern (16-digit lowercase hex via `float_to_bits`); human-readable
|
|
15
|
+
decimal may accompany as a comment field, but byte comparison only sees the
|
|
16
|
+
hex. Bit patterns are identical by definition across languages.
|
|
17
|
+
- Consequently `canonical_bytes` **rejects raw floats** — a float that reached
|
|
18
|
+
the canonicalizer would be about to be formatted by host rules, which is
|
|
19
|
+
exactly the failure the spec exists to prevent. Callers pre-encode floats.
|
|
20
|
+
|
|
21
|
+
The companion vectors (`vectors/canonical_vectors.json`, regenerated by
|
|
22
|
+
`vectors/generate_canonical_vectors.py`) pin: key ordering incl. non-ASCII
|
|
23
|
+
keys, string escaping, and the classic float traps (-0.0, subnormals, NaN
|
|
24
|
+
payloads, infinities, 0.1).
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import json
|
|
30
|
+
import struct
|
|
31
|
+
|
|
32
|
+
__all__ = ["canonical_bytes", "float_to_bits", "bits_to_float"]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def float_to_bits(value: float) -> str:
|
|
36
|
+
"""IEEE754 binary64 bit pattern of ``value`` as '0x' + 16 lowercase hex.
|
|
37
|
+
|
|
38
|
+
This is the *only* sanctioned float representation in comparison
|
|
39
|
+
fields: -0.0, subnormals and NaN payloads round-trip exactly.
|
|
40
|
+
"""
|
|
41
|
+
return "0x" + struct.pack(">d", value).hex()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def bits_to_float(bits: str) -> float:
|
|
45
|
+
"""Inverse of `float_to_bits` (accepts with or without the '0x' prefix)."""
|
|
46
|
+
return struct.unpack(">d", bytes.fromhex(bits.removeprefix("0x")))[0]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _encode(value, level_key: str | None):
|
|
50
|
+
# bool before int: bool is an int subclass in Python.
|
|
51
|
+
if value is None or value is True or value is False:
|
|
52
|
+
return value
|
|
53
|
+
if isinstance(value, int):
|
|
54
|
+
return value
|
|
55
|
+
if isinstance(value, float):
|
|
56
|
+
raise TypeError(
|
|
57
|
+
"raw float in canonical input; pre-encode comparison fields with "
|
|
58
|
+
f"float_to_bits (got {value!r}"
|
|
59
|
+
+ (f" at key {level_key!r}" if level_key is not None else "")
|
|
60
|
+
+ ")"
|
|
61
|
+
)
|
|
62
|
+
if isinstance(value, str):
|
|
63
|
+
return value
|
|
64
|
+
if isinstance(value, list):
|
|
65
|
+
return [_encode(item, level_key) for item in value]
|
|
66
|
+
if isinstance(value, dict):
|
|
67
|
+
out = {}
|
|
68
|
+
for key in sorted(value):
|
|
69
|
+
if not isinstance(key, str):
|
|
70
|
+
raise TypeError(f"canonical object keys must be strings, got {key!r}")
|
|
71
|
+
out[key] = _encode(value[key], key)
|
|
72
|
+
return out
|
|
73
|
+
raise TypeError(f"value not representable in canonical form: {value!r}")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def canonical_bytes(value) -> bytes:
|
|
77
|
+
"""Canonical serialization: JCS structural rules, floats pre-encoded.
|
|
78
|
+
|
|
79
|
+
Deterministic byte output for any JSON-compatible value tree whose
|
|
80
|
+
numeric comparison fields already carry IEEE754 bit-pattern hex strings
|
|
81
|
+
(see `float_to_bits`). Raises TypeError on raw floats, non-string keys
|
|
82
|
+
and non-JSON types — those are spec violations, not formatting choices.
|
|
83
|
+
"""
|
|
84
|
+
encoded = _encode(value, None)
|
|
85
|
+
text = json.dumps(
|
|
86
|
+
encoded,
|
|
87
|
+
ensure_ascii=False, # UTF-8, minimal escaping per JCS
|
|
88
|
+
separators=(",", ":"), # no insignificant whitespace
|
|
89
|
+
allow_nan=False,
|
|
90
|
+
)
|
|
91
|
+
return text.encode("utf-8")
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""D2 RunPhase + terminal-state decision, D5 evidence tier vocabulary.
|
|
2
|
+
|
|
3
|
+
Port of EvidenceCore.jl's D2/D5. Per §5.10 discipline 2, the legacy UPPER-CASE
|
|
4
|
+
phase spellings ("COMPLETED"/"FAILED"/…) are deliberately NOT ported — they
|
|
5
|
+
exist to read pre-unification ParaLife run artifacts, whose reason to exist is
|
|
6
|
+
not portable. New artifacts serialize TitleCase.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import enum
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class RunPhase(str, enum.Enum):
|
|
15
|
+
"""The unified 8-value TitleCase run lifecycle phases (D2).
|
|
16
|
+
|
|
17
|
+
Only the enum values and terminality are shared semantics; the transition
|
|
18
|
+
map stays with each host's run lifecycle (Parcells' 6-step and Parworlds'
|
|
19
|
+
8-step lifecycles were deliberately not unified in the first generation).
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
PLANNED = "Planned"
|
|
23
|
+
VALIDATED = "Validated"
|
|
24
|
+
INITIALIZING = "Initializing"
|
|
25
|
+
RUNNING = "Running"
|
|
26
|
+
ASSAYING = "Assaying"
|
|
27
|
+
FINALIZING = "Finalizing"
|
|
28
|
+
COMPLETED = "Completed"
|
|
29
|
+
FAILED = "Failed"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def is_terminal(phase: RunPhase) -> bool:
|
|
33
|
+
"""A phase is an irreversible terminal state iff it is Completed or Failed."""
|
|
34
|
+
return phase is RunPhase.COMPLETED or phase is RunPhase.FAILED
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def parse_phase(name: str) -> RunPhase:
|
|
38
|
+
"""Resolve a phase from its serialized (TitleCase) string form.
|
|
39
|
+
|
|
40
|
+
Raises on anything else — including the legacy UPPER-CASE spellings, which
|
|
41
|
+
are a ParaLife-local compatibility layer and intentionally not accepted
|
|
42
|
+
here.
|
|
43
|
+
"""
|
|
44
|
+
try:
|
|
45
|
+
return RunPhase(name)
|
|
46
|
+
except ValueError:
|
|
47
|
+
raise ValueError(f"unknown run phase {name!r}") from None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# ── D5: evidence tier vocabulary (cross-program governance, ADR-0016) ────────
|
|
51
|
+
# exploration and unknown may never be cited as evidence; confirmatory must be
|
|
52
|
+
# declared explicitly. The safety direction: a missing field degrades to
|
|
53
|
+
# unknown — never to confirmatory — so "forgot to declare" fails closed.
|
|
54
|
+
|
|
55
|
+
EVIDENCE_TIER_EXPLORATION = "exploration"
|
|
56
|
+
EVIDENCE_TIER_CONFIRMATORY = "confirmatory"
|
|
57
|
+
EVIDENCE_TIER_UNKNOWN = "unknown"
|
|
58
|
+
EVIDENCE_TIERS = frozenset(
|
|
59
|
+
{EVIDENCE_TIER_EXPLORATION, EVIDENCE_TIER_CONFIRMATORY, EVIDENCE_TIER_UNKNOWN}
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def resolve_evidence_tier(declared: str | None) -> str:
|
|
64
|
+
"""Resolve the evidence tier of a run artifact.
|
|
65
|
+
|
|
66
|
+
``None``/missing degrades to ``unknown`` (fail closed). A declared tier
|
|
67
|
+
must be a member of the vocabulary — a typo must raise, not silently pass
|
|
68
|
+
as either citable or uncitable.
|
|
69
|
+
"""
|
|
70
|
+
if declared is None:
|
|
71
|
+
return EVIDENCE_TIER_UNKNOWN
|
|
72
|
+
if declared not in EVIDENCE_TIERS:
|
|
73
|
+
raise ValueError(f"unknown evidence tier: {declared!r}")
|
|
74
|
+
return declared
|