This is the official implementation of AdapSafe2: Prior-Free Safe-Certified Reinforcement Learning for Multi-Area Frequency Control (https://ieeexplore.ieee.org/document/10726595).
This repository contains the core algorithm and multi-area frequency-control environments used for AdapSafe2.
main.py: main training entry point.algs/MQL/: MQL / TD3-style meta-RL algorithm, buffers, parameter learning, and task snapshots.safe/: control barrier function (CBF) and safe critic utilities.maml/: MAML inverse dynamics model. Small default MAML checkpoints for two-area and N-area training are kept inmaml/params_dir/.rlkit/envs/: two-area and N-area frequency-control environments plus normalization wrappers.models/: neural network modules.misc/: logging, runners, PyTorch utilities, and JSON/CSV helpers.configs/: environment/task configuration JSON files.
Python 3 is expected. The original codebase uses legacy Gym APIs, so a Python 3.7-3.9 environment is the safest starting point.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtExample commands from the original experiment setup:
# AdapSafe2: safe critic + CBF + MAML inverse model
python main.py --enable_safe_critic --enable_cbf --enable_fake_transition --inverse_model MAML --env_name n_area_freq
# AdapSafe: CBF + DNN inverse model
python main.py --enable_cbf --inverse_model DNN --enable_fake_transition --env_name n_area_freq
# MQL baseline
python main.py --expl_noise 0.2 --env_name n_area_freq --lr 0.00005By default, training writes checkpoints to ck/ and logs to log_dir/. These paths are intentionally ignored by git.