# amuthavanmoorthi/latency-minimization architecture

> Architecture diagram of the GitHub repository amuthavanmoorthi/latency-minimization, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amuthavanmoorthi/latency-minimization
- Repository: https://github.com/amuthavanmoorthi/latency-minimization

## Overview

#### Purpose and Entry Points
This is a research simulation for optimizing a multi-antenna active STAR-RIS wireless system serving URLLC mobile-edge-computing users. It compares baseline policies with a Deep Deterministic Policy Gradient (DDPG) agent and persists trained policies/reward traces.

Primary execution paths are `main.py` for experiment orchestration and `agent/train_ddpg.py` for DDPG training.

#### STAR-RIS URLLC-MEC Environment
`env/star_ris_env.py` is the central environment: it represents system state, accepts continuous control actions, evolves a wireless/MEC decision step, and returns reward/termination signals to the RL loop.

It composes:
- Channel and propagation modeling from `env/channel.py`.
- URLLC latency/reliability calculations from `env/urllc_latency.py`.
- Environment package boundary in `env/__init__.py`.

This is the main boundary between optimization agents and domain-specific communications modeling.

#### Wireless Channel and Latency Model
`env/channel.py` models the channel quantities needed to evaluate multi-antenna STAR-RIS actions. `env/urllc_latency.py` translates communication and computation outcomes into URLLC latency-related performance, which is likely a core part of the environment reward and constraint handling.

The conceptual system design and equations are documented alongside implementation in `paper/main.tex`, `paper/system_model.drawio`, and `paper/Multi-antenna active STAR-RIS URLLC-MEC system.drawio`.

#### RL Agent and Training Control Flow
`agent/ddpg_rl.py` implements the DDPG learning system, including the continuous-action policy and value-learning path. `agent/train_ddpg.py` drives repeated environment interaction:

1. Obtain an observation from the STAR-RIS environment.
2. Select a continuous RIS/resource-control action through the DDPG policy.
3. Step the environment and receive reward/next state.
4. Store experience and update actor/critic networks.
5. Save learned model artifacts and reward histories.

`agent/__init__.py` provides the agent package boundary.

#### Baseline Evaluation
`agent/baselines.py` contains non-RL comparison strategies. These policies use the same environment-facing interface as DDPG, enabling comparable evaluation under shared channel, latency, and reward calculations.

This establishes a clean experimental boundary: domain simulation in `env/`, optimization approaches in `agent/`, and orchestration in `main.py`.

#### Model and Result Artifacts
Pretrained policies are stored under `results/`, including DDPG policy artifacts for different STAR-RIS element/user configurations:
- `results/ddpg_model_N32_K2/policy.pt`
- `results/ddpg_model_N32_K4/policy.pt`
- `results/ddpg_rl_N32_K4/actor.pt`

Reward traces such as `results/training_rewards_N32_K4.npy` and `results/ddpg_rl_rewards_N32_K4.npy` support training comparison. `results/plot_results.py` is the reporting/visualization entry point for persisted NumPy outputs.

#### Runtime and External Dependencies
The repository is Python-based, with PyTorch serialized checkpoints (`.pt`) and NumPy result arrays (`.npy`), implying PyTorch and NumPy as material runtime dependencies. No deployment infrastructure, network service, database, or external API integration is represented in the repository tree; experiments execute as local simulation/training workloads.

Main entry points: [`agent/train_ddpg.py`](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/agent/train_ddpg.py) (DDPG training loop), [`env/star_ris_env.py`](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/env/star_ris_env.py) (Environment package), [`main.py`](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/main.py) (Experiment runner), [`paper/main.tex`](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/paper/main.tex) (System model paper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Experiment Control"]
  node_main["Experiment runner<br/>Python entry point<br/>[main.py]"]
end

subgraph group_environment["STAR-RIS Simulation"]
  node_environment_boundary["Environment package<br/>simulation boundary<br/>[star_ris_env.py]"]
  node_channel["Channel model<br/>wireless propagation<br/>[channel.py]"]
  node_urllc_latency["URLLC latency model<br/>performance model<br/>[urllc_latency.py]"]
end

subgraph group_optimization["Optimization Methods"]
  node_train_ddpg["DDPG training loop<br/>training controller<br/>[train_ddpg.py]"]
  node_ddpg["DDPG learner<br/>RL agent<br/>[ddpg_rl.py]"]
  node_baselines["Baseline policies<br/>comparison strategies<br/>[baselines.py]"]
end

subgraph group_artifacts["Models &amp; Results"]
  node_policy_n32_k2["N32/K2 policy<br/>PyTorch checkpoint<br/>[policy.pt]"]
  node_policy_n32_k4["N32/K4 policy<br/>PyTorch checkpoint<br/>[policy.pt]"]
  node_actor_n32_k4["N32/K4 actor<br/>PyTorch checkpoint<br/>[actor.pt]"]
  node_reward_traces["Reward traces<br/>NumPy arrays"]
  node_plot_results["Results plotting<br/>reporting script<br/>[plot_results.py]"]
end

subgraph group_documentation["System Design"]
  node_paper["System model paper<br/>research documentation<br/>[main.tex]"]
  node_system_diagram["System diagrams<br/>design diagrams"]
end

node_main -->|"runs training"| node_train_ddpg
node_main -->|"evaluates"| node_baselines
node_train_ddpg -->|"selects and updates"| node_ddpg
node_train_ddpg -->|"reset / step"| node_environment_boundary
node_baselines -->|"shared action interface"| node_environment_boundary
node_ddpg -->|"continuous actions"| node_environment_boundary
node_environment_boundary -->|"propagation evaluation"| node_channel
node_environment_boundary -->|"reward and constraints"| node_urllc_latency
node_train_ddpg -.->|"saves / loads"| node_policy_n32_k2
node_train_ddpg -.->|"saves / loads"| node_policy_n32_k4
node_train_ddpg -.->|"saves / loads"| node_actor_n32_k4
node_train_ddpg -.->|"writes rewards"| node_reward_traces
node_plot_results -->|"reads"| node_reward_traces
node_paper -.->|"documents design"| node_system_diagram
node_paper -.->|"specifies model"| node_environment_boundary

click node_main "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/main.py"
click node_train_ddpg "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/agent/train_ddpg.py"
click node_ddpg "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/agent/ddpg_rl.py"
click node_baselines "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/agent/baselines.py"
click node_environment_boundary "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/env/star_ris_env.py"
click node_channel "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/env/channel.py"
click node_urllc_latency "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/env/urllc_latency.py"
click node_policy_n32_k2 "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/results/ddpg_model_N32_K2/policy.pt"
click node_policy_n32_k4 "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/results/ddpg_model_N32_K4/policy.pt"
click node_actor_n32_k4 "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/results/ddpg_rl_N32_K4/actor.pt"
click node_reward_traces "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/results/training_rewards_N32_K4.npy"
click node_plot_results "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/results/plot_results.py"
click node_paper "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/paper/main.tex"
click node_system_diagram "https://github.com/amuthavanmoorthi/latency-minimization/blob/main/paper/system_model.drawio"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main toneBlue
class node_environment_boundary,node_channel,node_urllc_latency toneAmber
class node_train_ddpg,node_ddpg,node_baselines toneMint
class node_policy_n32_k2,node_policy_n32_k4,node_actor_n32_k4,node_reward_traces,node_plot_results toneRose
class node_paper,node_system_diagram toneIndigo
```

## Components

### Experiment Control

- [Experiment runner](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/main.py): Python entry point · Orchestrates simulation experiments and policy comparisons. · `main.py`

### STAR-RIS Simulation

- [Environment package](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/env/star_ris_env.py): simulation boundary · Maps actions to next state, reward, and termination signals. · `env/star_ris_env.py`
- [Channel model](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/env/channel.py): wireless propagation · Computes multi-antenna STAR-RIS channel quantities. · `env/channel.py`
- [URLLC latency model](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/env/urllc_latency.py): performance model · Evaluates communication and computation latency/reliability. · `env/urllc_latency.py`

### Optimization Methods

- [DDPG training loop](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/agent/train_ddpg.py): training controller · Runs environment interaction, replay updates, and persistence. · `agent/train_ddpg.py`
- [DDPG learner](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/agent/ddpg_rl.py): RL agent · Continuous-action actor-critic policy and value learning. · `agent/ddpg_rl.py`
- [Baseline policies](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/agent/baselines.py): comparison strategies · Non-RL policies evaluated through the shared environment interface. · `agent/baselines.py`

### Models & Results

- [N32/K2 policy](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/results/ddpg_model_N32_K2/policy.pt): PyTorch checkpoint · `results/ddpg_model_N32_K2/policy.pt`
- [N32/K4 policy](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/results/ddpg_model_N32_K4/policy.pt): PyTorch checkpoint · `results/ddpg_model_N32_K4/policy.pt`
- [N32/K4 actor](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/results/ddpg_rl_N32_K4/actor.pt): PyTorch checkpoint · `results/ddpg_rl_N32_K4/actor.pt`
- [Reward traces](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/results/training_rewards_N32_K4.npy): NumPy arrays · Persisted training reward histories for comparisons. · `results/training_rewards_N32_K4.npy`
- [Results plotting](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/results/plot_results.py): reporting script · Visualizes persisted experiment outputs. · `results/plot_results.py`

### System Design

- [System model paper](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/paper/main.tex): research documentation · Documents system design and equations. · `paper/main.tex`
- [System diagrams](https://github.com/amuthavanmoorthi/latency-minimization/blob/main/paper/system_model.drawio): design diagrams · STAR-RIS URLLC-MEC conceptual diagrams. · `paper/system_model.drawio`

## Connections

- Experiment runner → DDPG training loop: runs training
- Experiment runner → Baseline policies: evaluates
- DDPG training loop → DDPG learner: selects and updates
- DDPG training loop → Environment package: reset / step
- Baseline policies → Environment package: shared action interface
- DDPG learner → Environment package: continuous actions
- Environment package → Channel model: propagation evaluation
- Environment package → URLLC latency model: reward and constraints
- DDPG training loop → N32/K2 policy: saves / loads
- DDPG training loop → N32/K4 policy: saves / loads
- DDPG training loop → N32/K4 actor: saves / loads
- DDPG training loop → Reward traces: writes rewards
- Results plotting → Reward traces: reads
- System model paper → System diagrams: documents design
- System model paper → Environment package: specifies model
