alignscope 0.1.0__py3-none-any.whl
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.
- alignscope/__init__.py +150 -0
- alignscope/_frontend/css/style.css +663 -0
- alignscope/_frontend/index.html +169 -0
- alignscope/_frontend/js/app.js +360 -0
- alignscope/_frontend/js/metrics.js +220 -0
- alignscope/_frontend/js/timeline.js +494 -0
- alignscope/_frontend/js/topology.js +368 -0
- alignscope/adapters.py +169 -0
- alignscope/cli.py +99 -0
- alignscope/detector.py +242 -0
- alignscope/integrations/__init__.py +28 -0
- alignscope/integrations/mlflow_bridge.py +70 -0
- alignscope/integrations/wandb_bridge.py +81 -0
- alignscope/metrics.py +383 -0
- alignscope/patches/__init__.py +50 -0
- alignscope/patches/pettingzoo.py +332 -0
- alignscope/patches/pymarl.py +277 -0
- alignscope/patches/rllib.py +170 -0
- alignscope/sdk.py +606 -0
- alignscope/server.py +298 -0
- alignscope/simulator.py +493 -0
- alignscope-0.1.0.dist-info/METADATA +183 -0
- alignscope-0.1.0.dist-info/RECORD +26 -0
- alignscope-0.1.0.dist-info/WHEEL +4 -0
- alignscope-0.1.0.dist-info/entry_points.txt +2 -0
- alignscope-0.1.0.dist-info/licenses/LICENSE +21 -0
alignscope/__init__.py
ADDED
|
@@ -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)
|