02 / Energy systems / RL / EVM Team project / 2025

Closed-loop microgrid systems prototype

Gridium Protocol

Four runtimes connect a simulated neighborhood to a continuous-control agent, realtime command center, constant-product energy market, and proof-gated settlement experiment.

15Simulated prosumer nodes
7DController observation
1DContinuous fee action
500 msGateway polling loop
The engineering thesis

Treat energy coordination as a closed-loop systems problem, not a blockchain dashboard.

Gridium explores how physical state, market incentives, and privacy-preserving settlement could share one architecture. A Python environment simulates generation, demand, storage, and AMM reserves. A DDPG actor adjusts swap fees continuously. A gateway broadcasts state to a 3D operator interface while Solidity and Circom model the settlement boundary.

This is a systems prototype, not a grid-control product. Its technical value is the integration contract between simulation, control, realtime UX, and on-chain logic.

My contributionPython AI engine, backend integration, and 3D visualization

I implemented the FastAPI simulation loop, PyTorch DDPG actor-critic path, Node gateway integration, and React Three Fiber grid view. Yash Pandit led contracts and zero-knowledge work; Sanket Deka worked on frontend and UI/UX.

Runtime topology

A four-runtime control loop

Each runtime has a narrow contract. That keeps high-frequency simulation, browser rendering, proof generation, and EVM state from becoming one fragile process.

PY
AI engine
FastAPI, Gym environment, PyTorch DDPG
→
WS
Gateway
Node.js, REST polling, Socket.io fan-out
→
3D
Command center
React, Zustand, React Three Fiber
→
EVM
Settlement
Solidity AMM, access roles, Groth16 verifier
Simulation

15-node microgrid

Solar yield, duck-curve demand, battery state, reserves, and injected disturbances produce the controller state.

Control

DDPG actor-critic

A seven-value observation maps to one bounded swap-fee action. Replay memory and soft target updates support continuous learning.

Market

Constant-product AMM

Energy and stable reserves follow the x × y = k invariant with fee accrual, slippage guards, and non-reentrant swaps.

Privacy experiment

Groth16 surplus proof

The circuit exposes claimed surplus while keeping solar and load inputs private, then gates a contract path through a verifier.

Controller design

Why the RL problem is continuous

Observation[load, generation, imbalance, energy reserve, stable reserve, price, aggregate SoC]
Actionswap fee in [0.10%, 5.00%]
Rewardbalance - energy waste - price volatility
01

Observe the physical and market state together

The environment does not optimize price in isolation. Load, generation, imbalance, reserves, price, and battery state form a seven-dimensional observation.

02

Produce a bounded fee, not a discrete mode

The actor emits one normalized action and maps it into the permitted fee range. Continuous control avoids forcing the market into a handful of abrupt fee buckets.

actor(state) → sigmoid action → 0.001 + action × 0.049
03

Learn through an actor and a critic

The critic estimates the value of a state-action pair. Replay memory breaks temporal correlation, Ornstein-Uhlenbeck noise supports exploration, and Polyak updates stabilize the target networks.

04

Broadcast the resulting state

The Node gateway polls /tick every 500 ms and fans the state out through Socket.io. Zustand updates the UI while React Three Fiber renders energy flow and node behavior.

Product surfaces

One model, two operator views

Settlement boundary

What the contract and circuit actually enforce

AMM

Reserve integrity

Bidirectional energy/stable swaps update reserves under a constant-product rule. Minimum-output parameters protect users from unacceptable slippage and nonReentrant guards transfer paths.

Controller hook

Role-bounded fee updates

Only the RL_OPERATOR_ROLE can update the swap fee, and the contract clamps it between 10 and 500 basis points.

Proof path

Private arithmetic relation

The Circom circuit proves amount_to_sell = total_solar - total_load without publishing the two private inputs. The AMM can call a Groth16 verifier before proof-gated liquidity.

Important boundary

The current circuit proves an arithmetic relationship; it does not prove sensor authenticity, location, meter ownership, or that the private inputs came from trusted hardware. Those require oracle and attestation design beyond this prototype.

Implementation map

Where the advanced pieces live

SubsystemSourceResponsibilityTechnical detail
Physics environmentai-engine/aegis_env.pyState, disturbances, reward, action boundsGym-compatible seven-dimensional observation
DDPG agentai-engine/ddpg_agent.pyActor, critic, replay, targetsContinuous one-dimensional action with OU exploration
Realtime engineai-engine/main.pyTick loop and chaos endpointsFastAPI state service and WebSocket endpoint
Gatewaybackend/index.jsREST polling, Socket.io, proof endpoint500 ms fan-out with mock/event fallback paths
Market contractAegisAMM.solLiquidity, swaps, fee controlAccessControl, ReentrancyGuard, slippage checks
Proof circuitenergy_proof.circomSurplus relationTwo private signals and one public output
3D interfaceMicrogridCanvas.tsxNode topology and energy flowReact Three Fiber driven by Zustand state
Engineering judgment

Integrated prototype, explicit simulation boundary

Implemented

A working multi-runtime systems prototype

  • Closed-loop Python simulation and continuous controller
  • Realtime gateway and 3D operator interface
  • Constant-product Solidity market with control roles
  • Groth16 proof-generation and verification path
  • Chaos controls and mock-mode fallback for demonstration
Prototype boundary

Not yet a validated energy-control protocol

  • No comparison against rule-based or model-predictive control baselines
  • Some event-feed entries are generated for the demonstration UI
  • The circuit lacks trusted-meter attestation and stronger range constraints
  • Contract, controller, and adversarial tests need a frozen evaluation suite
Next engineering milestone

Freeze deterministic scenarios, compare DDPG against PID and rule-based controllers, add contract invariants and circuit tests, then measure imbalance, volatility, proof latency, and recovery under the same disturbances.