Package: omnisafe
Documentation|Implemented Algorithms|Installation|Getting Started|LicenseThis library is currently under heavy development - if you have suggestions on the API or use-cases you'd like to be covered, please open a GitHub issue or reach out. We'd love to hear about how you're using the library.OmniSafe is an infrastructural framework designed to accelerate safe reinforcement learning (RL) research by providing a comprehensive and reliable benchmark for safe RL algorithms.
The field of RL has great potential to benefit the society, and safety concerns are a significant issue, and RL algorithms have raised concerns about unintended harm or unsafe behavior.
Safe RL intends to develop algorithms that minimize the risk of unintended harm or unsafe behavior, but there is currently a lack of commonly recognized safe RL algorithm benchmarks.OmniSafe addresses these issues by providing more than 40 experimentally validated algorithms and a sound and efficient simulation environment.
Researchers can use OmniSafe to conduct experiments and verify their ideas, ensuring consistency and enabling more efficient development of safe RL algorithms.
By using OmniSafe as a benchmark, researchers can evaluate the performance of their own safe RL algorithms and contribute to the advancement of safe RL research.Table of ContentsImplemented AlgorithmsLatest SafeRL PapersList of AlgorithmsOn-Policy SafeOff-Policy SafeModel-Based SafeOffline SafeOthersInstallationPrerequisitesInstall from sourceInstall from PyPIExamplesTry with CLIGetting StartedImportant HintsQuickstart: Colab on the CloudChangelogThe OmniSafe TeamLicenseImplemented AlgorithmsThe supported interface algorithms currently include:Latest SafeRL Papers[AAAI 2023]Augmented Proximal Policy Optimization for Safe Reinforcement Learning (APPO)[NeurIPS 2022]Constrained Update Projection Approach to Safe Policy Optimization (CUP)[NeurIPS 2022]Effects of Safety State Augmentation on Safe Exploration (Simmer)[NeurIPS 2022]Model-based Safe Deep Reinforcement Learning via a Constrained Proximal Policy Optimization Algorithm[ICML 2022]Sauté RL: Almost Surely Safe Reinforcement Learning Using State Augmentation (SauteRL)[ICML 2022]Constrained Variational Policy Optimization for Safe Reinforcement Learning (CVPO)[IJCAI 2022]Penalized Proximal Policy Optimization for Safe Reinforcement Learning[ICLR 2022]Constrained Policy Optimization via Bayesian World Models (LA-MBDA)[AAAI 2022]Conservative and Adaptive Penalty for Model-Based Safe Reinforcement Learning (CAP)List of AlgorithmsOn-Policy SafeThe Lagrange version of PPO (PPO-Lag)The Lagrange version of TRPO (TRPO-Lag)[ICML 2017]Constrained Policy Optimization (CPO)[ICLR 2019]Reward Constrained Policy Optimization (RCPO)[ICML 2020]Responsive Safety in Reinforcement Learning by PID Lagrangian Methods (PID-Lag)[NeurIPS 2020]First Order Constrained Optimization in Policy Space (FOCOPS)[AAAI 2020]IPO: Interior-point Policy Optimization under Constraints (IPO)[ICLR 2020]Projection-Based Constrained Policy Optimization (PCPO)[ICML 2021]CRPO: A New Approach for Safe Reinforcement Learning with Convergence Guarantee[IJCAI 2022]Penalized Proximal Policy Optimization for Safe Reinforcement Learning(P3O)Off-Policy SafeThe Lagrange version of TD3 (TD3-Lag)The Lagrange version of DDPG (DDPG-Lag)The Lagrange version of SAC (SAC-Lag)[ICML 2019]Lyapunov-based Safe Policy Optimization for Continuous Control (SDDPG)[ICML 2019]Lyapunov-based Safe Policy Optimization for Continuous Control (SDDPG-modular)[ICML 2022]Constrained Variational Policy Optimization for Safe Reinforcement Learning (CVPO)Model-Based Safe[NeurIPS 2021]Safe Reinforcement Learning by Imagining the Near Future (SMBPO)[CoRL 2021 (Oral)]Learning Off-Policy with Online Planning (SafeLOOP)[AAAI 2022]Conservative and Adaptive Penalty for Model-Based Safe Reinforcement Learning (CAP)[NeurIPS 2022]Model-based Safe Deep Reinforcement Learning via a Constrained Proximal Policy Optimization Algorithm[ICLR 2022]Constrained Policy Optimization via Bayesian World Models (LA-MBDA)[ICML 2022 Workshop]Constrained Model-based Reinforcement Learning with Robust Cross-Entropy Method (RCE)[NeurIPS 2018]Constrained Cross-Entropy Method for Safe Reinforcement Learning (CCE)Offline SafeThe Lagrange version of BCQ (BCQ-Lag)The Constrained version of CRR (C-CRR)[AAAI 2022]Constraints Penalized Q-learning for Safe Offline Reinforcement Learning CPQ[ICLR 2022 (Spotlight)]COptiDICE: Offline Constrained Reinforcement Learning via Stationary Distribution Correction Estimation[ICML 2022]Constrained Offline Policy Optimization (COPO)OthersSafe Exploration in Continuous Action Spaces (Safety Layer)[RA-L 2021]Recovery RL: Safe Reinforcement Learning with Learned Recovery Zones[ICML 2022]Sauté RL: Almost Surely Safe Reinforcement Learning Using State Augmentation (SauteRL)[NeurIPS 2022]Effects of Safety State Augmentation on Safe ExplorationInstallationPrerequisitesOmniSafe requires Python 3.8+ and PyTorch 1.10+.We support and test for Python 3.8, 3.9, 3.10 on Linux. Meanwhile, we also support M1 and M2 versions of macOS. We will accept PRs related to Windows, but do not officially support it.Install from source# Clone the repogitclonehttps://github.com/OmniSafeAI/omnisafecdomnisafe# Create a conda environmentcondaenvcreate--fileconda-recipe.yaml
condaactivateomnisafe# Install omnisafepipinstall-e.Install from PyPIOmniSafe is hosted in/.pipinstallomnisafeExamplescdexamples
pythontrain_policy.py--algoPPOLag--env-idSafetyPointGoal1-v0--parallel1--total-steps1024000--devicecpu--vector-env-nums1--torch-threads1algo:TypeNameBase-On-PolicyPolicyGradient, PPONaturalPG, TRPOBase-Off-PolicyDDPG, TD3, SACNaive LagrangeRCPO, PPOLag, TRPOLagDDPGLag, TD3Lag, SACLagPID LagrangeCPPOPid, TRPOPidFirst OrderFOCOPS, CUPSecond OrderSDDPG, CPO, PCPOSaute RLPPOSaute, PPOLagSauteSimmer RLPPOSimmerQ, PPOSimmerPidPPOLagSimmerQ, PPOLagSimmerPidEarlyTerminatedPPOEarlyTerminatedPPOLagEarlyTerminatedModel-BasedCAP, MBPPOLag, SafeLOOPenv-id:Environment id inSafety Gymnasium, here a list of envs that safety-gymnasium supports.CategoryTaskAgentExampleSafe NavigationGoal[012]Point, Car, Racecar, AntSafetyPointGoal1-v0Button[012]Push[012]Circle[012]Safe VelocityVelocityHalfCheetah, Hopper, Swimmer, Walker2d, Ant, HumanoidSafetyHumanoidVelocity-v1More information about environments, please refer toSafety Gymnasiumparallel:Number of parallelsTry with CLIA video examplepipinstallomnisafe

omnisafe--help# Ask for helpomnisafebenchmark--help# The benchmark also can be replaced with 'eval', 'train', 'train-config'# Quick benchmarking for your research, just specify: 1.exp_name, 2.num_pool(how much processes are concurrent), 3.path of the config file(refer to omnisafe/examples/benchmarks for format)omnisafebenchmarktest_benchmark2./saved_source/benchmark_config.yaml# Quick evaluating and rendering your trained policy, just specify: 1.path of algorithm which you trainedomnisafeeval./saved_source/PPO-{SafetyPointGoal1-v0}--num-episode1# Quick training some algorithms to validate your thoughts# Note: use `key1:key2`, your can select key of hyperparameters which are recursively contained, and use `--custom-cfgs`, you can add custom cfgs via CLIomnisafetrain--algoPPO--total-steps2048--vector-env-nums1--custom-cfgsalgo_cfgs:steps_per_epoch--custom-cfgs1024# Quick training some algorithms via a saved config file, the format is as same as default formatomnisafetrain-config./saved_source/train_config.yamlGetting StartedImportant Hintstrain_cfgs:torch_threadsis especially important for training speed, and is varying with users' machine, this value shouldn't be too small or too large.Quickstart: Colab on the CloudExplore OmniSafe easily and quickly through a series of colab notebooks:Getting StartedIntroduce the basic usage of OmniSafe so that users can quickly hand on it.CLI CommandIntroduce how to use the CLI tool of OmniSafe.We take great pleasure in collaborating with our users to create tutorials in various languages.
Please refer to our list of currently supported languages.
If you are interested in translating the tutorial into a new language or improving an existing version, kindly submit a PR to us.ChangelogSeeCHANGELOG.md.The OmniSafe TeamOmniSafe is mainly developed by the SafeRL research team directed by Prof.Yaodong Yang.
Our SafeRL research team members includeBorong Zhang,Jiayi Zhou,JTao Dai,Weidong Huang,Ruiyang Sun,Xuehai PanandJiaming Ji.
If you have any questions in the process of using omnisafe, don't hesitate to ask your questions onthe GitHub issue page, we will reply to you in 2-3 working days.LicenseOmniSafe is released under Apache License 2.0.