saferl-lite 0.1.0__tar.gz → 0.1.2__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 (39) hide show
  1. saferl_lite-0.1.2/PKG-INFO +239 -0
  2. saferl_lite-0.1.2/README.md +187 -0
  3. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/about.md +1 -1
  4. saferl_lite-0.1.2/saferl_lite.egg-info/PKG-INFO +239 -0
  5. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/setup.py +2 -2
  6. saferl_lite-0.1.0/PKG-INFO +0 -139
  7. saferl_lite-0.1.0/README.md +0 -87
  8. saferl_lite-0.1.0/saferl_lite.egg-info/PKG-INFO +0 -139
  9. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/LICENSE +0 -0
  10. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/MANIFEST.in +0 -0
  11. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/agents/__init__.py +0 -0
  12. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/agents/constrained_dqn.py +0 -0
  13. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/agents/constraints.py +0 -0
  14. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/docs/index.md +0 -0
  15. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/evaluation/metrics.md +0 -0
  16. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/examples/cartpole.md +0 -0
  17. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/explainability/saliency.md +0 -0
  18. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/explainability/shap.md +0 -0
  19. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/mkdocs.yml +0 -0
  20. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/reference/agents.md +0 -0
  21. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/reference/constraints.md +0 -0
  22. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/reference/envs.md +0 -0
  23. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/reference.md +0 -0
  24. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/usage/installation.md +0 -0
  25. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/docs/usage/quickstart.md +0 -0
  26. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/envs/__init__.py +0 -0
  27. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/envs/wrappers.py +0 -0
  28. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/explainability/__init__.py +0 -0
  29. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/explainability/saliency.py +0 -0
  30. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/explainability/shap_explainer.py +0 -0
  31. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/requirements.txt +0 -0
  32. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/saferl_lite.egg-info/SOURCES.txt +0 -0
  33. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/saferl_lite.egg-info/dependency_links.txt +0 -0
  34. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/saferl_lite.egg-info/requires.txt +0 -0
  35. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/saferl_lite.egg-info/top_level.txt +0 -0
  36. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/setup.cfg +0 -0
  37. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/tests/test_constraints.py +0 -0
  38. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/tests/test_metrics.py +0 -0
  39. {saferl_lite-0.1.0 → saferl_lite-0.1.2}/tests/test_safe_env.py +0 -0
@@ -0,0 +1,239 @@
1
+ Metadata-Version: 2.4
2
+ Name: saferl-lite
3
+ Version: 0.1.2
4
+ Summary: A lightweight, explainable, and constrained reinforcement learning toolkit.
5
+ Home-page: https://github.com/satyamcser/saferl-lite
6
+ Author: Satyam Mishra
7
+ Author-email: satyam@example.com
8
+ Project-URL: Documentation, https://github.com/satyamcser/saferl-lite/tree/main/docs
9
+ Project-URL: Source, https://github.com/satyamcser/saferl-lite
10
+ Project-URL: Bug Tracker, https://github.com/satyamcser/saferl-lite/issues
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Requires-Python: >=3.8
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: gym
20
+ Requires-Dist: gymnasium
21
+ Requires-Dist: numpy
22
+ Requires-Dist: torch
23
+ Requires-Dist: matplotlib
24
+ Requires-Dist: seaborn
25
+ Requires-Dist: pre-commit
26
+ Requires-Dist: flake8
27
+ Requires-Dist: pyyaml
28
+ Requires-Dist: shap
29
+ Requires-Dist: captum
30
+ Requires-Dist: typer
31
+ Requires-Dist: scikit-learn
32
+ Requires-Dist: pandas
33
+ Requires-Dist: pytest
34
+ Requires-Dist: pytest-cov
35
+ Requires-Dist: coverage
36
+ Requires-Dist: mkdocs
37
+ Requires-Dist: wandb
38
+ Requires-Dist: mkdocs>=1.5
39
+ Requires-Dist: mkdocs-material>=9.5
40
+ Requires-Dist: mkdocstrings[python]
41
+ Dynamic: author
42
+ Dynamic: author-email
43
+ Dynamic: classifier
44
+ Dynamic: description
45
+ Dynamic: description-content-type
46
+ Dynamic: home-page
47
+ Dynamic: license-file
48
+ Dynamic: project-url
49
+ Dynamic: requires-dist
50
+ Dynamic: requires-python
51
+ Dynamic: summary
52
+
53
+ # 🔐 SafeRL-Lite
54
+
55
+ A **lightweight, explainable, and modular** Python library for **Constrained Reinforcement Learning (Safe RL)** with real-time **SHAP & saliency-based explainability**, custom metrics, and Gym-compatible wrappers.
56
+
57
+ By:
58
+ - Satyam Mishra, Vision Mentors Ltd., Hanoi, Vietnam
59
+ - Shivam Mishra, Phung Thao Vi, Vietnam National University, Hanoi, Vietnam
60
+ - Dr. Vishwanath Bijalwan, SR University, Warangal, India
61
+ - Dr. Vijay Bhaskar Semwal, MANIT, Bhopal, India
62
+ - University of West London, London, UK
63
+
64
+ <p align="center">
65
+ <a href="https://github.com/satyamcser/saferl-lite/blob/main/LICENSE">
66
+ <img src="https://img.shields.io/github/license/satyamcser/saferl-lite?style=flat-square" alt="License">
67
+ </a>
68
+ <a href="https://github.com/satyamcser/saferl-lite/stargazers">
69
+ <img src="https://img.shields.io/github/stars/satyamcser/saferl-lite?style=flat-square" alt="Stars">
70
+ </a>
71
+ <a href="https://pypi.org/project/saferl-lite/">
72
+ <img src="https://img.shields.io/pypi/v/saferl-lite?style=flat-square" alt="PyPI version">
73
+ </a>
74
+ <a href="https://github.com/satyamcser/saferl-lite/actions/workflows/ci.yml">
75
+ <img src="https://img.shields.io/github/actions/workflow/status/satyamcser/saferl-lite/ci.yml?branch=main&style=flat-square" alt="Build Status">
76
+ </a>
77
+ </p>
78
+
79
+
80
+ ---
81
+
82
+ ## 🌟 Overview
83
+
84
+ **SafeRL-Lite** empowers reinforcement learning agents to act under **safety constraints**, while remaining **interpretable** and **modular** for fast experimentation. It wraps standard Gym environments and DQN-based agents with:
85
+
86
+ - ✅ Safety constraint logic
87
+ - 🔍 Visual explainability (SHAP, saliency maps)
88
+ - 📊 Violation and reward tracking
89
+ - 🧪 Built-in testing and evaluations
90
+
91
+ ---
92
+
93
+ ## ✅ Problem We Solved
94
+
95
+ Modern Reinforcement Learning (RL) agents are powerful but unsafe and opaque:
96
+
97
+ - 🚫 They frequently violate safety constraints during learning or deployment (e.g., fall off a cliff in navigation tasks).
98
+
99
+ - 😕 Their decision-making is a black box: humans can’t understand why a certain action was chosen.
100
+
101
+ - 🔍 Standard RL libraries lack native support for:
102
+
103
+ - Enforcing hard constraints during training.
104
+
105
+ - Explaining decisions using methods like SHAP or saliency maps.
106
+
107
+ ## ✅ Our Solution
108
+ SafeRL-Lite is a lightweight Python library that:
109
+
110
+ 1. 📏 Adds a SafetyWrapper around any Gym environment to enforce safety constraints (e.g., bounding actions, limiting states).
111
+
112
+ 2. 🧠 Integrates explainability methods:
113
+
114
+ - SHAPExplainer (model-agnostic local explanations).
115
+
116
+ - SaliencyExplainer (gradient-based sensitivity maps).
117
+
118
+ 3. 🔧 Wraps Constrained DQNs with ease, enabling safety-compliant Q-learning.
119
+
120
+ 4. 📊 Offers built-in metrics like violation count and safe episode tracking.
121
+
122
+ ## ✅ Novelty
123
+ While Safe RL and Explainable RL are separately studied, no prior lightweight library:
124
+
125
+ - Combines hard safety constraints with post-hoc interpretability.
126
+
127
+ - Is designed to be minimal, pluggable, and easily installable (pip install saferl-lite) for education, experimentation, or safe deployment.
128
+
129
+ - Enables real-time SHAP or saliency visualization for Gym-based agents out-of-the-box.
130
+ ``` bash
131
+ SafeRL-Lite is the first minimal library to unify constraint satisfaction and explainability in reinforcement learning — without heavy dependencies or overhead.
132
+ ```
133
+
134
+ ## ✅ Our Contribution
135
+ 1. 🔐 Constraint Wrapper API: Drop-in Gym wrapper for defining and enforcing logical constraints on observations, actions, and reward signals.
136
+
137
+ 2. 🧠 Explainability Modules: Plug-and-play SHAP and saliency explainer classes for deep Q-networks.
138
+
139
+ 3. 📦 PyPI-Ready Toolkit: Easily installed, documented, and CI/CD tested; built for research and reproducibility.
140
+
141
+ 4. 📈 Metrics for Constraint Violation: Tracks unsafe episodes, per-step violations, and integrates cleanly with WandB or TensorBoard.
142
+
143
+ ## ✅ Technical Explanation
144
+ - We define a custom SafeEnvWrapper(gym.Env) that:
145
+
146
+ - Intercepts actions.
147
+
148
+ - Applies logical rules or thresholding.
149
+
150
+ - Optionally overrides rewards or terminations if constraints are violated.
151
+
152
+ - A ConstrainedDQNAgent uses:
153
+
154
+ - Safety-wrapped Gym envs.
155
+
156
+ - Standard Q-learning with optional penalty_on_violation flag.
157
+
158
+ - Post-training, the SHAPExplainer and SaliencyExplainer:
159
+
160
+ - Generate local attributions using input perturbations or gradient norms.
161
+
162
+ - Can visualize per-state or per-action explanations.
163
+
164
+
165
+
166
+ ## ✅ Satyam's Explanation
167
+ ```bash
168
+ Imagine you're teaching a robot to walk — but there’s lava on the floor!
169
+ You don’t just want it to learn fast, you want it to stay safe and explain why it stepped left, not right.
170
+ ```
171
+ SafeRL-Lite is like a safety helmet and voicebox for robots:
172
+
173
+ - The helmet makes sure they don’t do dangerous stuff.
174
+
175
+ - The voicebox lets them say why they made that move.
176
+
177
+ ## 🔧 Installation
178
+
179
+ > 📦 PyPI
180
+ ```bash
181
+ pip install saferl-lite
182
+ ```
183
+
184
+ ## 🛠️ From source:
185
+
186
+ ```bash
187
+ git clone https://github.com/satyamcser/saferl-lite.git
188
+ cd saferl-lite
189
+ pip install -e .
190
+ ```
191
+
192
+ ## 🚀 Quickstart
193
+ Train a constrained DQN agent with saliency-based explainability:
194
+
195
+ ```bash
196
+ python train.py --env CartPole-v1 --constraint pole_angle --explain shap
197
+ ```
198
+
199
+ 🔹 This:
200
+
201
+ - Adds a pole-angle constraint wrapper to the Gym env
202
+
203
+ - Logs violations
204
+
205
+ - Displays SHAP or saliency explanations for agent decisions
206
+
207
+ ## 🧠 Features
208
+ #### ✅ Constrained RL
209
+ - Add custom constraints via wrapper or logic class
210
+
211
+ - Violation logging and reward shaping
212
+
213
+ - Safe vs unsafe episode tracking
214
+
215
+ #### 🔍 Explainability
216
+ - SaliencyExplainer — gradient-based visual heatmaps
217
+
218
+ - SHAPExplainer — feature contribution values per decision
219
+
220
+ - Compatible with any PyTorch-based agent
221
+
222
+ #### 📊 Metrics
223
+ - Constraint violation rate
224
+
225
+ - Episode reward
226
+
227
+ - Cumulative safe reward
228
+
229
+ - Action entropy & temporal behavior stats
230
+
231
+ #### 📚 Modularity
232
+ - Swap out agents, constraints, evaluators, or explainers
233
+
234
+ - Supports Gym environments
235
+
236
+ - Configurable training pipeline
237
+
238
+ ## 📜 Citation
239
+ Coming soon after arXiv/preprint release.
@@ -0,0 +1,187 @@
1
+ # 🔐 SafeRL-Lite
2
+
3
+ A **lightweight, explainable, and modular** Python library for **Constrained Reinforcement Learning (Safe RL)** with real-time **SHAP & saliency-based explainability**, custom metrics, and Gym-compatible wrappers.
4
+
5
+ By:
6
+ - Satyam Mishra, Vision Mentors Ltd., Hanoi, Vietnam
7
+ - Shivam Mishra, Phung Thao Vi, Vietnam National University, Hanoi, Vietnam
8
+ - Dr. Vishwanath Bijalwan, SR University, Warangal, India
9
+ - Dr. Vijay Bhaskar Semwal, MANIT, Bhopal, India
10
+ - University of West London, London, UK
11
+
12
+ <p align="center">
13
+ <a href="https://github.com/satyamcser/saferl-lite/blob/main/LICENSE">
14
+ <img src="https://img.shields.io/github/license/satyamcser/saferl-lite?style=flat-square" alt="License">
15
+ </a>
16
+ <a href="https://github.com/satyamcser/saferl-lite/stargazers">
17
+ <img src="https://img.shields.io/github/stars/satyamcser/saferl-lite?style=flat-square" alt="Stars">
18
+ </a>
19
+ <a href="https://pypi.org/project/saferl-lite/">
20
+ <img src="https://img.shields.io/pypi/v/saferl-lite?style=flat-square" alt="PyPI version">
21
+ </a>
22
+ <a href="https://github.com/satyamcser/saferl-lite/actions/workflows/ci.yml">
23
+ <img src="https://img.shields.io/github/actions/workflow/status/satyamcser/saferl-lite/ci.yml?branch=main&style=flat-square" alt="Build Status">
24
+ </a>
25
+ </p>
26
+
27
+
28
+ ---
29
+
30
+ ## 🌟 Overview
31
+
32
+ **SafeRL-Lite** empowers reinforcement learning agents to act under **safety constraints**, while remaining **interpretable** and **modular** for fast experimentation. It wraps standard Gym environments and DQN-based agents with:
33
+
34
+ - ✅ Safety constraint logic
35
+ - 🔍 Visual explainability (SHAP, saliency maps)
36
+ - 📊 Violation and reward tracking
37
+ - 🧪 Built-in testing and evaluations
38
+
39
+ ---
40
+
41
+ ## ✅ Problem We Solved
42
+
43
+ Modern Reinforcement Learning (RL) agents are powerful but unsafe and opaque:
44
+
45
+ - 🚫 They frequently violate safety constraints during learning or deployment (e.g., fall off a cliff in navigation tasks).
46
+
47
+ - 😕 Their decision-making is a black box: humans can’t understand why a certain action was chosen.
48
+
49
+ - 🔍 Standard RL libraries lack native support for:
50
+
51
+ - Enforcing hard constraints during training.
52
+
53
+ - Explaining decisions using methods like SHAP or saliency maps.
54
+
55
+ ## ✅ Our Solution
56
+ SafeRL-Lite is a lightweight Python library that:
57
+
58
+ 1. 📏 Adds a SafetyWrapper around any Gym environment to enforce safety constraints (e.g., bounding actions, limiting states).
59
+
60
+ 2. 🧠 Integrates explainability methods:
61
+
62
+ - SHAPExplainer (model-agnostic local explanations).
63
+
64
+ - SaliencyExplainer (gradient-based sensitivity maps).
65
+
66
+ 3. 🔧 Wraps Constrained DQNs with ease, enabling safety-compliant Q-learning.
67
+
68
+ 4. 📊 Offers built-in metrics like violation count and safe episode tracking.
69
+
70
+ ## ✅ Novelty
71
+ While Safe RL and Explainable RL are separately studied, no prior lightweight library:
72
+
73
+ - Combines hard safety constraints with post-hoc interpretability.
74
+
75
+ - Is designed to be minimal, pluggable, and easily installable (pip install saferl-lite) for education, experimentation, or safe deployment.
76
+
77
+ - Enables real-time SHAP or saliency visualization for Gym-based agents out-of-the-box.
78
+ ``` bash
79
+ SafeRL-Lite is the first minimal library to unify constraint satisfaction and explainability in reinforcement learning — without heavy dependencies or overhead.
80
+ ```
81
+
82
+ ## ✅ Our Contribution
83
+ 1. 🔐 Constraint Wrapper API: Drop-in Gym wrapper for defining and enforcing logical constraints on observations, actions, and reward signals.
84
+
85
+ 2. 🧠 Explainability Modules: Plug-and-play SHAP and saliency explainer classes for deep Q-networks.
86
+
87
+ 3. 📦 PyPI-Ready Toolkit: Easily installed, documented, and CI/CD tested; built for research and reproducibility.
88
+
89
+ 4. 📈 Metrics for Constraint Violation: Tracks unsafe episodes, per-step violations, and integrates cleanly with WandB or TensorBoard.
90
+
91
+ ## ✅ Technical Explanation
92
+ - We define a custom SafeEnvWrapper(gym.Env) that:
93
+
94
+ - Intercepts actions.
95
+
96
+ - Applies logical rules or thresholding.
97
+
98
+ - Optionally overrides rewards or terminations if constraints are violated.
99
+
100
+ - A ConstrainedDQNAgent uses:
101
+
102
+ - Safety-wrapped Gym envs.
103
+
104
+ - Standard Q-learning with optional penalty_on_violation flag.
105
+
106
+ - Post-training, the SHAPExplainer and SaliencyExplainer:
107
+
108
+ - Generate local attributions using input perturbations or gradient norms.
109
+
110
+ - Can visualize per-state or per-action explanations.
111
+
112
+
113
+
114
+ ## ✅ Satyam's Explanation
115
+ ```bash
116
+ Imagine you're teaching a robot to walk — but there’s lava on the floor!
117
+ You don’t just want it to learn fast, you want it to stay safe and explain why it stepped left, not right.
118
+ ```
119
+ SafeRL-Lite is like a safety helmet and voicebox for robots:
120
+
121
+ - The helmet makes sure they don’t do dangerous stuff.
122
+
123
+ - The voicebox lets them say why they made that move.
124
+
125
+ ## 🔧 Installation
126
+
127
+ > 📦 PyPI
128
+ ```bash
129
+ pip install saferl-lite
130
+ ```
131
+
132
+ ## 🛠️ From source:
133
+
134
+ ```bash
135
+ git clone https://github.com/satyamcser/saferl-lite.git
136
+ cd saferl-lite
137
+ pip install -e .
138
+ ```
139
+
140
+ ## 🚀 Quickstart
141
+ Train a constrained DQN agent with saliency-based explainability:
142
+
143
+ ```bash
144
+ python train.py --env CartPole-v1 --constraint pole_angle --explain shap
145
+ ```
146
+
147
+ 🔹 This:
148
+
149
+ - Adds a pole-angle constraint wrapper to the Gym env
150
+
151
+ - Logs violations
152
+
153
+ - Displays SHAP or saliency explanations for agent decisions
154
+
155
+ ## 🧠 Features
156
+ #### ✅ Constrained RL
157
+ - Add custom constraints via wrapper or logic class
158
+
159
+ - Violation logging and reward shaping
160
+
161
+ - Safe vs unsafe episode tracking
162
+
163
+ #### 🔍 Explainability
164
+ - SaliencyExplainer — gradient-based visual heatmaps
165
+
166
+ - SHAPExplainer — feature contribution values per decision
167
+
168
+ - Compatible with any PyTorch-based agent
169
+
170
+ #### 📊 Metrics
171
+ - Constraint violation rate
172
+
173
+ - Episode reward
174
+
175
+ - Cumulative safe reward
176
+
177
+ - Action entropy & temporal behavior stats
178
+
179
+ #### 📚 Modularity
180
+ - Swap out agents, constraints, evaluators, or explainers
181
+
182
+ - Supports Gym environments
183
+
184
+ - Configurable training pipeline
185
+
186
+ ## 📜 Citation
187
+ Coming soon after arXiv/preprint release.
@@ -59,7 +59,7 @@ This project is licensed under the **MIT License**. See the [LICENSE](https://gi
59
59
  ## 🌐 Links
60
60
 
61
61
  - GitHub: [https://github.com/satyamcser/saferl-lite](https://github.com/satyamcser/saferl-lite)
62
- - PyPI: *Coming soon*
62
+ - PyPI: [https://pypi.org/project/saferl-lite/](https://pypi.org/project/saferl-lite/)
63
63
  - Docs: *This site*
64
64
 
65
65
  ---
@@ -0,0 +1,239 @@
1
+ Metadata-Version: 2.4
2
+ Name: saferl-lite
3
+ Version: 0.1.2
4
+ Summary: A lightweight, explainable, and constrained reinforcement learning toolkit.
5
+ Home-page: https://github.com/satyamcser/saferl-lite
6
+ Author: Satyam Mishra
7
+ Author-email: satyam@example.com
8
+ Project-URL: Documentation, https://github.com/satyamcser/saferl-lite/tree/main/docs
9
+ Project-URL: Source, https://github.com/satyamcser/saferl-lite
10
+ Project-URL: Bug Tracker, https://github.com/satyamcser/saferl-lite/issues
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Requires-Python: >=3.8
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: gym
20
+ Requires-Dist: gymnasium
21
+ Requires-Dist: numpy
22
+ Requires-Dist: torch
23
+ Requires-Dist: matplotlib
24
+ Requires-Dist: seaborn
25
+ Requires-Dist: pre-commit
26
+ Requires-Dist: flake8
27
+ Requires-Dist: pyyaml
28
+ Requires-Dist: shap
29
+ Requires-Dist: captum
30
+ Requires-Dist: typer
31
+ Requires-Dist: scikit-learn
32
+ Requires-Dist: pandas
33
+ Requires-Dist: pytest
34
+ Requires-Dist: pytest-cov
35
+ Requires-Dist: coverage
36
+ Requires-Dist: mkdocs
37
+ Requires-Dist: wandb
38
+ Requires-Dist: mkdocs>=1.5
39
+ Requires-Dist: mkdocs-material>=9.5
40
+ Requires-Dist: mkdocstrings[python]
41
+ Dynamic: author
42
+ Dynamic: author-email
43
+ Dynamic: classifier
44
+ Dynamic: description
45
+ Dynamic: description-content-type
46
+ Dynamic: home-page
47
+ Dynamic: license-file
48
+ Dynamic: project-url
49
+ Dynamic: requires-dist
50
+ Dynamic: requires-python
51
+ Dynamic: summary
52
+
53
+ # 🔐 SafeRL-Lite
54
+
55
+ A **lightweight, explainable, and modular** Python library for **Constrained Reinforcement Learning (Safe RL)** with real-time **SHAP & saliency-based explainability**, custom metrics, and Gym-compatible wrappers.
56
+
57
+ By:
58
+ - Satyam Mishra, Vision Mentors Ltd., Hanoi, Vietnam
59
+ - Shivam Mishra, Phung Thao Vi, Vietnam National University, Hanoi, Vietnam
60
+ - Dr. Vishwanath Bijalwan, SR University, Warangal, India
61
+ - Dr. Vijay Bhaskar Semwal, MANIT, Bhopal, India
62
+ - University of West London, London, UK
63
+
64
+ <p align="center">
65
+ <a href="https://github.com/satyamcser/saferl-lite/blob/main/LICENSE">
66
+ <img src="https://img.shields.io/github/license/satyamcser/saferl-lite?style=flat-square" alt="License">
67
+ </a>
68
+ <a href="https://github.com/satyamcser/saferl-lite/stargazers">
69
+ <img src="https://img.shields.io/github/stars/satyamcser/saferl-lite?style=flat-square" alt="Stars">
70
+ </a>
71
+ <a href="https://pypi.org/project/saferl-lite/">
72
+ <img src="https://img.shields.io/pypi/v/saferl-lite?style=flat-square" alt="PyPI version">
73
+ </a>
74
+ <a href="https://github.com/satyamcser/saferl-lite/actions/workflows/ci.yml">
75
+ <img src="https://img.shields.io/github/actions/workflow/status/satyamcser/saferl-lite/ci.yml?branch=main&style=flat-square" alt="Build Status">
76
+ </a>
77
+ </p>
78
+
79
+
80
+ ---
81
+
82
+ ## 🌟 Overview
83
+
84
+ **SafeRL-Lite** empowers reinforcement learning agents to act under **safety constraints**, while remaining **interpretable** and **modular** for fast experimentation. It wraps standard Gym environments and DQN-based agents with:
85
+
86
+ - ✅ Safety constraint logic
87
+ - 🔍 Visual explainability (SHAP, saliency maps)
88
+ - 📊 Violation and reward tracking
89
+ - 🧪 Built-in testing and evaluations
90
+
91
+ ---
92
+
93
+ ## ✅ Problem We Solved
94
+
95
+ Modern Reinforcement Learning (RL) agents are powerful but unsafe and opaque:
96
+
97
+ - 🚫 They frequently violate safety constraints during learning or deployment (e.g., fall off a cliff in navigation tasks).
98
+
99
+ - 😕 Their decision-making is a black box: humans can’t understand why a certain action was chosen.
100
+
101
+ - 🔍 Standard RL libraries lack native support for:
102
+
103
+ - Enforcing hard constraints during training.
104
+
105
+ - Explaining decisions using methods like SHAP or saliency maps.
106
+
107
+ ## ✅ Our Solution
108
+ SafeRL-Lite is a lightweight Python library that:
109
+
110
+ 1. 📏 Adds a SafetyWrapper around any Gym environment to enforce safety constraints (e.g., bounding actions, limiting states).
111
+
112
+ 2. 🧠 Integrates explainability methods:
113
+
114
+ - SHAPExplainer (model-agnostic local explanations).
115
+
116
+ - SaliencyExplainer (gradient-based sensitivity maps).
117
+
118
+ 3. 🔧 Wraps Constrained DQNs with ease, enabling safety-compliant Q-learning.
119
+
120
+ 4. 📊 Offers built-in metrics like violation count and safe episode tracking.
121
+
122
+ ## ✅ Novelty
123
+ While Safe RL and Explainable RL are separately studied, no prior lightweight library:
124
+
125
+ - Combines hard safety constraints with post-hoc interpretability.
126
+
127
+ - Is designed to be minimal, pluggable, and easily installable (pip install saferl-lite) for education, experimentation, or safe deployment.
128
+
129
+ - Enables real-time SHAP or saliency visualization for Gym-based agents out-of-the-box.
130
+ ``` bash
131
+ SafeRL-Lite is the first minimal library to unify constraint satisfaction and explainability in reinforcement learning — without heavy dependencies or overhead.
132
+ ```
133
+
134
+ ## ✅ Our Contribution
135
+ 1. 🔐 Constraint Wrapper API: Drop-in Gym wrapper for defining and enforcing logical constraints on observations, actions, and reward signals.
136
+
137
+ 2. 🧠 Explainability Modules: Plug-and-play SHAP and saliency explainer classes for deep Q-networks.
138
+
139
+ 3. 📦 PyPI-Ready Toolkit: Easily installed, documented, and CI/CD tested; built for research and reproducibility.
140
+
141
+ 4. 📈 Metrics for Constraint Violation: Tracks unsafe episodes, per-step violations, and integrates cleanly with WandB or TensorBoard.
142
+
143
+ ## ✅ Technical Explanation
144
+ - We define a custom SafeEnvWrapper(gym.Env) that:
145
+
146
+ - Intercepts actions.
147
+
148
+ - Applies logical rules or thresholding.
149
+
150
+ - Optionally overrides rewards or terminations if constraints are violated.
151
+
152
+ - A ConstrainedDQNAgent uses:
153
+
154
+ - Safety-wrapped Gym envs.
155
+
156
+ - Standard Q-learning with optional penalty_on_violation flag.
157
+
158
+ - Post-training, the SHAPExplainer and SaliencyExplainer:
159
+
160
+ - Generate local attributions using input perturbations or gradient norms.
161
+
162
+ - Can visualize per-state or per-action explanations.
163
+
164
+
165
+
166
+ ## ✅ Satyam's Explanation
167
+ ```bash
168
+ Imagine you're teaching a robot to walk — but there’s lava on the floor!
169
+ You don’t just want it to learn fast, you want it to stay safe and explain why it stepped left, not right.
170
+ ```
171
+ SafeRL-Lite is like a safety helmet and voicebox for robots:
172
+
173
+ - The helmet makes sure they don’t do dangerous stuff.
174
+
175
+ - The voicebox lets them say why they made that move.
176
+
177
+ ## 🔧 Installation
178
+
179
+ > 📦 PyPI
180
+ ```bash
181
+ pip install saferl-lite
182
+ ```
183
+
184
+ ## 🛠️ From source:
185
+
186
+ ```bash
187
+ git clone https://github.com/satyamcser/saferl-lite.git
188
+ cd saferl-lite
189
+ pip install -e .
190
+ ```
191
+
192
+ ## 🚀 Quickstart
193
+ Train a constrained DQN agent with saliency-based explainability:
194
+
195
+ ```bash
196
+ python train.py --env CartPole-v1 --constraint pole_angle --explain shap
197
+ ```
198
+
199
+ 🔹 This:
200
+
201
+ - Adds a pole-angle constraint wrapper to the Gym env
202
+
203
+ - Logs violations
204
+
205
+ - Displays SHAP or saliency explanations for agent decisions
206
+
207
+ ## 🧠 Features
208
+ #### ✅ Constrained RL
209
+ - Add custom constraints via wrapper or logic class
210
+
211
+ - Violation logging and reward shaping
212
+
213
+ - Safe vs unsafe episode tracking
214
+
215
+ #### 🔍 Explainability
216
+ - SaliencyExplainer — gradient-based visual heatmaps
217
+
218
+ - SHAPExplainer — feature contribution values per decision
219
+
220
+ - Compatible with any PyTorch-based agent
221
+
222
+ #### 📊 Metrics
223
+ - Constraint violation rate
224
+
225
+ - Episode reward
226
+
227
+ - Cumulative safe reward
228
+
229
+ - Action entropy & temporal behavior stats
230
+
231
+ #### 📚 Modularity
232
+ - Swap out agents, constraints, evaluators, or explainers
233
+
234
+ - Supports Gym environments
235
+
236
+ - Configurable training pipeline
237
+
238
+ ## 📜 Citation
239
+ Coming soon after arXiv/preprint release.
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="saferl-lite",
5
- version="0.1.0",
5
+ version="0.1.2",
6
6
  author="Satyam Mishra",
7
7
  author_email="satyam@example.com",
8
8
  description="A lightweight, explainable, and constrained reinforcement learning toolkit.",
@@ -10,7 +10,7 @@ setup(
10
10
  long_description_content_type="text/markdown",
11
11
  url="https://github.com/satyamcser/saferl-lite",
12
12
  project_urls={
13
- "Documentation": "https://satyamcser.github.io/saferl-lite/",
13
+ "Documentation": "https://github.com/satyamcser/saferl-lite/tree/main/docs",
14
14
  "Source": "https://github.com/satyamcser/saferl-lite",
15
15
  "Bug Tracker": "https://github.com/satyamcser/saferl-lite/issues",
16
16
  },
@@ -1,139 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: saferl-lite
3
- Version: 0.1.0
4
- Summary: A lightweight, explainable, and constrained reinforcement learning toolkit.
5
- Home-page: https://github.com/satyamcser/saferl-lite
6
- Author: Satyam Mishra
7
- Author-email: satyam@example.com
8
- Project-URL: Documentation, https://satyamcser.github.io/saferl-lite/
9
- Project-URL: Source, https://github.com/satyamcser/saferl-lite
10
- Project-URL: Bug Tracker, https://github.com/satyamcser/saferl-lite/issues
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: OS Independent
14
- Classifier: Intended Audience :: Science/Research
15
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
- Requires-Python: >=3.8
17
- Description-Content-Type: text/markdown
18
- License-File: LICENSE
19
- Requires-Dist: gym
20
- Requires-Dist: gymnasium
21
- Requires-Dist: numpy
22
- Requires-Dist: torch
23
- Requires-Dist: matplotlib
24
- Requires-Dist: seaborn
25
- Requires-Dist: pre-commit
26
- Requires-Dist: flake8
27
- Requires-Dist: pyyaml
28
- Requires-Dist: shap
29
- Requires-Dist: captum
30
- Requires-Dist: typer
31
- Requires-Dist: scikit-learn
32
- Requires-Dist: pandas
33
- Requires-Dist: pytest
34
- Requires-Dist: pytest-cov
35
- Requires-Dist: coverage
36
- Requires-Dist: mkdocs
37
- Requires-Dist: wandb
38
- Requires-Dist: mkdocs>=1.5
39
- Requires-Dist: mkdocs-material>=9.5
40
- Requires-Dist: mkdocstrings[python]
41
- Dynamic: author
42
- Dynamic: author-email
43
- Dynamic: classifier
44
- Dynamic: description
45
- Dynamic: description-content-type
46
- Dynamic: home-page
47
- Dynamic: license-file
48
- Dynamic: project-url
49
- Dynamic: requires-dist
50
- Dynamic: requires-python
51
- Dynamic: summary
52
-
53
- # 🔐 SafeRL-Lite
54
-
55
- A **lightweight, explainable, and modular** Python library for **Constrained Reinforcement Learning (Safe RL)** with real-time **SHAP & saliency-based explainability**, custom metrics, and Gym-compatible wrappers.
56
-
57
- <p align="center">
58
- <img src="https://img.shields.io/github/license/satyamcser/saferl-lite?style=flat-square">
59
- <img src="https://img.shields.io/github/stars/satyamcser/saferl-lite?style=flat-square">
60
- <img src="https://img.shields.io/pypi/v/saferl-lite?style=flat-square">
61
- <img src="https://img.shields.io/github/actions/workflow/status/satyamcser/saferl-lite/ci.yml?branch=main&style=flat-square">
62
- </p>
63
-
64
- ---
65
-
66
- ## 🌟 Overview
67
-
68
- **SafeRL-Lite** empowers reinforcement learning agents to act under **safety constraints**, while remaining **interpretable** and **modular** for fast experimentation. It wraps standard Gym environments and DQN-based agents with:
69
-
70
- - ✅ Safety constraint logic
71
- - 🔍 Visual explainability (SHAP, saliency maps)
72
- - 📊 Violation and reward tracking
73
- - 🧪 Built-in testing and evaluations
74
-
75
- ---
76
-
77
- ## 🔧 Installation
78
-
79
- > 📦 PyPI (coming soon)
80
- ```bash
81
- pip install saferl-lite
82
- ```
83
-
84
- ## 🛠️ From source:
85
-
86
- ```bash
87
- git clone https://github.com/satyamcser/saferl-lite.git
88
- cd saferl-lite
89
- pip install -e .
90
- ```
91
-
92
- ## 🚀 Quickstart
93
- Train a constrained DQN agent with saliency-based explainability:
94
-
95
- ```bash
96
- python train.py --env CartPole-v1 --constraint pole_angle --explain shap
97
- ```
98
-
99
- 🔹 This:
100
-
101
- - Adds a pole-angle constraint wrapper to the Gym env
102
-
103
- - Logs violations
104
-
105
- - Displays SHAP or saliency explanations for agent decisions
106
-
107
- ## 🧠 Features
108
- #### ✅ Constrained RL
109
- - Add custom constraints via wrapper or logic class
110
-
111
- - Violation logging and reward shaping
112
-
113
- - Safe vs unsafe episode tracking
114
-
115
- #### 🔍 Explainability
116
- - SaliencyExplainer — gradient-based visual heatmaps
117
-
118
- - SHAPExplainer — feature contribution values per decision
119
-
120
- - Compatible with any PyTorch-based agent
121
-
122
- #### 📊 Metrics
123
- - Constraint violation rate
124
-
125
- - Episode reward
126
-
127
- - Cumulative safe reward
128
-
129
- - Action entropy & temporal behavior stats
130
-
131
- #### 📚 Modularity
132
- - Swap out agents, constraints, evaluators, or explainers
133
-
134
- - Supports Gym environments
135
-
136
- - Configurable training pipeline
137
-
138
- ## 📜 Citation
139
- Coming soon after arXiv/preprint release.
@@ -1,87 +0,0 @@
1
- # 🔐 SafeRL-Lite
2
-
3
- A **lightweight, explainable, and modular** Python library for **Constrained Reinforcement Learning (Safe RL)** with real-time **SHAP & saliency-based explainability**, custom metrics, and Gym-compatible wrappers.
4
-
5
- <p align="center">
6
- <img src="https://img.shields.io/github/license/satyamcser/saferl-lite?style=flat-square">
7
- <img src="https://img.shields.io/github/stars/satyamcser/saferl-lite?style=flat-square">
8
- <img src="https://img.shields.io/pypi/v/saferl-lite?style=flat-square">
9
- <img src="https://img.shields.io/github/actions/workflow/status/satyamcser/saferl-lite/ci.yml?branch=main&style=flat-square">
10
- </p>
11
-
12
- ---
13
-
14
- ## 🌟 Overview
15
-
16
- **SafeRL-Lite** empowers reinforcement learning agents to act under **safety constraints**, while remaining **interpretable** and **modular** for fast experimentation. It wraps standard Gym environments and DQN-based agents with:
17
-
18
- - ✅ Safety constraint logic
19
- - 🔍 Visual explainability (SHAP, saliency maps)
20
- - 📊 Violation and reward tracking
21
- - 🧪 Built-in testing and evaluations
22
-
23
- ---
24
-
25
- ## 🔧 Installation
26
-
27
- > 📦 PyPI (coming soon)
28
- ```bash
29
- pip install saferl-lite
30
- ```
31
-
32
- ## 🛠️ From source:
33
-
34
- ```bash
35
- git clone https://github.com/satyamcser/saferl-lite.git
36
- cd saferl-lite
37
- pip install -e .
38
- ```
39
-
40
- ## 🚀 Quickstart
41
- Train a constrained DQN agent with saliency-based explainability:
42
-
43
- ```bash
44
- python train.py --env CartPole-v1 --constraint pole_angle --explain shap
45
- ```
46
-
47
- 🔹 This:
48
-
49
- - Adds a pole-angle constraint wrapper to the Gym env
50
-
51
- - Logs violations
52
-
53
- - Displays SHAP or saliency explanations for agent decisions
54
-
55
- ## 🧠 Features
56
- #### ✅ Constrained RL
57
- - Add custom constraints via wrapper or logic class
58
-
59
- - Violation logging and reward shaping
60
-
61
- - Safe vs unsafe episode tracking
62
-
63
- #### 🔍 Explainability
64
- - SaliencyExplainer — gradient-based visual heatmaps
65
-
66
- - SHAPExplainer — feature contribution values per decision
67
-
68
- - Compatible with any PyTorch-based agent
69
-
70
- #### 📊 Metrics
71
- - Constraint violation rate
72
-
73
- - Episode reward
74
-
75
- - Cumulative safe reward
76
-
77
- - Action entropy & temporal behavior stats
78
-
79
- #### 📚 Modularity
80
- - Swap out agents, constraints, evaluators, or explainers
81
-
82
- - Supports Gym environments
83
-
84
- - Configurable training pipeline
85
-
86
- ## 📜 Citation
87
- Coming soon after arXiv/preprint release.
@@ -1,139 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: saferl-lite
3
- Version: 0.1.0
4
- Summary: A lightweight, explainable, and constrained reinforcement learning toolkit.
5
- Home-page: https://github.com/satyamcser/saferl-lite
6
- Author: Satyam Mishra
7
- Author-email: satyam@example.com
8
- Project-URL: Documentation, https://satyamcser.github.io/saferl-lite/
9
- Project-URL: Source, https://github.com/satyamcser/saferl-lite
10
- Project-URL: Bug Tracker, https://github.com/satyamcser/saferl-lite/issues
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: OS Independent
14
- Classifier: Intended Audience :: Science/Research
15
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
- Requires-Python: >=3.8
17
- Description-Content-Type: text/markdown
18
- License-File: LICENSE
19
- Requires-Dist: gym
20
- Requires-Dist: gymnasium
21
- Requires-Dist: numpy
22
- Requires-Dist: torch
23
- Requires-Dist: matplotlib
24
- Requires-Dist: seaborn
25
- Requires-Dist: pre-commit
26
- Requires-Dist: flake8
27
- Requires-Dist: pyyaml
28
- Requires-Dist: shap
29
- Requires-Dist: captum
30
- Requires-Dist: typer
31
- Requires-Dist: scikit-learn
32
- Requires-Dist: pandas
33
- Requires-Dist: pytest
34
- Requires-Dist: pytest-cov
35
- Requires-Dist: coverage
36
- Requires-Dist: mkdocs
37
- Requires-Dist: wandb
38
- Requires-Dist: mkdocs>=1.5
39
- Requires-Dist: mkdocs-material>=9.5
40
- Requires-Dist: mkdocstrings[python]
41
- Dynamic: author
42
- Dynamic: author-email
43
- Dynamic: classifier
44
- Dynamic: description
45
- Dynamic: description-content-type
46
- Dynamic: home-page
47
- Dynamic: license-file
48
- Dynamic: project-url
49
- Dynamic: requires-dist
50
- Dynamic: requires-python
51
- Dynamic: summary
52
-
53
- # 🔐 SafeRL-Lite
54
-
55
- A **lightweight, explainable, and modular** Python library for **Constrained Reinforcement Learning (Safe RL)** with real-time **SHAP & saliency-based explainability**, custom metrics, and Gym-compatible wrappers.
56
-
57
- <p align="center">
58
- <img src="https://img.shields.io/github/license/satyamcser/saferl-lite?style=flat-square">
59
- <img src="https://img.shields.io/github/stars/satyamcser/saferl-lite?style=flat-square">
60
- <img src="https://img.shields.io/pypi/v/saferl-lite?style=flat-square">
61
- <img src="https://img.shields.io/github/actions/workflow/status/satyamcser/saferl-lite/ci.yml?branch=main&style=flat-square">
62
- </p>
63
-
64
- ---
65
-
66
- ## 🌟 Overview
67
-
68
- **SafeRL-Lite** empowers reinforcement learning agents to act under **safety constraints**, while remaining **interpretable** and **modular** for fast experimentation. It wraps standard Gym environments and DQN-based agents with:
69
-
70
- - ✅ Safety constraint logic
71
- - 🔍 Visual explainability (SHAP, saliency maps)
72
- - 📊 Violation and reward tracking
73
- - 🧪 Built-in testing and evaluations
74
-
75
- ---
76
-
77
- ## 🔧 Installation
78
-
79
- > 📦 PyPI (coming soon)
80
- ```bash
81
- pip install saferl-lite
82
- ```
83
-
84
- ## 🛠️ From source:
85
-
86
- ```bash
87
- git clone https://github.com/satyamcser/saferl-lite.git
88
- cd saferl-lite
89
- pip install -e .
90
- ```
91
-
92
- ## 🚀 Quickstart
93
- Train a constrained DQN agent with saliency-based explainability:
94
-
95
- ```bash
96
- python train.py --env CartPole-v1 --constraint pole_angle --explain shap
97
- ```
98
-
99
- 🔹 This:
100
-
101
- - Adds a pole-angle constraint wrapper to the Gym env
102
-
103
- - Logs violations
104
-
105
- - Displays SHAP or saliency explanations for agent decisions
106
-
107
- ## 🧠 Features
108
- #### ✅ Constrained RL
109
- - Add custom constraints via wrapper or logic class
110
-
111
- - Violation logging and reward shaping
112
-
113
- - Safe vs unsafe episode tracking
114
-
115
- #### 🔍 Explainability
116
- - SaliencyExplainer — gradient-based visual heatmaps
117
-
118
- - SHAPExplainer — feature contribution values per decision
119
-
120
- - Compatible with any PyTorch-based agent
121
-
122
- #### 📊 Metrics
123
- - Constraint violation rate
124
-
125
- - Episode reward
126
-
127
- - Cumulative safe reward
128
-
129
- - Action entropy & temporal behavior stats
130
-
131
- #### 📚 Modularity
132
- - Swap out agents, constraints, evaluators, or explainers
133
-
134
- - Supports Gym environments
135
-
136
- - Configurable training pipeline
137
-
138
- ## 📜 Citation
139
- Coming soon after arXiv/preprint release.
File without changes
File without changes
File without changes
File without changes