erisml-compiler 0.4.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.
Files changed (116) hide show
  1. erisml_compiler-0.4.0/LICENSE +21 -0
  2. erisml_compiler-0.4.0/PKG-INFO +265 -0
  3. erisml_compiler-0.4.0/README.md +216 -0
  4. erisml_compiler-0.4.0/pyproject.toml +84 -0
  5. erisml_compiler-0.4.0/setup.cfg +4 -0
  6. erisml_compiler-0.4.0/src/erisml_compiler/__init__.py +8 -0
  7. erisml_compiler-0.4.0/src/erisml_compiler/annotation/__init__.py +32 -0
  8. erisml_compiler-0.4.0/src/erisml_compiler/annotation/base.py +54 -0
  9. erisml_compiler-0.4.0/src/erisml_compiler/annotation/critic.py +183 -0
  10. erisml_compiler-0.4.0/src/erisml_compiler/annotation/llm_extractor.py +416 -0
  11. erisml_compiler-0.4.0/src/erisml_compiler/annotation/mock_extractor.py +409 -0
  12. erisml_compiler-0.4.0/src/erisml_compiler/annotation/probe_extractor.py +171 -0
  13. erisml_compiler-0.4.0/src/erisml_compiler/annotation/rule_extractor.py +263 -0
  14. erisml_compiler-0.4.0/src/erisml_compiler/audit/__init__.py +16 -0
  15. erisml_compiler-0.4.0/src/erisml_compiler/audit/artifact.py +95 -0
  16. erisml_compiler-0.4.0/src/erisml_compiler/audit/hash_chain.py +64 -0
  17. erisml_compiler-0.4.0/src/erisml_compiler/audit/provenance.py +25 -0
  18. erisml_compiler-0.4.0/src/erisml_compiler/calibration/__init__.py +56 -0
  19. erisml_compiler-0.4.0/src/erisml_compiler/calibration/adversarial_heads.py +77 -0
  20. erisml_compiler-0.4.0/src/erisml_compiler/calibration/bond_index.py +62 -0
  21. erisml_compiler-0.4.0/src/erisml_compiler/calibration/dataset.py +97 -0
  22. erisml_compiler-0.4.0/src/erisml_compiler/calibration/losses.py +110 -0
  23. erisml_compiler-0.4.0/src/erisml_compiler/calibration/probe_head.py +155 -0
  24. erisml_compiler-0.4.0/src/erisml_compiler/calibration/train.py +214 -0
  25. erisml_compiler-0.4.0/src/erisml_compiler/canonicalizer/__init__.py +29 -0
  26. erisml_compiler-0.4.0/src/erisml_compiler/canonicalizer/base.py +68 -0
  27. erisml_compiler-0.4.0/src/erisml_compiler/canonicalizer/labse.py +109 -0
  28. erisml_compiler-0.4.0/src/erisml_compiler/canonicalizer/registry.py +85 -0
  29. erisml_compiler-0.4.0/src/erisml_compiler/cli.py +546 -0
  30. erisml_compiler-0.4.0/src/erisml_compiler/correction/__init__.py +26 -0
  31. erisml_compiler-0.4.0/src/erisml_compiler/correction/corrector.py +237 -0
  32. erisml_compiler-0.4.0/src/erisml_compiler/correction/diff.py +166 -0
  33. erisml_compiler-0.4.0/src/erisml_compiler/delta/__init__.py +44 -0
  34. erisml_compiler-0.4.0/src/erisml_compiler/delta/compare.py +180 -0
  35. erisml_compiler-0.4.0/src/erisml_compiler/delta/equivariance.py +219 -0
  36. erisml_compiler-0.4.0/src/erisml_compiler/delta/failure_modes.py +225 -0
  37. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/__init__.py +18 -0
  38. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/base.py +50 -0
  39. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/dag.py +129 -0
  40. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/modules/__init__.py +31 -0
  41. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/modules/_helpers.py +110 -0
  42. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/modules/autonomy.py +50 -0
  43. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/modules/care.py +50 -0
  44. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/modules/epistemic.py +34 -0
  45. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/modules/externality.py +44 -0
  46. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/modules/fairness.py +27 -0
  47. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/modules/fidelity.py +81 -0
  48. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/modules/harm.py +23 -0
  49. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/modules/legitimacy.py +32 -0
  50. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/modules/repair.py +69 -0
  51. erisml_compiler-0.4.0/src/erisml_compiler/em_dag/modules/rights.py +27 -0
  52. erisml_compiler-0.4.0/src/erisml_compiler/erisml_backend/__init__.py +5 -0
  53. erisml_compiler-0.4.0/src/erisml_compiler/erisml_backend/codegen.py +27 -0
  54. erisml_compiler-0.4.0/src/erisml_compiler/erisml_backend/deme_bridge.py +150 -0
  55. erisml_compiler-0.4.0/src/erisml_compiler/evaluation/__init__.py +6 -0
  56. erisml_compiler-0.4.0/src/erisml_compiler/evaluation/conflict_detector.py +56 -0
  57. erisml_compiler-0.4.0/src/erisml_compiler/evaluation/moral_vector.py +43 -0
  58. erisml_compiler-0.4.0/src/erisml_compiler/evaluation/tensor_builder.py +49 -0
  59. erisml_compiler-0.4.0/src/erisml_compiler/export/__init__.py +6 -0
  60. erisml_compiler-0.4.0/src/erisml_compiler/export/erisml_export.py +14 -0
  61. erisml_compiler-0.4.0/src/erisml_compiler/export/json_export.py +21 -0
  62. erisml_compiler-0.4.0/src/erisml_compiler/export/rlef.py +53 -0
  63. erisml_compiler-0.4.0/src/erisml_compiler/fsm/__init__.py +21 -0
  64. erisml_compiler-0.4.0/src/erisml_compiler/fsm/commitment_fsm.py +95 -0
  65. erisml_compiler-0.4.0/src/erisml_compiler/fsm/consent_fsm.py +39 -0
  66. erisml_compiler-0.4.0/src/erisml_compiler/fsm/legitimacy_fsm.py +74 -0
  67. erisml_compiler-0.4.0/src/erisml_compiler/ingestion/__init__.py +5 -0
  68. erisml_compiler-0.4.0/src/erisml_compiler/ingestion/structured_loader.py +63 -0
  69. erisml_compiler-0.4.0/src/erisml_compiler/ingestion/text_loader.py +24 -0
  70. erisml_compiler-0.4.0/src/erisml_compiler/ir/__init__.py +40 -0
  71. erisml_compiler-0.4.0/src/erisml_compiler/ir/schemas.py +397 -0
  72. erisml_compiler-0.4.0/src/erisml_compiler/monitor/__init__.py +45 -0
  73. erisml_compiler-0.4.0/src/erisml_compiler/monitor/activation_probe.py +145 -0
  74. erisml_compiler-0.4.0/src/erisml_compiler/monitor/base.py +98 -0
  75. erisml_compiler-0.4.0/src/erisml_compiler/monitor/huggingface_source.py +233 -0
  76. erisml_compiler-0.4.0/src/erisml_compiler/monitor/ieip_monitor.py +159 -0
  77. erisml_compiler-0.4.0/src/erisml_compiler/monitor/mock_source.py +108 -0
  78. erisml_compiler-0.4.0/src/erisml_compiler/monitor/remote_source.py +260 -0
  79. erisml_compiler-0.4.0/src/erisml_compiler/ontology/canonical_forms.yaml +38 -0
  80. erisml_compiler-0.4.0/src/erisml_compiler/ontology/commitments.yaml +17 -0
  81. erisml_compiler-0.4.0/src/erisml_compiler/ontology/moral_dimensions.yaml +32 -0
  82. erisml_compiler-0.4.0/src/erisml_compiler/ontology/roles.yaml +15 -0
  83. erisml_compiler-0.4.0/src/erisml_compiler/pipeline/__init__.py +4 -0
  84. erisml_compiler-0.4.0/src/erisml_compiler/pipeline/orchestrator.py +216 -0
  85. erisml_compiler-0.4.0/src/erisml_compiler/segmentation/__init__.py +4 -0
  86. erisml_compiler-0.4.0/src/erisml_compiler/segmentation/segmenter.py +62 -0
  87. erisml_compiler-0.4.0/src/erisml_compiler/silicon/__init__.py +44 -0
  88. erisml_compiler-0.4.0/src/erisml_compiler/silicon/fixed_point.py +79 -0
  89. erisml_compiler-0.4.0/src/erisml_compiler/silicon/hls_emit.py +387 -0
  90. erisml_compiler-0.4.0/src/erisml_compiler/streaming/__init__.py +5 -0
  91. erisml_compiler-0.4.0/src/erisml_compiler/streaming/captioner.py +74 -0
  92. erisml_compiler-0.4.0/src/erisml_compiler/streaming/streamer.py +119 -0
  93. erisml_compiler-0.4.0/src/erisml_compiler/tiers.py +91 -0
  94. erisml_compiler-0.4.0/src/erisml_compiler/viz/__init__.py +5 -0
  95. erisml_compiler-0.4.0/src/erisml_compiler/viz/html_report.py +139 -0
  96. erisml_compiler-0.4.0/src/erisml_compiler/viz/timeline_plot.py +44 -0
  97. erisml_compiler-0.4.0/src/erisml_compiler.egg-info/PKG-INFO +265 -0
  98. erisml_compiler-0.4.0/src/erisml_compiler.egg-info/SOURCES.txt +114 -0
  99. erisml_compiler-0.4.0/src/erisml_compiler.egg-info/dependency_links.txt +1 -0
  100. erisml_compiler-0.4.0/src/erisml_compiler.egg-info/entry_points.txt +2 -0
  101. erisml_compiler-0.4.0/src/erisml_compiler.egg-info/requires.txt +37 -0
  102. erisml_compiler-0.4.0/src/erisml_compiler.egg-info/top_level.txt +1 -0
  103. erisml_compiler-0.4.0/tests/test_calibration.py +190 -0
  104. erisml_compiler-0.4.0/tests/test_canonicalizer.py +90 -0
  105. erisml_compiler-0.4.0/tests/test_cli_monitor.py +134 -0
  106. erisml_compiler-0.4.0/tests/test_correction.py +178 -0
  107. erisml_compiler-0.4.0/tests/test_critic.py +75 -0
  108. erisml_compiler-0.4.0/tests/test_delta.py +312 -0
  109. erisml_compiler-0.4.0/tests/test_em_dag.py +73 -0
  110. erisml_compiler-0.4.0/tests/test_export.py +44 -0
  111. erisml_compiler-0.4.0/tests/test_fsm.py +45 -0
  112. erisml_compiler-0.4.0/tests/test_ir_schemas.py +57 -0
  113. erisml_compiler-0.4.0/tests/test_llm_extractor.py +105 -0
  114. erisml_compiler-0.4.0/tests/test_monitor.py +201 -0
  115. erisml_compiler-0.4.0/tests/test_pipeline.py +83 -0
  116. erisml_compiler-0.4.0/tests/test_silicon.py +139 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Andrew H. Bond
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,265 @@
1
+ Metadata-Version: 2.4
2
+ Name: erisml-compiler
3
+ Version: 0.4.0
4
+ Summary: Structure-preserving compiler from natural language to ErisML
5
+ Author-email: "Andrew H. Bond" <andrew.bond@sjsu.edu>
6
+ License: MIT
7
+ Keywords: ethics,ai-safety,geometric-ethics,moral-reasoning,compiler,nlp
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: pydantic>=2.5
19
+ Requires-Dist: click>=8.1
20
+ Requires-Dist: pyyaml>=6.0
21
+ Requires-Dist: structlog>=24.1
22
+ Provides-Extra: llm
23
+ Requires-Dist: openai>=1.30; extra == "llm"
24
+ Requires-Dist: httpx>=0.27; extra == "llm"
25
+ Provides-Extra: ml
26
+ Requires-Dist: sentence-transformers>=2.7; extra == "ml"
27
+ Requires-Dist: numpy>=1.24; extra == "ml"
28
+ Provides-Extra: calibration
29
+ Requires-Dist: torch>=2.1; extra == "calibration"
30
+ Requires-Dist: sentence-transformers>=2.7; extra == "calibration"
31
+ Requires-Dist: numpy>=1.24; extra == "calibration"
32
+ Requires-Dist: tqdm>=4.66; extra == "calibration"
33
+ Provides-Extra: monitor
34
+ Requires-Dist: torch>=2.1; extra == "monitor"
35
+ Requires-Dist: transformers>=4.40; extra == "monitor"
36
+ Requires-Dist: numpy>=1.24; extra == "monitor"
37
+ Requires-Dist: paramiko>=3.4; extra == "monitor"
38
+ Provides-Extra: test
39
+ Requires-Dist: pytest>=8.0; extra == "test"
40
+ Requires-Dist: pytest-cov>=5.0; extra == "test"
41
+ Provides-Extra: dev
42
+ Requires-Dist: black>=24.0; extra == "dev"
43
+ Requires-Dist: ruff>=0.5; extra == "dev"
44
+ Requires-Dist: mypy>=1.10; extra == "dev"
45
+ Provides-Extra: notebook
46
+ Requires-Dist: jupyter>=1.0; extra == "notebook"
47
+ Requires-Dist: matplotlib>=3.8; extra == "notebook"
48
+ Dynamic: license-file
49
+
50
+ # ErisML Compiler
51
+
52
+ [![CI](https://github.com/ahb-sjsu/erisml-compiler/actions/workflows/ci.yml/badge.svg)](https://github.com/ahb-sjsu/erisml-compiler/actions/workflows/ci.yml)
53
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
54
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
55
+ [![Pydantic v2](https://img.shields.io/badge/pydantic-v2-green.svg)](https://docs.pydantic.dev/)
56
+ [![Schema](https://img.shields.io/badge/IR%20schema-erisml__compiler__ir__v0.1-orange.svg)](SCOPE.md)
57
+ [![Tests](https://img.shields.io/badge/tests-142%20passing-brightgreen.svg)](#status)
58
+ [![Status: Alpha](https://img.shields.io/badge/status-alpha-red.svg)](SCOPE.md)
59
+ [![PyPI](https://img.shields.io/pypi/v/erisml-compiler.svg)](https://pypi.org/project/erisml-compiler/)
60
+
61
+ A structure-preserving compiler from natural-language moral material into a
62
+ canonical **ErisML Intermediate Representation** (IR) that can be evaluated by
63
+ DEME, exported for RLEF training, audited as a structured trace, and
64
+ introspected by the I-EIP Monitor's three lenses.
65
+
66
+ The compiler operationalises the thesis that **moral reasoning requires
67
+ structure-preserving representation before decision contraction**. A scalar
68
+ "good / bad / safe / unsafe" label discards the dimensions that justify or
69
+ defeat a candidate action: who the stakeholders are, what commitments bind
70
+ them, which authorities are legitimate, who bears imposed risk. The compiler
71
+ preserves this tensorial structure as a first-class object, then closes the
72
+ loop by inspecting whether the text output and the model's internal state
73
+ actually agree about it.
74
+
75
+ See `ErisML-Compiler.md` for the full design spec (31 sections) and `SCOPE.md`
76
+ for what each phase actually delivers versus what is deferred. Current `main`
77
+ covers Phases 1–4 (IR + DEME + calibration + silicon emitters + I-EIP
78
+ Monitor); the production web app and silicon hardware verification are
79
+ deferred.
80
+
81
+ ## Quick start
82
+
83
+ ```bash
84
+ # Install from PyPI
85
+ pip install erisml-compiler # core
86
+ pip install 'erisml-compiler[llm,calibration,monitor]' # full stack
87
+
88
+ # Or, install from source (editable; choose extras as needed)
89
+ pip install -e ".[test,calibration,monitor,notebook]"
90
+
91
+ # Compile one of the bundled examples (text lens)
92
+ eris-compile compile examples/nazi_attic.txt --out out/nazi_attic.ir.json
93
+
94
+ # Validate the IR
95
+ eris-compile validate out/nazi_attic.ir.json
96
+
97
+ # Export as an RLEF training record
98
+ eris-compile rlef out/nazi_attic.ir.json --out out/nazi_attic.rlef.json
99
+
100
+ # Run the activation lens (mock source for offline use)
101
+ eris-compile monitor "Soldiers at the door asking about hidden refugees." \
102
+ --source mock --hidden-dim 64 --n-layers 8 \
103
+ --out out/nazi_attic.trace.json
104
+
105
+ # Compare the two lenses — fires requires_human_review when they disagree
106
+ eris-compile delta out/nazi_attic.ir.json out/nazi_attic.trace.json \
107
+ --out out/nazi_attic.delta.json
108
+
109
+ # Emit synthesizable Vitis HLS C++ for the silicon target
110
+ eris-compile silicon-emit --out-dir out/silicon
111
+
112
+ # Run the full test suite (142 tests, ~30s without LaBSE download)
113
+ pytest
114
+
115
+ # Quickstart notebook
116
+ jupyter notebook notebooks/quickstart.ipynb
117
+ ```
118
+
119
+ ## Architecture
120
+
121
+ The compiler implements the 12-pass pipeline from spec §12 with a tiered
122
+ extractor stack, a silicon-castable evaluation kernel, and the I-EIP Monitor
123
+ on top.
124
+
125
+ ```
126
+ text ──► ingest ──► segment ──► extract ──► canonicalize ──► tensorize
127
+ │ │
128
+ │ └── Mock | Rule | LLM (NRP / local vLLM)
129
+ │ + Critic + ProbeExtractor
130
+
131
+ └──► EM-DAG (10 modules) ──► FSMs ──► DEME ──► audit
132
+
133
+ └──► silicon emit (Vitis HLS)
134
+
135
+ (out-of-band, sampled audit)
136
+ model ──► hooks ──► IEIPMonitor ──► Delta lens
137
+
138
+ └─► requires_human_review
139
+ + failure-mode report
140
+ ```
141
+
142
+ Three extractor tiers cover the latency / faithfulness frontier:
143
+
144
+ - **Mock / Rule** — deterministic, real-time, silicon-castable.
145
+ - **LLM** — NRP OpenAI-compatible (`gpt-oss`, `qwen3`, etc.) or local vLLM,
146
+ with a critic pass that flags off-canon outputs for `requires_human_review`.
147
+ - **Probe** — calibrated LaBSE-backed classifier head using
148
+ sqnd-probe v10.16.9 methods: spectral decoupling, VIB, multi-head GRL
149
+ adversarial, confusion loss.
150
+
151
+ Three lenses cover the alignment frontier:
152
+
153
+ - **Text lens** (Phases 1–3) — what the model *says*.
154
+ - **Activation lens** (Phase 4) — what the model *internally exhibits*
155
+ at chosen transformer layers (forward hooks on Qwen2.5-7B-Instruct,
156
+ LLaMA, Mistral, GPT-2, or BERT-family models).
157
+ - **Delta lens** (Phase 4) — where they disagree, structured by moral
158
+ dimension, with five named failure modes
159
+ (`text_internal_mismatch`, `layerwise_drift`, `group_symmetry_break`,
160
+ `probe_uncertainty_spike`, `audit_chain_break`). Any firing sets
161
+ `requires_human_review`; the Monitor never overrules DEME.
162
+
163
+ See `docs/i_eip_monitor.md` for the threat model, trust-boundary
164
+ diagram, and the precise semantics of each failure mode.
165
+
166
+ ### Layered architecture
167
+
168
+ | Layer | Purpose |
169
+ |---|---|
170
+ | `ingestion/` | Load text from files or strings, attach metadata |
171
+ | `segmentation/` | Split text into morally-coherent segments |
172
+ | `annotation/` | Mock / Rule / LLM / Probe extractors + critic |
173
+ | `canonicalizer/` | Registry (Jaccard) + LaBSE cosine canonical-form snap |
174
+ | `ontology/` | YAML registries: dimensions, roles, commitments, canonical forms |
175
+ | `ir/` | Pydantic v2 IR schemas and validators |
176
+ | `em_dag/` | 10 ethical modules + topological DAG evaluator |
177
+ | `fsm/` | Commitment / Legitimacy / Consent finite-state machines |
178
+ | `evaluation/` | MoralVector / MoralTensor construction; conflict detection |
179
+ | `calibration/` | Probe training: losses, adversarial heads, VIB, bond index |
180
+ | `correction/` | IR diff + apply-corrections (RLEF feedback loop) |
181
+ | `erisml_backend/` | ErisML codegen and DEME bridge |
182
+ | `silicon/` | Fixed-point conversion + Vitis HLS C++ emitters (FSM + DAG) |
183
+ | `audit/` | SHA-256 hash chain and per-pass provenance |
184
+ | `export/` | JSON, ErisML source, RLEF training records |
185
+ | `viz/` | HTML report + timeline plot |
186
+ | `streaming/` | Real-time captioner of pipeline events |
187
+ | `monitor/` | I-EIP Monitor activation lens: ActivationSource + ActivationProbe + IEIPMonitor |
188
+ | `delta/` | Delta lens: compare_morals, BIP equivariance check, 5-mode failure detector |
189
+ | `cli.py` | 12 subcommands: `bundle calibrate compile correct delta diff monitor report rlef silicon-emit validate version` |
190
+
191
+ ### What is NOT yet in `main`
192
+
193
+ See `SCOPE.md` for the full list. Headline in-flight items:
194
+
195
+ - **Production web app** (deferred from the Phase 4 redirect to the I-EIP Monitor)
196
+ - **NRP runtime deployment** (orchestrator + pod templates)
197
+ - **Silicon hardware verification** on the Xilinx U55C target — Vitis HLS C++
198
+ is emitted and builds; on-FPGA bring-up is gated by the NRP Coder bitstream
199
+ pipeline (see `project_epu_phase3_hw_blocked` in the user's notes).
200
+
201
+ ## Project layout
202
+
203
+ ```
204
+ erisml-compiler/
205
+ ErisML-Compiler.docx # Original design spec (31 sections)
206
+ ErisML-Compiler.md # Same, converted to Markdown
207
+ SCOPE.md # What is built / stubbed / deferred
208
+ README.md # This file
209
+ LICENSE # MIT
210
+ pyproject.toml # Extras: [llm] [calibration] [monitor] [test] [dev] [notebook]
211
+ src/erisml_compiler/
212
+ cli.py
213
+ ingestion/ segmentation/ annotation/ ontology/ ir/ evaluation/
214
+ em_dag/ fsm/ canonicalizer/ correction/
215
+ calibration/ monitor/ delta/ silicon/ erisml_backend/
216
+ audit/ export/ viz/ streaming/
217
+ examples/
218
+ nazi_attic.txt
219
+ medical_confidentiality.txt
220
+ whistleblower.txt
221
+ tests/ # 142 tests
222
+ notebooks/quickstart.ipynb
223
+ docs/
224
+ architecture.md
225
+ silicon_target.md
226
+ nrp_coder_deployment.md
227
+ i_eip_monitor.md # I-EIP Monitor threat model & trust boundaries
228
+ scripts/atlas/
229
+ probe_models.py # Recon: enumerate HF + GGUF models on Atlas
230
+ ```
231
+
232
+ ## Status
233
+
234
+ **Phases 1–4 on `main`** — alpha. **142 tests passing** across IR, EM-DAG,
235
+ FSMs, canonicalizer, critic, correction, calibration, export, silicon emit,
236
+ activation lens, delta lens, equivariance, and the failure-mode detectors.
237
+ CI green on Ubuntu × Python 3.10/3.11/3.12.
238
+
239
+ End-to-end verified:
240
+
241
+ - NRP LLM integration on the bundled `nazi_attic` example (the LLM picks the
242
+ wrong canonical form, the canonicalizer corrects it, the critic pass
243
+ triggers `requires_human_review`).
244
+ - I-EIP Monitor on the same example: divergence 0.70, 6 direction breaks,
245
+ two failure modes fire, `requires_human_review=True`.
246
+ - Vitis HLS C++ emit for FSMs + EM-DAG (NRP Coder bitstream blocked
247
+ separately — see SCOPE.md).
248
+
249
+ ## Citing
250
+
251
+ If you use this work academically, please cite the design spec:
252
+
253
+ ```bibtex
254
+ @misc{bond2026erisml,
255
+ author = {Bond, Andrew H.},
256
+ title = {ErisML Compiler: Structure-Preserving Compilation from
257
+ Natural Language to a Moral Intermediate Representation},
258
+ year = {2026},
259
+ url = {https://github.com/ahb-sjsu/erisml-compiler}
260
+ }
261
+ ```
262
+
263
+ ## License
264
+
265
+ MIT. See `LICENSE`.
@@ -0,0 +1,216 @@
1
+ # ErisML Compiler
2
+
3
+ [![CI](https://github.com/ahb-sjsu/erisml-compiler/actions/workflows/ci.yml/badge.svg)](https://github.com/ahb-sjsu/erisml-compiler/actions/workflows/ci.yml)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
6
+ [![Pydantic v2](https://img.shields.io/badge/pydantic-v2-green.svg)](https://docs.pydantic.dev/)
7
+ [![Schema](https://img.shields.io/badge/IR%20schema-erisml__compiler__ir__v0.1-orange.svg)](SCOPE.md)
8
+ [![Tests](https://img.shields.io/badge/tests-142%20passing-brightgreen.svg)](#status)
9
+ [![Status: Alpha](https://img.shields.io/badge/status-alpha-red.svg)](SCOPE.md)
10
+ [![PyPI](https://img.shields.io/pypi/v/erisml-compiler.svg)](https://pypi.org/project/erisml-compiler/)
11
+
12
+ A structure-preserving compiler from natural-language moral material into a
13
+ canonical **ErisML Intermediate Representation** (IR) that can be evaluated by
14
+ DEME, exported for RLEF training, audited as a structured trace, and
15
+ introspected by the I-EIP Monitor's three lenses.
16
+
17
+ The compiler operationalises the thesis that **moral reasoning requires
18
+ structure-preserving representation before decision contraction**. A scalar
19
+ "good / bad / safe / unsafe" label discards the dimensions that justify or
20
+ defeat a candidate action: who the stakeholders are, what commitments bind
21
+ them, which authorities are legitimate, who bears imposed risk. The compiler
22
+ preserves this tensorial structure as a first-class object, then closes the
23
+ loop by inspecting whether the text output and the model's internal state
24
+ actually agree about it.
25
+
26
+ See `ErisML-Compiler.md` for the full design spec (31 sections) and `SCOPE.md`
27
+ for what each phase actually delivers versus what is deferred. Current `main`
28
+ covers Phases 1–4 (IR + DEME + calibration + silicon emitters + I-EIP
29
+ Monitor); the production web app and silicon hardware verification are
30
+ deferred.
31
+
32
+ ## Quick start
33
+
34
+ ```bash
35
+ # Install from PyPI
36
+ pip install erisml-compiler # core
37
+ pip install 'erisml-compiler[llm,calibration,monitor]' # full stack
38
+
39
+ # Or, install from source (editable; choose extras as needed)
40
+ pip install -e ".[test,calibration,monitor,notebook]"
41
+
42
+ # Compile one of the bundled examples (text lens)
43
+ eris-compile compile examples/nazi_attic.txt --out out/nazi_attic.ir.json
44
+
45
+ # Validate the IR
46
+ eris-compile validate out/nazi_attic.ir.json
47
+
48
+ # Export as an RLEF training record
49
+ eris-compile rlef out/nazi_attic.ir.json --out out/nazi_attic.rlef.json
50
+
51
+ # Run the activation lens (mock source for offline use)
52
+ eris-compile monitor "Soldiers at the door asking about hidden refugees." \
53
+ --source mock --hidden-dim 64 --n-layers 8 \
54
+ --out out/nazi_attic.trace.json
55
+
56
+ # Compare the two lenses — fires requires_human_review when they disagree
57
+ eris-compile delta out/nazi_attic.ir.json out/nazi_attic.trace.json \
58
+ --out out/nazi_attic.delta.json
59
+
60
+ # Emit synthesizable Vitis HLS C++ for the silicon target
61
+ eris-compile silicon-emit --out-dir out/silicon
62
+
63
+ # Run the full test suite (142 tests, ~30s without LaBSE download)
64
+ pytest
65
+
66
+ # Quickstart notebook
67
+ jupyter notebook notebooks/quickstart.ipynb
68
+ ```
69
+
70
+ ## Architecture
71
+
72
+ The compiler implements the 12-pass pipeline from spec §12 with a tiered
73
+ extractor stack, a silicon-castable evaluation kernel, and the I-EIP Monitor
74
+ on top.
75
+
76
+ ```
77
+ text ──► ingest ──► segment ──► extract ──► canonicalize ──► tensorize
78
+ │ │
79
+ │ └── Mock | Rule | LLM (NRP / local vLLM)
80
+ │ + Critic + ProbeExtractor
81
+
82
+ └──► EM-DAG (10 modules) ──► FSMs ──► DEME ──► audit
83
+
84
+ └──► silicon emit (Vitis HLS)
85
+
86
+ (out-of-band, sampled audit)
87
+ model ──► hooks ──► IEIPMonitor ──► Delta lens
88
+
89
+ └─► requires_human_review
90
+ + failure-mode report
91
+ ```
92
+
93
+ Three extractor tiers cover the latency / faithfulness frontier:
94
+
95
+ - **Mock / Rule** — deterministic, real-time, silicon-castable.
96
+ - **LLM** — NRP OpenAI-compatible (`gpt-oss`, `qwen3`, etc.) or local vLLM,
97
+ with a critic pass that flags off-canon outputs for `requires_human_review`.
98
+ - **Probe** — calibrated LaBSE-backed classifier head using
99
+ sqnd-probe v10.16.9 methods: spectral decoupling, VIB, multi-head GRL
100
+ adversarial, confusion loss.
101
+
102
+ Three lenses cover the alignment frontier:
103
+
104
+ - **Text lens** (Phases 1–3) — what the model *says*.
105
+ - **Activation lens** (Phase 4) — what the model *internally exhibits*
106
+ at chosen transformer layers (forward hooks on Qwen2.5-7B-Instruct,
107
+ LLaMA, Mistral, GPT-2, or BERT-family models).
108
+ - **Delta lens** (Phase 4) — where they disagree, structured by moral
109
+ dimension, with five named failure modes
110
+ (`text_internal_mismatch`, `layerwise_drift`, `group_symmetry_break`,
111
+ `probe_uncertainty_spike`, `audit_chain_break`). Any firing sets
112
+ `requires_human_review`; the Monitor never overrules DEME.
113
+
114
+ See `docs/i_eip_monitor.md` for the threat model, trust-boundary
115
+ diagram, and the precise semantics of each failure mode.
116
+
117
+ ### Layered architecture
118
+
119
+ | Layer | Purpose |
120
+ |---|---|
121
+ | `ingestion/` | Load text from files or strings, attach metadata |
122
+ | `segmentation/` | Split text into morally-coherent segments |
123
+ | `annotation/` | Mock / Rule / LLM / Probe extractors + critic |
124
+ | `canonicalizer/` | Registry (Jaccard) + LaBSE cosine canonical-form snap |
125
+ | `ontology/` | YAML registries: dimensions, roles, commitments, canonical forms |
126
+ | `ir/` | Pydantic v2 IR schemas and validators |
127
+ | `em_dag/` | 10 ethical modules + topological DAG evaluator |
128
+ | `fsm/` | Commitment / Legitimacy / Consent finite-state machines |
129
+ | `evaluation/` | MoralVector / MoralTensor construction; conflict detection |
130
+ | `calibration/` | Probe training: losses, adversarial heads, VIB, bond index |
131
+ | `correction/` | IR diff + apply-corrections (RLEF feedback loop) |
132
+ | `erisml_backend/` | ErisML codegen and DEME bridge |
133
+ | `silicon/` | Fixed-point conversion + Vitis HLS C++ emitters (FSM + DAG) |
134
+ | `audit/` | SHA-256 hash chain and per-pass provenance |
135
+ | `export/` | JSON, ErisML source, RLEF training records |
136
+ | `viz/` | HTML report + timeline plot |
137
+ | `streaming/` | Real-time captioner of pipeline events |
138
+ | `monitor/` | I-EIP Monitor activation lens: ActivationSource + ActivationProbe + IEIPMonitor |
139
+ | `delta/` | Delta lens: compare_morals, BIP equivariance check, 5-mode failure detector |
140
+ | `cli.py` | 12 subcommands: `bundle calibrate compile correct delta diff monitor report rlef silicon-emit validate version` |
141
+
142
+ ### What is NOT yet in `main`
143
+
144
+ See `SCOPE.md` for the full list. Headline in-flight items:
145
+
146
+ - **Production web app** (deferred from the Phase 4 redirect to the I-EIP Monitor)
147
+ - **NRP runtime deployment** (orchestrator + pod templates)
148
+ - **Silicon hardware verification** on the Xilinx U55C target — Vitis HLS C++
149
+ is emitted and builds; on-FPGA bring-up is gated by the NRP Coder bitstream
150
+ pipeline (see `project_epu_phase3_hw_blocked` in the user's notes).
151
+
152
+ ## Project layout
153
+
154
+ ```
155
+ erisml-compiler/
156
+ ErisML-Compiler.docx # Original design spec (31 sections)
157
+ ErisML-Compiler.md # Same, converted to Markdown
158
+ SCOPE.md # What is built / stubbed / deferred
159
+ README.md # This file
160
+ LICENSE # MIT
161
+ pyproject.toml # Extras: [llm] [calibration] [monitor] [test] [dev] [notebook]
162
+ src/erisml_compiler/
163
+ cli.py
164
+ ingestion/ segmentation/ annotation/ ontology/ ir/ evaluation/
165
+ em_dag/ fsm/ canonicalizer/ correction/
166
+ calibration/ monitor/ delta/ silicon/ erisml_backend/
167
+ audit/ export/ viz/ streaming/
168
+ examples/
169
+ nazi_attic.txt
170
+ medical_confidentiality.txt
171
+ whistleblower.txt
172
+ tests/ # 142 tests
173
+ notebooks/quickstart.ipynb
174
+ docs/
175
+ architecture.md
176
+ silicon_target.md
177
+ nrp_coder_deployment.md
178
+ i_eip_monitor.md # I-EIP Monitor threat model & trust boundaries
179
+ scripts/atlas/
180
+ probe_models.py # Recon: enumerate HF + GGUF models on Atlas
181
+ ```
182
+
183
+ ## Status
184
+
185
+ **Phases 1–4 on `main`** — alpha. **142 tests passing** across IR, EM-DAG,
186
+ FSMs, canonicalizer, critic, correction, calibration, export, silicon emit,
187
+ activation lens, delta lens, equivariance, and the failure-mode detectors.
188
+ CI green on Ubuntu × Python 3.10/3.11/3.12.
189
+
190
+ End-to-end verified:
191
+
192
+ - NRP LLM integration on the bundled `nazi_attic` example (the LLM picks the
193
+ wrong canonical form, the canonicalizer corrects it, the critic pass
194
+ triggers `requires_human_review`).
195
+ - I-EIP Monitor on the same example: divergence 0.70, 6 direction breaks,
196
+ two failure modes fire, `requires_human_review=True`.
197
+ - Vitis HLS C++ emit for FSMs + EM-DAG (NRP Coder bitstream blocked
198
+ separately — see SCOPE.md).
199
+
200
+ ## Citing
201
+
202
+ If you use this work academically, please cite the design spec:
203
+
204
+ ```bibtex
205
+ @misc{bond2026erisml,
206
+ author = {Bond, Andrew H.},
207
+ title = {ErisML Compiler: Structure-Preserving Compilation from
208
+ Natural Language to a Moral Intermediate Representation},
209
+ year = {2026},
210
+ url = {https://github.com/ahb-sjsu/erisml-compiler}
211
+ }
212
+ ```
213
+
214
+ ## License
215
+
216
+ MIT. See `LICENSE`.
@@ -0,0 +1,84 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "erisml-compiler"
7
+ version = "0.4.0"
8
+ description = "Structure-preserving compiler from natural language to ErisML"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "Andrew H. Bond", email = "andrew.bond@sjsu.edu" }]
13
+ keywords = ["ethics", "ai-safety", "geometric-ethics", "moral-reasoning", "compiler", "nlp"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Science/Research",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
22
+ ]
23
+ dependencies = [
24
+ "pydantic>=2.5",
25
+ "click>=8.1",
26
+ "pyyaml>=6.0",
27
+ "structlog>=24.1",
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ llm = [
32
+ "openai>=1.30",
33
+ "httpx>=0.27",
34
+ ]
35
+ ml = [
36
+ "sentence-transformers>=2.7",
37
+ "numpy>=1.24",
38
+ ]
39
+ calibration = [
40
+ "torch>=2.1",
41
+ "sentence-transformers>=2.7",
42
+ "numpy>=1.24",
43
+ "tqdm>=4.66",
44
+ ]
45
+ monitor = [
46
+ "torch>=2.1",
47
+ "transformers>=4.40",
48
+ "numpy>=1.24",
49
+ "paramiko>=3.4",
50
+ ]
51
+ test = [
52
+ "pytest>=8.0",
53
+ "pytest-cov>=5.0",
54
+ ]
55
+ dev = [
56
+ "black>=24.0",
57
+ "ruff>=0.5",
58
+ "mypy>=1.10",
59
+ ]
60
+ notebook = [
61
+ "jupyter>=1.0",
62
+ "matplotlib>=3.8",
63
+ ]
64
+
65
+ [project.scripts]
66
+ eris-compile = "erisml_compiler.cli:cli"
67
+
68
+ [tool.setuptools.packages.find]
69
+ where = ["src"]
70
+
71
+ [tool.setuptools.package-data]
72
+ erisml_compiler = ["ontology/*.yaml", "annotation/prompts/*.txt"]
73
+
74
+ [tool.pytest.ini_options]
75
+ testpaths = ["tests"]
76
+ addopts = "-ra --strict-markers"
77
+
78
+ [tool.ruff]
79
+ line-length = 100
80
+ target-version = "py310"
81
+
82
+ [tool.black]
83
+ line-length = 100
84
+ target-version = ["py310"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,8 @@
1
+ """ErisML Compiler — Structure-preserving compiler from natural language to ErisML.
2
+
3
+ Phase 3 (v0.3.0). See SCOPE.md at the repo root for what is built, stubbed, and deferred.
4
+ """
5
+ from __future__ import annotations
6
+
7
+ __version__ = "0.4.0"
8
+ __schema_version__ = "erisml_compiler_ir_v0.1"
@@ -0,0 +1,32 @@
1
+ """Annotation: extract stakeholders, commitments, events, ethical facts."""
2
+ from erisml_compiler.annotation.base import (
3
+ Extractor,
4
+ ExtractorResult,
5
+ UnknownDocumentError,
6
+ )
7
+ from erisml_compiler.annotation.critic import CriticExtractor, CriticReport, critic_pass
8
+ from erisml_compiler.annotation.llm_extractor import (
9
+ LLMExtractor,
10
+ LocalVLLMAdapter,
11
+ MockLLMAdapter,
12
+ ModelAdapter,
13
+ NRPOpenAIAdapter,
14
+ )
15
+ from erisml_compiler.annotation.mock_extractor import MockExtractor
16
+ from erisml_compiler.annotation.rule_extractor import RuleExtractor
17
+
18
+ __all__ = [
19
+ "CriticExtractor",
20
+ "CriticReport",
21
+ "Extractor",
22
+ "ExtractorResult",
23
+ "LLMExtractor",
24
+ "LocalVLLMAdapter",
25
+ "MockExtractor",
26
+ "MockLLMAdapter",
27
+ "ModelAdapter",
28
+ "NRPOpenAIAdapter",
29
+ "RuleExtractor",
30
+ "UnknownDocumentError",
31
+ "critic_pass",
32
+ ]