Constitutional Dynamics: An application for AI alignment analysis using State Transition Calculus principles from the PrincipiaDynamica project
Project description
Constitutional Dynamics ๐งญ
Vector-space alignment metrics & state-transition calculus for language-model telemetry
โจ Why does this exist?
Large-model "alignment" is usually reported as a static score after fine-tuning.
Constitutional Dynamics treats alignment as a trajectory your model walks through embedding-space:
- Time domain โ how successive responses drift toward / away from desired values.
- Frequency domain โ whether telemetry or exfil channels reveal periodic "spikes" defenders can spot.
- State-Transition Calculus (STC) โ a lightweight formalism that captures latent potentialities (good and bad) and how they re-activate under specific context.
The result is a self-contained Python package you can drop on any JSON embedding dump or live psutil feed, and instantly obtain:
- ฯ-alignment scores, robust to noise & perturbations
- ฮ-transition vectors with direction-to-aligned-region heuristics
- PSD (spectral) deviation for stealth / anomaly studies
- A dual-objective cost
C(t)ready to feed into quantum / classical optimizers
TL;DR
Constitutional Dynamics isn't "yet another" static alignment benchmark. It treats alignment as a living trajectoryโmonitored in real time, quantified in both time- and frequency-domains, and optimized via QUBO solvers. If we want to improve alignment, we must measure its dynamics, not just its snapshots. Constitutional Dynamics delivers that, coupling production-grade engineering (pydantic configs, CLI, tests, CI) with research-grade rigor. โ built for practitioners who treat alignment as an empirical science. At least that is what we are aiming for (ใ) (For Anthropicโ with appreciation.) ๐ซก
๐๏ธ Package layout
principiadynamica/ <-- Repository Root (contains pyproject.toml, README.md)
โ
โโโ constitutional_dynamics/ <-- Main Python package
โ โโโ __init__.py # version + public re-exports
โ โ
โ โโโ cfg/ # YAML & logging config
โ โ โโโ defaults.yaml # ฯ (memory), ฮป, thresholdsโฆ
โ โ โโโ logging.yaml # Logging configuration
โ โ
โ โโโ core/ # Core functionality
โ โ โโโ space.py # AlignmentVectorSpace
โ โ โโโ transition.py # analyse_transition() + STC wrappers
โ โ โโโ metrics.py # stability, robustness, PSD distance
โ โ โโโ optimise.py # Graph- & QUBO-based multi-objective solver
โ โ
โ โโโ io/ # Input/Output operations
โ โ โโโ loaders.py # load_embeddings() / aligned_examples()
โ โ โโโ timeseries.py # detect & order time-series
โ โ โโโ live.py # psutil collector
โ โ
โ โโโ integrations/ # External system integrations
โ โ โโโ graph.py # Neo4j consequence-graph connector
โ โ โโโ quantum.py # D-Wave / dwave-ocean wrapper
โ โ โโโ strategist.py # (optional) LLM prompt builder
โ โ
โ โโโ vis/ # Visualization tools
โ โ โโโ visualizer.py # Rich / ASCII sparklines & tables
โ โ
โ โโโ cli/ # Command-line interface
โ โโโ main.py # python -m constitutional_dynamics ...
โ
โโโ tests/ # Tests for the package & integrations
โ โโโ ...
โ
โโโ docs/ # Project documentation
โ โโโ ...
โ
โโโ ... (LICENSE, .gitignore, etc.)
๐ง Mathematical backbone
1. Alignment region (time domain)
Vector-space hypersphere or convex-hull defined by known "good-behaviour" embeddings.
- ฯ(state) โ cosine similarity to aligned centroid/boundary (with exponential memory decay ฯ).
2. State-Transition Calculus (STC)
| STC symbol | Implementation |
|---|---|
a_i (value subset) |
cluster centres / prototype vectors |
ฯ(a_i,t, โฆ) |
metrics.activation() (ฯ ยท e^{-ฮt/ฯ}) |
Residual potentiality b(a_res) |
robustness perturbation samples |
ฮป(t) exploration/exploitation knob |
CLI flag โ cost weight |
3. Dual-objective cost
[ C(t)=\bigl[1-\bar ฯ(t)\bigr];+;\lambda(t),\text{PSD_distance}(S_x,S_{\text{aligned}}) ]
Minimized by core/optimise.py with a graph-enhanced QUBO (quantum or classical).
๐ Quick-start
Installation
From source:
git clone https://github.com/FF-GardenFn/principiadynamica.git
cd principiadynamica
pip install -e . # This will install as constitutional-dynamics
For developers:
git clone https://github.com/FF-GardenFn/principiadynamica.git
cd principiadynamica
pip install -e ".[dev]" # Installs as constitutional-dynamics with development dependencies
Usage Examples
# 1. offline log analysis
python -m constitutional_dynamics \
--embeddings runs/LLM_chat_embeddings.json \
--aligned docs/aligned_examples.json \
--spectral --steps 6
# 2. live feed (every 1 s)
python -m constitutional_dynamics --live --graph bolt://neo4j:password@localhost:7687
Hit Ctrl-C to see a Rich sparkline of alignment vs time plus the PSD deviation table.
๐ Full Documentation
For more detailed information, including a full usage guide, the mathematical framework of State Transition Calculus, and complete API references, please see:
- Main Documentation Index (Browse on GitHub)
๐ฎ Roadmap
| Milestone | Status | ETA |
|---|---|---|
| ๐ Configurable ฮป(t) schedules (cosine, linear...) | ๐ | v0.2 |
| ๐ Neo4j -> GraphQL API for dashboards | โณ | v0.3 |
| โ๏ธ D-Wave hybrid solver integration | โณ | v0.3 |
| ๐ค LLM strategist loop ("Suggest a timing modulation...") | โณ | v0.4 |
๐ License & Attribution
Prototype code ยฉ 2025 FF-GardenFn. Released under the Apache License 2.0 for non-commercial research & interview demo purposes.
"In theory there is no difference between theory and practice. In practice, there is." โ Yogi Berra
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file constitutional_dynamics-0.1.0.tar.gz.
File metadata
- Download URL: constitutional_dynamics-0.1.0.tar.gz
- Upload date:
- Size: 59.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09cb538fd1316581ec3f10fdaf29744c44e10110346decabc7614bde72c243fd
|
|
| MD5 |
d4384a5964e4535fc811b4522ee022b8
|
|
| BLAKE2b-256 |
c62a05cf960a541df7ce4d84b60910cf3f4e7b55a3a4a7ce4ae6490f134b0957
|
File details
Details for the file constitutional_dynamics-0.1.0-py3-none-any.whl.
File metadata
- Download URL: constitutional_dynamics-0.1.0-py3-none-any.whl
- Upload date:
- Size: 65.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0dc08f88b560fae5bae5d836e9f9941fa92b4aaeb6c152bf190cd51d4e1eb8ef
|
|
| MD5 |
bc38d50a1c0097f66cb9d90a39664ecc
|
|
| BLAKE2b-256 |
b2768493ea2758d93d8c3945b67d5cf302c09bb6af9fecd80956d55261ca1b9f
|