PyTorch library for deep RL with Global State Prediction (GSP) for decentralized multi-agent swarm robotics. Implements DQN, DDQN, DDPG, TD3, RDDPG with three GSP variants: DDPG-GSP, RDDPG-GSP, and A-GSP (attention-based).
- Entry point:
gsp_rl/src/actors/actor.py-- theActorclass is the main public API - Inheritance:
Actor->NetworkAids->Hyperparameters(all inactors/) - Config: All hyperparameters flow through a YAML config dict passed to
Actor.__init__()->Hyperparameters.__init__() - Network storage:
self.networksandself.gsp_networksare plain dicts (not classes), keyed by strings like'actor','critic','q_eval','replay','learning_scheme','learn_step_counter' - GSP augmentation: When GSP is enabled,
network_input_size = input_size + gsp_output_size. The GSP prediction is concatenated with the observation before feeding the main action network.
Load only the docs relevant to your current task:
| Task | Load these files |
|---|---|
| Understand overall architecture | docs/architecture.md |
| Refactor inheritance or add algorithm family | docs/architecture.md + docs/class-graph.md |
| Add/modify a neural network | docs/modules/networks.md + docs/data-flow.md |
| Add/modify a replay buffer | docs/modules/buffers.md |
| Debug learning logic or loss computation | docs/modules/actors.md + docs/algorithms.md |
| Modify hyperparameters or config | docs/configuration.md |
| Work on GSP prediction pipeline | docs/algorithms.md + docs/class-graph.md |
| Debug tensor shape mismatches | docs/data-flow.md |
gsp_rl/src/
actors/
actor.py # Actor class -- main agent, builds networks + buffers
learning_aids.py # NetworkAids (factory + learn methods) + Hyperparameters
networks/
dqn.py # DQN (discrete, nn.Module)
ddqn.py # DDQN (discrete, nn.Module)
ddpg.py # DDPGActorNetwork + DDPGCriticNetwork + fanin_init
td3.py # TD3ActorNetwork + TD3CriticNetwork
rddpg.py # RDDPGActorNetwork + RDDPGCriticNetwork (compose EE + DDPG)
lstm.py # EnvironmentEncoder (LSTM-based)
self_attention.py # SelfAttention, TransformerBlock, AttentionEncoder
buffers/
replay.py # ReplayBuffer (standard SARSD, circular)
sequential.py # SequenceReplayBuffer (two-stage: seq staging -> main)
attention_sequential.py # AttentionSequenceReplayBuffer (obs + label)
utility/
zmq_utility.py # ZMQ binary message parsing for CoppeliaSim robotics
examples/baselines/ # CartPole, LunarLander, Pendulum training scripts
tests/ # Shape validation tests for all network types
- Networks stored in plain dicts, not wrapper classes. Dict schema varies by algorithm (see
docs/class-graph.md). - All
nn.Modulesubclasses self-assign device (cuda:0orcpu) in their constructors. - Replay buffers use circular indexing:
mem_ctr % mem_size. - The
intentionparameter onsave_checkpoint/load_checkpointrefers to the GSP network (historical naming from "intention prediction"). fanin_initinddpg.pyis used for weight initialization in DDPG networks only. TD3 uses default PyTorch init.- All optimizers are Adam with
weight_decay=1e-4. - Tests validate network input/output tensor shapes, not learning convergence.
- Examples subclass or directly instantiate
Actor, notNetworkAids.
- GSP always builds (
actor.py:89):if gsp is not Noneis always True sincegspdefaults toFalse(andFalse is not None). This meansbuild_gsp_network('DDPG')is always called. - RDDPG dead code (
actor.py:159):self.build_RDDPG()is called with 0 args but the method signature (actor.py:200) requires 3 positional args. This code path will raise TypeError if reached. load_stat_dicttypo: Severalload_checkpointmethods in the CPU branch callself.load_stat_dict()(missing 'e') instead ofself.load_state_dict(). Affects:dqn.py:67,ddqn.py:66,ddpg.py:162,td3.py:69,lstm.py:73,self_attention.py:171.- TD3 vs DDPG cat dim:
TD3CriticNetwork.forwardusesdim=1for state-action concatenation whileDDPGCriticNetwork.forwardusesdim=-1. Functionally equivalent for 2D tensors but inconsistent. - RDDPG shared encoder: In
make_RDDPG_networks(learning_aids.py:74-82), actor and critic share oneEnvironmentEncoderinstance, but target networks get separate instances. This is intentional for gradient flow isolation. - Module-level
Loss:learning_aids.py:20definesLoss = nn.MSELoss()as a module-level singleton shared across all learn methods.