RL4Sys is a distributed reinforcement learning framework designed for system control applications. It provides a server-client architecture that enables multiple clients to train and share models in a distributed manner.

RL4Sys-Dev/
βββ rl4sys/ # Main Python package
β βββ algorithms/ # RL algorithm implementations
β β βββ PPO/ # Proximal Policy Optimization
β β β βββ PPO.py # PPO algorithm implementation
β β β βββ kernel.py # PPO training kernel
β β β βββ replay_buffer.py
β β βββ DQN/ # Deep Q-Network
β β βββ DQN.py # DQN algorithm implementation
β β βββ kernel.py # DQN training kernel
β β βββ replay_buffer.py
β βββ client/ # Python client-side components
β β βββ agent.py # RL agent implementation
β β βββ config_loader.py # Configuration loader for client
β β βββ readme.md # Client documentation
β βββ cppclient/ # High-performance C++ client
β β βββ include/ # C++ header files
β β βββ src/ # C++ source files
β β βββ examples/ # C++ examples (Lunar Lander)
β β βββ test/ # C++ unit tests
β β βββ generated_proto/ # Generated gRPC stubs
β β βββ CMakeLists.txt # CMake build configuration
β β βββ README.md # C++ client documentation
β βββ common/ # Shared utilities and components
β β βββ action.py # Definition of RL4SysAction
β β βββ trajectory.py # Definition of RL4SysTrajectory
β βββ examples/ # Example applications
β β βββ lunar/ # Lunar Lander example
β β β βββ lunar_lander.py
β β β βββ lunar_lander_dqn.py
β β β βββ luna_conf.json
β β βββ job_schedual_old/ # Job scheduling examples
β β β βββ HPCSim/ # HPC simulation environment
β β βββ test_python/ # Python client tests
β β βββ test_cpp/ # C++ client tests
β βββ logs/ # Logging directory
β βββ proto/ # Protocol buffer definitions
β β βββ rl4sys.proto # gRPC proto definition
β β βββ generate_proto.sh # Script to generate gRPC stubs
β βββ server/ # Server-side components
β β βββ server.py # Main server implementation
β β βββ model_diff_manager.py # Model versioning and diff management
β βββ utils/ # Utility functions
β β βββ conf_loader.py # Configuration loading utilities
β β βββ logging_config.py # Logging configuration
β β βββ plot.py # Plotting utilities
β β βββ system_monitor.py # System monitoring utilities
β β βββ util.py # General utilities
β βββ start_server.py # Server startup script
β βββ __init__.py # Package initialization
βββ examples/ # Top-level examples
β βββ job-scheduling/ # Job scheduling examples
β β βββ scheduler.py
β βββ profiling_lunar/ # Performance profiling examples
β βββ baseline_main.py
β βββ rllib/ # RLlib integration examples
β βββ torchrl/ # TorchRL integration examples
βββ grpc_test/ # gRPC testing utilities
β βββ client.cpp
β βββ server.cpp
β βββ helloworld.proto
β βββ CMakeLists.txt
βββ docs/ # Documentation
β βββ <doc pngs>
βββ setup.py # Package setup configuration
βββ config.json # Global configuration
βββ README.md # This file
- Distributed training architecture with server-client model
- Support for multiple RL algorithms (PPO, DQN)
- Efficient model versioning and diff management
- Client-specific training threads
- Protocol buffer-based communication
- Comprehensive logging system
- Example implementations for system control tasks
- Clone the repository:
git clone https://github.com/yourusername/RL4Sys.git
cd RL4Sys- Install dependencies:
pip install -r requirements.txtcd rl4sys
python start_server.py --debugThe Lunar Lander example demonstrates how to use RL4Sys with the Gymnasium Lunar Lander environment:
cd rl4sys/examples/lunar
python lunar_lander.py --debugThe training logs are stored in
cd rl4sys/logs
tensorboard --logdir rl4sys-ppo-infoThe Lunar Lander example uses a configuration file (luna_conf.json) to specify:
- Algorithm parameters
- Network architecture
- Training hyperparameters
- Communication settings
Example configuration:
{
"client_id": "luna-landing",
"algorithm_name": "PPO",
"algorithm_parameters": {
"batch_size": 512,
"act_dim": 4,
"seed": 0,
"traj_per_epoch": 256,
"clip_ratio": 0.2,
"gamma": 0.99,
"lam": 0.95,
"pi_lr": 3e-4,
"vf_lr": 1e-3,
"train_pi_iters": 80,
"train_v_iters": 80,
"target_kl": null,
"input_size": 8
},
"act_limit": 1.0,
"max_traj_length": 1000,
"type": "onpolicy",
"train_server_address": "localhost:50051",
"send_frequency": 10
}The RL4Sys server implements a client-specific training approach:
-
Each client gets its own:
- Algorithm instance
- Training thread
- Model version manager
- Training queue
-
A central dispatcher thread:
- Receives trajectories from all clients
- Routes them to the appropriate client's training queue
-
Client-specific training threads:
- Process trajectories from their dedicated queue
- Update their algorithm's model
- Manage model versioning
The Lunar Lander example shows how to implement a client:
- Initialize the RL4Sys agent:
self.rlagent = RL4SysAgent(conf_path='./luna_conf.json')- Run the training loop:
def run_application(self, num_iterations, max_moves):
for iteration in range(num_iterations):
obs, _ = self.env.reset(seed=self._seed + iteration)
done = False
moves = 0
while not done and moves < max_moves:
# Get action from agent
self.rl4sys_traj, self.rl4sys_action = self.rlagent.request_for_action(
self.rl4sys_traj, obs_tensor
)
# Execute action and get reward
next_obs, reward, terminated, truncated, _ = self.env.step(action)
# Update trajectory
self.rlagent.add_to_trajectory(self.rl4sys_traj, self.rl4sys_action)
self.rl4sys_action.update_reward(reward)The Rl4Sys Python API's are listed as following:
RL4SysAgent(conf_path: str, debug: bool)Creates a lightweight client that opens (or re-uses) a gRPC/TCP connection to the RL4Sys trainer. All behavioural detailsβserver address, authentication token, rollout-buffer size, policy id, etc.βare taken from the JSON/YAML file referenced by conf_path
| name | type | description |
|---|---|---|
conf_path |
str |
Absolute or relative path to a RL4Sys client-side configuration file. |
| 'debug' | 'bool' | Whether to enable debug logging |
request_for_action(
traj: Optional[RL4SysTrajectory],
obs: torch.Tensor | np.ndarray | list[float]
) -> tuple[RL4SysTrajectory, RL4SysAction]Synchronously forwards the latest observation to the remote policy and returns: A trajectory handle β either the one you passed in (updated in-place) or a brand-new RL4SysTrjectory object if you passed None. An RL4SysAction object embedding the chosen action plus bookkeeping fields. Internally the call stores (obs, t_step) in the trajectory so the learner can later compute returns/advantages.
| name | type | description |
|---|---|---|
traj |
RL4SysTrajectory | Existing trajectory handle or None to start a new episode. |
obs |
tensor / array / list | Observation for the current environment state. Must match the dimensionality expected by the model configured in conf_path. |
Tuple (traj, action) where: traj β same type as input, now containing the new step. action β instance of RL4SysAction exposing .act and other helpers.
add_to_trajectory(traj: RL4SysTrajectory,
action: RL4SysAction) -> NoneAdds the action (and any metadata you have updated on it) to RL4SysTrajectory. Call this once per env step, right after request_for_action and before executing the next call.
| name | type | description |
|---|---|---|
traj |
RL4SysTrajectory |
The trajectory obtained from request_for_action. |
action |
RL4SysAction |
The action object you just executed. |
None (in-place side effects only).
mark_end_of_trajectory(
traj: RL4SysTrajectory,
action: RL4SysAction
) -> NoneFlags the terminal step so the learner can finish computing returns and discard server-side state for this episode. Call when the environment terminates/truncates or when you enforce a fixed horizon.
| name | type | description |
|---|---|---|
traj |
RL4SysTrajectory | The running trajectory. |
action |
RL4SysAction | Final step's action object (with reward filled in). |
None
RL4SysAction.update_reward(reward: float) -> NoneAttaches the scalar reward obtained for this step to the action. Invoke once between env.step and the next request_for_action (or before mark_end_of_trajectory on the last step).
| name | type | description |
|---|---|---|
reward |
float | Immediate reward from the environment. |
None
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.