How sk-subroto/pignn-dhn works
Purpose and execution entry points
pignn-dhn is a physics-informed GNN solver for steady-state district-heating hydraulic flows. It predicts pipe mass flows from boundary setpoints without using Newton–Raphson solutions as training labels. Main runnable modules are dhn_gnn/train.py, dhn_gnn/evaluate.py, and dhn_gnn/generate.py; verification entry points are tests/run_gates.py and tests/run_model_smoke.py.
Network and data boundary
The bundled Verbier DHN topology and pipe parameters are CSV inputs under data/network/nodes.csv, data/network/pipes.csv, and data/network/heating_stations.csv. Boundary measurements and weather inputs live in data/measurements/mass_flow.csv and data/weather/outdoor_temp_verbier_2022-01.csv. dhn_gnn/config.py centralizes dataset paths and fixed 50 °C fluid properties. Generated solved datasets are intentionally external/git-ignored.
Graph-operator construction
dhn_gnn/data/network_operators.py converts the PyDHN-backed network topology into graph algebra: node-edge incidence A, cycle matrix B, and masks for independent loops. This is a critical representation boundary: the solver works in cycle-space variables, with pipe flows reconstructed as a feasible base flow plus cycle corrections. Since cycle-space directions satisfy A·Z = 0, mass conservation is preserved structurally rather than imposed as a penalty.
Differentiable hydraulic physics
dhn_gnn/data/physics.py implements differentiable Darcy–Weisbach pressure-loss/resistance behavior and its flow derivative in PyTorch. The governing loop residual is B·φ(Bᵀ·m̃), evaluated from reconstructed edge flows. PyDHN remains a material external dependency for network construction and validation/oracle comparisons, while the optimization-time physics path is Torch-native.
Unrolled hybrid solver
dhn_gnn/model/unrolled_solver.py is the central K-step solver. At each step it recomputes a diagonal Newton-style correction from the known hydraulic derivative, applies damping, and adds a learned bounded correction. dhn_gnn/model/stability.py supplies evaluation-time protections such as velocity caps and Armijo-style acceptance. This separates guaranteed physical structure from the learned residual refinement.
Learned graph refinement
dhn_gnn/model/attention.py implements edge-biased multi-head attention over the pipe graph. Its attention bias is based on the current linearized hydraulic resistance, recomputed each unrolled step. The learned block operates only as a correction to the physics-derived update, not as a standalone flow predictor.
Training and evaluation flow
dhn_gnn/losses.py defines discounted, deep-supervised physics-residual losses across unrolled steps. dhn_gnn/train.py trains self-supervised with truncated backpropagation: state is detached between solver steps to control instability from the quadratic operator. dhn_gnn/evaluate.py runs the solver against generated PyDHN reference outputs, calculates flow metrics, and emits result artifacts. Runtime is Python 3.12 with PyTorch, NumPy/Pandas, Matplotlib, PyDHN, and Meteostat as declared in requirements.txt.
Main entry points: unrolled_solver.py K-step unrolled solver · train.py Training entry point · evaluate.py Evaluation entry point · network_operators.py Cycle-space operators
Components 18
Network & inputs
- Network nodes
data/network/nodes.csv - Pipe parameters
data/network/pipes.csv - Heating stations
data/network/heating_stations.csv - Mass-flow measurements
data/measurements/mass_flow.csv - Outdoor temperature
data/weather/outdoor_temp_verbier_2022-01.csv - Dataset & fluid config · Centralizes paths and fixed 50 °C fluid properties.
dhn_gnn/config.py
Physics representation
- PyDHN · Builds the network and provides validation/oracle comparisons.
- Cycle-space operators · Builds incidence A, cycle matrix B, and independent-loop masks.
dhn_gnn/data/network_operators.py - Differentiable hydraulics · Computes Darcy–Weisbach losses, derivatives, and loop residuals.
dhn_gnn/data/physics.py
Hybrid solver
- Resistance-biased attention · Produces bounded learned corrections from current linearized resistance.
dhn_gnn/model/attention.py - Stability controls · Applies velocity caps and Armijo-style acceptance at evaluation.
dhn_gnn/model/stability.py - K-step unrolled solver · Reconstructs feasible flows, applies Newton-style updates, then learned corrections.
dhn_gnn/model/unrolled_solver.py - Deep-supervised residual loss · Discounts loop-residual loss across solver steps.
dhn_gnn/losses.py
Execution & verification
- Generated reference datasets · Git-ignored PyDHN reference outputs.
- Training entry point · Self-supervised training with truncated backpropagation between steps.
dhn_gnn/train.py - Evaluation entry point · Scores flows against PyDHN references and emits artifacts.
dhn_gnn/evaluate.py - Dataset generation · Generates solved reference datasets.
dhn_gnn/generate.py - Verification gates · Regression gates and model smoke checks.
tests/run_gates.py
Connections 20
- Network nodes → PyDHN: topology
- Pipe parameters → PyDHN: pipe data
- Heating stations → PyDHN: setpoints
- PyDHN → Cycle-space operators: network graph
- Cycle-space operators → K-step unrolled solver: A, B, loop basis · Cycle corrections preserve mass conservation structurally.
- Differentiable hydraulics → K-step unrolled solver: losses & derivatives
- Resistance-biased attention → K-step unrolled solver: learned correction
- Stability controls → K-step unrolled solver: evaluation safeguards
- K-step unrolled solver → Deep-supervised residual loss: per-step residuals
- Dataset & fluid config → Training entry point: paths & fluid properties
- Mass-flow measurements → Training entry point: boundary inputs
- Outdoor temperature → Training entry point: weather inputs
- K-step unrolled solver → Training entry point: unrolled predictions
- Deep-supervised residual loss → Training entry point: self-supervised objective
- PyDHN → Dataset generation: solves reference cases
- Dataset generation → Generated reference datasets: writes
- K-step unrolled solver → Evaluation entry point: predictions
- Generated reference datasets → Evaluation entry point: reference flows
- PyDHN → Evaluation entry point: oracle comparison
- Training entry point → Verification gates: trained model