Skip to main content

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
Status


โœจ 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:


๐Ÿ”ฎ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

constitutional_dynamics-0.1.0.tar.gz (59.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

constitutional_dynamics-0.1.0-py3-none-any.whl (65.7 kB view details)

Uploaded Python 3

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

Hashes for constitutional_dynamics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 09cb538fd1316581ec3f10fdaf29744c44e10110346decabc7614bde72c243fd
MD5 d4384a5964e4535fc811b4522ee022b8
BLAKE2b-256 c62a05cf960a541df7ce4d84b60910cf3f4e7b55a3a4a7ce4ae6490f134b0957

See more details on using hashes here.

File details

Details for the file constitutional_dynamics-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for constitutional_dynamics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0dc08f88b560fae5bae5d836e9f9941fa92b4aaeb6c152bf190cd51d4e1eb8ef
MD5 bc38d50a1c0097f66cb9d90a39664ecc
BLAKE2b-256 b2768493ea2758d93d8c3945b67d5cf302c09bb6af9fecd80956d55261ca1b9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page