alignscope 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.
Files changed (47) hide show
  1. alignscope-0.1.0/.github/workflows/publish.yml +28 -0
  2. alignscope-0.1.0/CHANGELOG.md +16 -0
  3. alignscope-0.1.0/Dockerfile +17 -0
  4. alignscope-0.1.0/LICENSE +21 -0
  5. alignscope-0.1.0/MOTIVATION.md +32 -0
  6. alignscope-0.1.0/PKG-INFO +183 -0
  7. alignscope-0.1.0/README.md +138 -0
  8. alignscope-0.1.0/alignscope/__init__.py +150 -0
  9. alignscope-0.1.0/alignscope/adapters.py +169 -0
  10. alignscope-0.1.0/alignscope/cli.py +99 -0
  11. alignscope-0.1.0/alignscope/detector.py +242 -0
  12. alignscope-0.1.0/alignscope/integrations/__init__.py +28 -0
  13. alignscope-0.1.0/alignscope/integrations/mlflow_bridge.py +70 -0
  14. alignscope-0.1.0/alignscope/integrations/wandb_bridge.py +81 -0
  15. alignscope-0.1.0/alignscope/metrics.py +383 -0
  16. alignscope-0.1.0/alignscope/patches/__init__.py +50 -0
  17. alignscope-0.1.0/alignscope/patches/pettingzoo.py +332 -0
  18. alignscope-0.1.0/alignscope/patches/pymarl.py +277 -0
  19. alignscope-0.1.0/alignscope/patches/rllib.py +170 -0
  20. alignscope-0.1.0/alignscope/sdk.py +606 -0
  21. alignscope-0.1.0/alignscope/server.py +298 -0
  22. alignscope-0.1.0/alignscope/simulator.py +493 -0
  23. alignscope-0.1.0/epymarl_err.txt +0 -0
  24. alignscope-0.1.0/examples/pettingzoo_example.py +58 -0
  25. alignscope-0.1.0/examples/test_butterfly.py +81 -0
  26. alignscope-0.1.0/examples/test_classic_games.py +102 -0
  27. alignscope-0.1.0/examples/test_competitive.py +188 -0
  28. alignscope-0.1.0/examples/test_cooperative.py +189 -0
  29. alignscope-0.1.0/examples/test_ctde.py +180 -0
  30. alignscope-0.1.0/examples/test_epymarl.py +235 -0
  31. alignscope-0.1.0/examples/test_kaz.py +123 -0
  32. alignscope-0.1.0/examples/test_log_replay.py +177 -0
  33. alignscope-0.1.0/examples/test_mean_field.py +237 -0
  34. alignscope-0.1.0/examples/test_mixed_interest.py +201 -0
  35. alignscope-0.1.0/examples/test_mpe.py +40 -0
  36. alignscope-0.1.0/examples/test_mpe_suite.py +107 -0
  37. alignscope-0.1.0/examples/test_rllib.py +222 -0
  38. alignscope-0.1.0/examples/test_sisl.py +81 -0
  39. alignscope-0.1.0/examples/test_smac.py +275 -0
  40. alignscope-0.1.0/frontend/css/style.css +663 -0
  41. alignscope-0.1.0/frontend/index.html +169 -0
  42. alignscope-0.1.0/frontend/js/app.js +360 -0
  43. alignscope-0.1.0/frontend/js/metrics.js +220 -0
  44. alignscope-0.1.0/frontend/js/timeline.js +494 -0
  45. alignscope-0.1.0/frontend/js/topology.js +368 -0
  46. alignscope-0.1.0/pyproject.toml +56 -0
  47. alignscope-0.1.0/requirements.txt +3 -0
@@ -0,0 +1,28 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ pypi-publish:
9
+ name: Build and publish Python distribution to PyPI
10
+ runs-on: ubuntu-latest
11
+ environment:
12
+ name: pypi
13
+ url: https://pypi.org/p/alignscope
14
+ permissions:
15
+ id-token: write
16
+ steps:
17
+ - name: Checkout Source
18
+ uses: actions/checkout@v4
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: "3.10"
23
+ - name: Install build dependencies
24
+ run: python -m pip install --upgrade build hatchling
25
+ - name: Build a binary wheel and a source tarball
26
+ run: python -m build --sdist --wheel --outdir dist/
27
+ - name: Publish package distributions to PyPI
28
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - Unreleased
9
+
10
+ ### Added
11
+ - Core Python SDK for zero-code instrumentation of MARL environments (`alignscope.wrap`).
12
+ - Real-time dashboard featuring Force-Directed Agent Topology, Event Timeline, and cooperative metrics.
13
+ - Universal environment adapters for PettingZoo, MPE, and SMAC.
14
+ - Seamless metric forwarding integrations for Weights & Biases and MLflow.
15
+ - Offline replay streaming functionality for CSV, JSON, NPZ, and TensorBoard logs.
16
+ - Automated anomaly detection engine identifying agent defections and coalition breakages in real-time.
@@ -0,0 +1,17 @@
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Install the package
6
+ COPY pyproject.toml .
7
+ COPY alignscope/ alignscope/
8
+ COPY frontend/ frontend/
9
+ COPY README.md .
10
+
11
+ RUN pip install --no-cache-dir .
12
+
13
+ # Expose dashboard port
14
+ EXPOSE 8000
15
+
16
+ # Default: start in demo mode
17
+ CMD ["alignscope", "start", "--demo", "--port", "8000"]
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nithisha
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,32 @@
1
+ # Why AlignScope Matters for Alignment Research
2
+
3
+ AI alignment is not just a single-agent problem. As multi-agent reinforcement learning (MARL) systems grow in complexity — agents learning to cooperate, specialize, and form coalitions — we need tools to **observe** alignment as it emerges.
4
+
5
+ AlignScope is a scientific instrument for this phenomenon.
6
+
7
+ ## The Measurement Gap
8
+
9
+ You can't study what you can't see.
10
+
11
+ Most MARL training pipelines produce experience logs and reward curves that tell you *whether* an agent won, but not *how* alignment formed — or when it broke. The three questions that matter most to alignment research are currently invisible in standard tooling:
12
+
13
+ 1. **Are agents specializing?** When agents commit to consistent roles, that's not just strategy — that's the beginning of role-based trust, the same dynamic that makes cells differentiate in an organism. AlignScope measures this as **role stability** via Shannon entropy.
14
+
15
+ 2. **Are agents reciprocating?** When Agent A gathers resources for Agent B, and B captures objectives for A, that's the seed of coalition — individuals learning to form cooperative wholes. AlignScope measures this as the **reciprocity index**.
16
+
17
+ 3. **When does alignment fail?** The most scientifically valuable moment in any training run is not when everything works — it's the exact tick when an agent defects. That moment reveals what the alignment was actually built on, and how fragile it was. AlignScope's **defection detector** flags these moments so researchers can inspect what changed.
18
+
19
+ ## What This Enables
20
+
21
+ With AlignScope, a researcher can:
22
+
23
+ - Watch coalition clusters form in real-time in the topology graph and see which role combinations naturally attract
24
+ - Identify which training configurations produce stable alignment vs. fragile cooperation that breaks under pressure
25
+ - Compare episodes side-by-side using alignment metric histories rather than just reward curves
26
+ - Build intuition about organic alignment by *seeing* it happen, not reconstructing it from logs
27
+
28
+ ## Environment Agnostic
29
+
30
+ AlignScope works with **any** MARL environment. Whether you're training agents in grid worlds, competitive games, robotics simulations, or social dilemma environments — if your agents have roles, teams, and interactions, AlignScope can visualize their alignment dynamics.
31
+
32
+ This is not observability for observability's sake. It's a scientific instrument for studying emergent cooperation in artificial intelligence.
@@ -0,0 +1,183 @@
1
+ Metadata-Version: 2.4
2
+ Name: alignscope
3
+ Version: 0.1.0
4
+ Summary: Real-time alignment observability for multi-agent reinforcement learning
5
+ Project-URL: Homepage, https://github.com/raghavarajunithisha-lab/AlignScopeV1
6
+ Project-URL: Documentation, https://github.com/raghavarajunithisha-lab/AlignScopeV1#readme
7
+ Project-URL: Repository, https://github.com/raghavarajunithisha-lab/AlignScopeV1
8
+ Author-email: Nithisha <nithisha2201@gmail.com>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: alignment,dashboard,marl,multi-agent,observability,reinforcement-learning
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Requires-Python: >=3.9
22
+ Requires-Dist: click>=8.0
23
+ Requires-Dist: fastapi>=0.104.0
24
+ Requires-Dist: rich>=13.0
25
+ Requires-Dist: uvicorn[standard]>=0.24.0
26
+ Requires-Dist: websockets>=12.0
27
+ Provides-Extra: all
28
+ Requires-Dist: mlflow>=2.0; extra == 'all'
29
+ Requires-Dist: pettingzoo>=1.22; extra == 'all'
30
+ Requires-Dist: ray[rllib]>=2.0; extra == 'all'
31
+ Requires-Dist: wandb>=0.15; extra == 'all'
32
+ Provides-Extra: dev
33
+ Requires-Dist: httpx; extra == 'dev'
34
+ Requires-Dist: pytest; extra == 'dev'
35
+ Provides-Extra: mlflow
36
+ Requires-Dist: mlflow>=2.0; extra == 'mlflow'
37
+ Provides-Extra: pettingzoo
38
+ Requires-Dist: pettingzoo>=1.22; extra == 'pettingzoo'
39
+ Provides-Extra: pymarl
40
+ Provides-Extra: rllib
41
+ Requires-Dist: ray[rllib]>=2.0; extra == 'rllib'
42
+ Provides-Extra: wandb
43
+ Requires-Dist: wandb>=0.15; extra == 'wandb'
44
+ Description-Content-Type: text/markdown
45
+
46
+ # AlignScope 🔬
47
+
48
+ [![PyPI version](https://badge.fury.io/py/alignscope.svg)](https://badge.fury.io/py/alignscope)
49
+ [![Build Status](https://github.com/raghavarajunithisha-lab/AlignScopeV1/actions/workflows/publish.yml/badge.svg)](https://github.com/raghavarajunithisha-lab/AlignScopeV1/actions)
50
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
51
+
52
+ **An open-source observability SDK and real-time streaming dashboard designed to monitor and debug Multi-Agent Reinforcement Learning (MARL) systems.**
53
+
54
+ AlignScope gives machine learning engineers and researchers instant, zero-code visual feedback on complex multi-agent dynamics—including coalition formation, role specialization, reciprocity collapses, and defection events—without needing to manually parse through thousands of lines of terminal logs.
55
+
56
+ ---
57
+
58
+ ## 🎯 Why This Matters
59
+
60
+ Debugging multi-agent AI ecosystems is notoriously difficult. Standard MLOps tools like Weights & Biases (W&B) and MLflow are optimized for **scalar metrics** (loss, reward curves) but fall short when answering spatial or behavioral questions:
61
+
62
+ - *Why did the agent defect?*
63
+ - *When exactly did the cooperative coalition break down?*
64
+ - *Are agents actually specializing into useful roles, or just exploiting the environment?*
65
+
66
+ **AlignScope solves this by providing real-time topological graphs and event timelines** specifically engineered for multi-agent anomalies. It translates raw, high-frequency environment steps into actionable, human-readable alignment metrics.
67
+
68
+ ### Key Capabilities
69
+
70
+ * **Zero-code Integration**: One line (`alignscope.wrap(env)`) instruments any standard PettingZoo or RLlib environment.
71
+ * **Real-Time Streaming**: High-performance WebSocket backend streams data to a 60fps D3.js and Canvas frontend.
72
+ * **Automated Anomaly Detection**: Dynamically identifies defection, stability drops, and coalition fragmentation using continuous rolling averages.
73
+ * **No Vendor Lock-in**: Automatically forwards intercepted telemetry back out to Weights & Biases and MLflow for persisted logging.
74
+
75
+ ---
76
+
77
+ ## 🏗️ Architecture Overview
78
+
79
+ AlignScope is designed as a decoupled, full-stack monitoring solution:
80
+
81
+ 1. **The SDK (Python)**: A lightweight, non-blocking telemetry tracker that normalizes raw environment step data, computes real-time alignment metrics (reciprocity, stability, convergence), and flags anomalous behavior.
82
+ 2. **The Backend (FastAPI + WebSockets)**: A robust server that manages high-frequency incoming telemetry and broadcasts it to connected clients.
83
+ 3. **The Dashboard (Vanilla JS + D3.js)**: A dark-mode, browser-based UI featuring:
84
+ * **Force-Directed Agent Topology**: Visualizing agent relationships, teams, and defections dynamically.
85
+ * **Zoomable Event Timeline**: A high-performance canvas timeline pinpointing the exact training tick where cooperation fails.
86
+
87
+ ---
88
+
89
+ ## 💼 Core Use Cases
90
+
91
+ **For ML Engineers:**
92
+ * **Reduce Debugging Time**: Identify exactly when and why training instability occurs without waiting for the full epoc to finish.
93
+ * **Track Systemic Collapse**: Monitor reciprocity and role stability drops to catch model collapse early.
94
+ * **Offline Log Replay**: Stream huge offline CSV, JSON, NPZ, or TensorBoard training runs through the dashboard for retroactive analysis.
95
+
96
+ **For Researchers:**
97
+ * **Study Emergent Behavior**: Measure actual role specialization (Shannon entropy) and goal convergence (Cosine similarity).
98
+ * **Validate Alignment**: Visually confirm that your agents are forming expected coalitions in environments like SMAC (StarCraft II) or MPE.
99
+
100
+ ---
101
+
102
+ ## 🚀 Quick Start
103
+
104
+ ### Installation
105
+
106
+ Install AlignScope directly via PyPI:
107
+
108
+ ```bash
109
+ pip install alignscope
110
+ ```
111
+
112
+ ### Starting the Dashboard
113
+
114
+ Launch the real-time visualization server:
115
+
116
+ ```bash
117
+ alignscope start
118
+ ```
119
+
120
+ Open **http://localhost:8000** and watch agents interact live.
121
+
122
+
123
+ ## Why AlignScope?
124
+
125
+ Training MARL agents is hard. Understanding *why* they succeed or fail is harder. Most researchers rely on reward curves and terminal logs — but those don't tell you:
126
+
127
+ - **When** did cooperation break down?
128
+ - **Which** agent defected, and why?
129
+ - **How** are coalitions forming and dissolving over time?
130
+ - **Are** agents actually specializing into useful roles?
131
+
132
+ AlignScope answers all of these questions **visually and in real time**.
133
+
134
+ ### Key Advantages
135
+
136
+ | Advantage | Description |
137
+ |-----------|-------------|
138
+ | **Zero-code integration** | One line (`alignscope.wrap(env)`) to instrument any PettingZoo environment |
139
+ | **Environment agnostic** | Works with PettingZoo, SMAC, RLlib, EPyMARL, or any custom env |
140
+ | **Real-time dashboard** | Watch agents move, form coalitions, and defect as training runs |
141
+ | **Scientific precision** | Pinpoints the exact tick where cooperation fails |
142
+ | **No vendor lock-in** | Forwards metrics to W&B and MLflow automatically if installed |
143
+ | **Offline replay** | Replay saved CSV, JSON, NPZ, TensorBoard, or W&B logs into the dashboard |
144
+
145
+
146
+ ## Supported MARL Environments
147
+
148
+ AlignScope is designed to work with **any** multi-agent system. Here are the environments with dedicated adapters:
149
+
150
+ ### 1. PettingZoo (Cooperative & Classic Games)
151
+
152
+ PettingZoo is the most widely used MARL framework. AlignScope wraps **any** PettingZoo environment — AEC or Parallel API — with a single line.
153
+
154
+ ```python
155
+ import alignscope
156
+ from pettingzoo.butterfly import knights_archers_zombies_v10
157
+
158
+ # 1. Initialize your environment
159
+ env = knights_archers_zombies_v10.env()
160
+
161
+ # 2. Add one line to wrap it with AlignScope
162
+ env = alignscope.wrap(env)
163
+
164
+ # 3. Run your standard training loop!
165
+ env.reset()
166
+ for agent in env.agent_iter():
167
+ obs, reward, term, trunc, info = env.last()
168
+ action = env.action_space(agent).sample() if not (term or trunc) else None
169
+ env.step(action)
170
+ ```
171
+
172
+ *(See `examples/` for templates using RLlib, SMAC, and offline log replay.)*
173
+
174
+ ---
175
+
176
+ ## 🤝 Contributing & Support
177
+
178
+ We welcome contributions! Whether it's adding a new environment adapter, optimizing the frontend canvas renderer, or designing new alignment metrics.
179
+
180
+ For support, issues, or professional inquiries, please [open an issue](https://github.com/raghavarajunithisha-lab/AlignScopeV1/issues) or reach out directly:
181
+ 📧 **nithisha2201@gmail.com**
182
+
183
+ *Designed and maintained by Nithisha.*
@@ -0,0 +1,138 @@
1
+ # AlignScope 🔬
2
+
3
+ [![PyPI version](https://badge.fury.io/py/alignscope.svg)](https://badge.fury.io/py/alignscope)
4
+ [![Build Status](https://github.com/raghavarajunithisha-lab/AlignScopeV1/actions/workflows/publish.yml/badge.svg)](https://github.com/raghavarajunithisha-lab/AlignScopeV1/actions)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ **An open-source observability SDK and real-time streaming dashboard designed to monitor and debug Multi-Agent Reinforcement Learning (MARL) systems.**
8
+
9
+ AlignScope gives machine learning engineers and researchers instant, zero-code visual feedback on complex multi-agent dynamics—including coalition formation, role specialization, reciprocity collapses, and defection events—without needing to manually parse through thousands of lines of terminal logs.
10
+
11
+ ---
12
+
13
+ ## 🎯 Why This Matters
14
+
15
+ Debugging multi-agent AI ecosystems is notoriously difficult. Standard MLOps tools like Weights & Biases (W&B) and MLflow are optimized for **scalar metrics** (loss, reward curves) but fall short when answering spatial or behavioral questions:
16
+
17
+ - *Why did the agent defect?*
18
+ - *When exactly did the cooperative coalition break down?*
19
+ - *Are agents actually specializing into useful roles, or just exploiting the environment?*
20
+
21
+ **AlignScope solves this by providing real-time topological graphs and event timelines** specifically engineered for multi-agent anomalies. It translates raw, high-frequency environment steps into actionable, human-readable alignment metrics.
22
+
23
+ ### Key Capabilities
24
+
25
+ * **Zero-code Integration**: One line (`alignscope.wrap(env)`) instruments any standard PettingZoo or RLlib environment.
26
+ * **Real-Time Streaming**: High-performance WebSocket backend streams data to a 60fps D3.js and Canvas frontend.
27
+ * **Automated Anomaly Detection**: Dynamically identifies defection, stability drops, and coalition fragmentation using continuous rolling averages.
28
+ * **No Vendor Lock-in**: Automatically forwards intercepted telemetry back out to Weights & Biases and MLflow for persisted logging.
29
+
30
+ ---
31
+
32
+ ## 🏗️ Architecture Overview
33
+
34
+ AlignScope is designed as a decoupled, full-stack monitoring solution:
35
+
36
+ 1. **The SDK (Python)**: A lightweight, non-blocking telemetry tracker that normalizes raw environment step data, computes real-time alignment metrics (reciprocity, stability, convergence), and flags anomalous behavior.
37
+ 2. **The Backend (FastAPI + WebSockets)**: A robust server that manages high-frequency incoming telemetry and broadcasts it to connected clients.
38
+ 3. **The Dashboard (Vanilla JS + D3.js)**: A dark-mode, browser-based UI featuring:
39
+ * **Force-Directed Agent Topology**: Visualizing agent relationships, teams, and defections dynamically.
40
+ * **Zoomable Event Timeline**: A high-performance canvas timeline pinpointing the exact training tick where cooperation fails.
41
+
42
+ ---
43
+
44
+ ## 💼 Core Use Cases
45
+
46
+ **For ML Engineers:**
47
+ * **Reduce Debugging Time**: Identify exactly when and why training instability occurs without waiting for the full epoc to finish.
48
+ * **Track Systemic Collapse**: Monitor reciprocity and role stability drops to catch model collapse early.
49
+ * **Offline Log Replay**: Stream huge offline CSV, JSON, NPZ, or TensorBoard training runs through the dashboard for retroactive analysis.
50
+
51
+ **For Researchers:**
52
+ * **Study Emergent Behavior**: Measure actual role specialization (Shannon entropy) and goal convergence (Cosine similarity).
53
+ * **Validate Alignment**: Visually confirm that your agents are forming expected coalitions in environments like SMAC (StarCraft II) or MPE.
54
+
55
+ ---
56
+
57
+ ## 🚀 Quick Start
58
+
59
+ ### Installation
60
+
61
+ Install AlignScope directly via PyPI:
62
+
63
+ ```bash
64
+ pip install alignscope
65
+ ```
66
+
67
+ ### Starting the Dashboard
68
+
69
+ Launch the real-time visualization server:
70
+
71
+ ```bash
72
+ alignscope start
73
+ ```
74
+
75
+ Open **http://localhost:8000** and watch agents interact live.
76
+
77
+
78
+ ## Why AlignScope?
79
+
80
+ Training MARL agents is hard. Understanding *why* they succeed or fail is harder. Most researchers rely on reward curves and terminal logs — but those don't tell you:
81
+
82
+ - **When** did cooperation break down?
83
+ - **Which** agent defected, and why?
84
+ - **How** are coalitions forming and dissolving over time?
85
+ - **Are** agents actually specializing into useful roles?
86
+
87
+ AlignScope answers all of these questions **visually and in real time**.
88
+
89
+ ### Key Advantages
90
+
91
+ | Advantage | Description |
92
+ |-----------|-------------|
93
+ | **Zero-code integration** | One line (`alignscope.wrap(env)`) to instrument any PettingZoo environment |
94
+ | **Environment agnostic** | Works with PettingZoo, SMAC, RLlib, EPyMARL, or any custom env |
95
+ | **Real-time dashboard** | Watch agents move, form coalitions, and defect as training runs |
96
+ | **Scientific precision** | Pinpoints the exact tick where cooperation fails |
97
+ | **No vendor lock-in** | Forwards metrics to W&B and MLflow automatically if installed |
98
+ | **Offline replay** | Replay saved CSV, JSON, NPZ, TensorBoard, or W&B logs into the dashboard |
99
+
100
+
101
+ ## Supported MARL Environments
102
+
103
+ AlignScope is designed to work with **any** multi-agent system. Here are the environments with dedicated adapters:
104
+
105
+ ### 1. PettingZoo (Cooperative & Classic Games)
106
+
107
+ PettingZoo is the most widely used MARL framework. AlignScope wraps **any** PettingZoo environment — AEC or Parallel API — with a single line.
108
+
109
+ ```python
110
+ import alignscope
111
+ from pettingzoo.butterfly import knights_archers_zombies_v10
112
+
113
+ # 1. Initialize your environment
114
+ env = knights_archers_zombies_v10.env()
115
+
116
+ # 2. Add one line to wrap it with AlignScope
117
+ env = alignscope.wrap(env)
118
+
119
+ # 3. Run your standard training loop!
120
+ env.reset()
121
+ for agent in env.agent_iter():
122
+ obs, reward, term, trunc, info = env.last()
123
+ action = env.action_space(agent).sample() if not (term or trunc) else None
124
+ env.step(action)
125
+ ```
126
+
127
+ *(See `examples/` for templates using RLlib, SMAC, and offline log replay.)*
128
+
129
+ ---
130
+
131
+ ## 🤝 Contributing & Support
132
+
133
+ We welcome contributions! Whether it's adding a new environment adapter, optimizing the frontend canvas renderer, or designing new alignment metrics.
134
+
135
+ For support, issues, or professional inquiries, please [open an issue](https://github.com/raghavarajunithisha-lab/AlignScopeV1/issues) or reach out directly:
136
+ 📧 **nithisha2201@gmail.com**
137
+
138
+ *Designed and maintained by Nithisha.*
@@ -0,0 +1,150 @@
1
+ """
2
+ AlignScope — Real-time alignment observability for multi-agent RL.
3
+
4
+ Usage:
5
+ import alignscope
6
+
7
+ # Initialize a tracking run
8
+ alignscope.init(project="my-experiment")
9
+
10
+ # In your training loop, add one line:
11
+ alignscope.log(step, agents, obs, actions, rewards)
12
+
13
+ # Or start the dashboard server:
14
+ alignscope.start(port=8000, demo=True)
15
+
16
+ # Framework-specific integrations:
17
+ alignscope.patch("rllib") # Auto-patch RLlib
18
+ env = alignscope.wrap(env) # Wrap PettingZoo env
19
+ """
20
+
21
+ from typing import Optional, Union
22
+
23
+ __version__ = "0.1.0"
24
+
25
+ from alignscope.sdk import AlignScopeTracker
26
+
27
+ # Module-level singleton tracker
28
+ _tracker: Optional[AlignScopeTracker] = None
29
+
30
+
31
+ def init(
32
+ project: str = "default",
33
+ server_url: str = "ws://localhost:8000/ws/sdk",
34
+ preset: Optional[str] = None,
35
+ paradigm: Optional[dict] = None,
36
+ metrics: Optional[list] = None,
37
+ events: Optional[list] = None,
38
+ topology: Optional[dict] = None,
39
+ config: Optional[dict] = None,
40
+ forward_wandb: bool = True,
41
+ forward_mlflow: bool = True,
42
+ ) -> AlignScopeTracker:
43
+ """
44
+ Initialize an AlignScope tracking session.
45
+
46
+ Args:
47
+ project: Name for this experiment run
48
+ server_url: WebSocket URL of the AlignScope dashboard server
49
+ config: Optional environment config (teams, roles, etc.)
50
+ forward_wandb: If True and wandb is installed, forward metrics to W&B
51
+ forward_mlflow: If True and mlflow is installed, forward metrics to MLflow
52
+
53
+ Returns:
54
+ AlignScopeTracker instance
55
+ """
56
+ global _tracker
57
+ _tracker = AlignScopeTracker(
58
+ project=project,
59
+ server_url=server_url,
60
+ preset=preset,
61
+ paradigm=paradigm,
62
+ metrics=metrics,
63
+ events=events,
64
+ topology=topology,
65
+ config=config,
66
+ forward_wandb=forward_wandb,
67
+ forward_mlflow=forward_mlflow,
68
+ )
69
+ return _tracker
70
+
71
+
72
+ def log(
73
+ step: int,
74
+ agents = None,
75
+ obs: object = None,
76
+ actions: object = None,
77
+ rewards: object = None,
78
+ **kwargs,
79
+ ) -> None:
80
+ """
81
+ Log one step of multi-agent data. This is the Tier 2 one-line API.
82
+
83
+ Args:
84
+ step: Current timestep / tick number
85
+ agents: Agent states — list of dicts or framework-specific format
86
+ obs: Observations (auto-normalized from framework format)
87
+ actions: Actions taken (auto-normalized)
88
+ rewards: Rewards received (auto-normalized)
89
+ **kwargs: Additional data to attach to this step
90
+ """
91
+ global _tracker
92
+ if _tracker is None:
93
+ # Auto-init with defaults if not explicitly initialized
94
+ init()
95
+ _tracker.log(step, agents=agents, obs=obs, actions=actions, rewards=rewards, **kwargs)
96
+
97
+
98
+ def report(tick: int, agent: Union[str, int], metrics: dict) -> None:
99
+ """Dynamically report custom metrics for an agent."""
100
+ global _tracker
101
+ if _tracker is None:
102
+ init()
103
+ _tracker.report(tick, agent, metrics)
104
+
105
+
106
+ def event(tick: int, type: str, agent: Union[str, int], detail: str, severity: float = 0.5) -> None:
107
+ """Dynamically report custom events."""
108
+ global _tracker
109
+ if _tracker is None:
110
+ init()
111
+ _tracker.event(tick, type, agent, detail, severity)
112
+
113
+
114
+ def start(port: int = 8000, host: str = "0.0.0.0", demo: bool = False) -> None:
115
+ """
116
+ Start the AlignScope dashboard server.
117
+
118
+ Args:
119
+ port: Port to serve on (default 8000)
120
+ host: Host to bind to (default 0.0.0.0)
121
+ demo: If True, run the built-in demo simulator
122
+ """
123
+ from alignscope.server import run_server
124
+ run_server(host=host, port=port, demo=demo)
125
+
126
+
127
+ def patch(framework: str) -> None:
128
+ """
129
+ Auto-patch a MARL framework for zero-code integration (Tier 1).
130
+
131
+ Args:
132
+ framework: One of "rllib", "pettingzoo", "pymarl"
133
+ """
134
+ from alignscope.patches import apply_patch
135
+ apply_patch(framework)
136
+
137
+
138
+ def wrap(env, **kwargs):
139
+ """
140
+ Wrap a PettingZoo environment for automatic logging (Tier 3).
141
+
142
+ Args:
143
+ env: A PettingZoo environment instance
144
+ **kwargs: Additional config passed to the wrapper
145
+
146
+ Returns:
147
+ Wrapped environment that auto-logs to AlignScope
148
+ """
149
+ from alignscope.patches.pettingzoo import AlignScopeWrapper
150
+ return AlignScopeWrapper(env, **kwargs)