dRoute Routing Model#
Warning
EXPERIMENTAL - The dRoute integration is in active development and should be used at your own risk. The API may change without notice in future releases.
Overview#
dRoute is a C++ river routing library with Python bindings that enables:
Automatic differentiation for gradient-based calibration
Multiple routing methods (Muskingum-Cunge, IRF, Lag, Diffusive Wave, KWT)
Native Python API for fast in-memory routing (no subprocess overhead)
mizuRoute-compatible network topology format for seamless model switching
Key Features#
Gradient-Based Calibration: Native AD support via CoDiPack or Enzyme enables efficient gradient computation for routing parameters, enabling ~15x faster calibration compared to finite differences.
Multiple Routing Schemes:
muskingum_cunge: Well-tested Muskingum-Cunge method (default)irf: Impulse Response Function routinglag: Simple lag routingdiffusive_wave: Diffusive wave approximationkwt: Kinematic Wave Tracking
mizuRoute Compatibility: Uses the same network topology format as mizuRoute, allowing easy switching between routing models without re-preprocessing.
Installation#
dRoute requires separate installation of the C++ library with Python bindings.
Using SYMFLUENCE Tool Installer#
symfluence tools install droute
This will:
Clone the dRoute repository
Build with CMake (Python bindings + AD enabled)
Install Python package
Manual Installation#
# Clone repository
git clone https://github.com/your-org/droute.git
cd droute
# Build with CMake
mkdir build && cd build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DDROUTE_BUILD_PYTHON=ON \
-DDROUTE_ENABLE_AD=ON \
-DDROUTE_AD_BACKEND=codipack
make -j$(nproc)
make install
# Install Python bindings
pip install .
Verify installation:
python -c "import droute; print(droute.__version__)"
Configuration#
Basic Configuration#
model:
hydrological_model: SUMMA
routing_model: DROUTE
droute:
routing_method: muskingum_cunge
routing_dt: 3600 # seconds
topology_format: netcdf
Configuration Options#
Parameter |
Default |
Description |
|---|---|---|
|
|
Execution mode: |
|
|
Routing scheme: |
|
|
Routing timestep in seconds |
|
|
Enable AD for gradient-based calibration |
|
|
AD backend: |
|
|
Topology file format: |
|
|
Source model for runoff input |
Gradient-Based Calibration#
To enable gradient-based calibration:
model:
routing_model: DROUTE
droute:
enable_gradients: true
ad_backend: codipack
params_to_calibrate: velocity,diffusivity
optimization:
algorithm: L-BFGS # or Adam, gradient_descent
Network Topology#
dRoute uses mizuRoute-compatible NetCDF topology files. If you have already run mizuRoute preprocessing, dRoute can reuse the existing topology.
Required Topology Variables#
segId: Segment identifiersdownSegId: Downstream segment identifiersslope: Segment slopeslength: Segment lengths (m)hruId: HRU identifiershruToSegId: HRU-to-segment mappingarea: HRU areas (m²)
Optional:
width: Channel widths (m) - estimated from contributing area if not provided
Usage#
Standard Workflow#
from symfluence.models.droute import DRoutePreProcessor, DRouteRunner
# Preprocessing (reuses mizuRoute topology if available)
preprocessor = DRoutePreProcessor(config, logger)
preprocessor.run_preprocessing()
# Run routing
runner = DRouteRunner(config, logger)
output_path = runner.run_droute()
Calibration with Gradients#
from symfluence.models.droute.calibration import DRouteWorker
worker = DRouteWorker(config, logger)
# Check if gradients are available
if worker.supports_native_gradients():
# Efficient gradient computation via AD
loss, gradients = worker.evaluate_with_gradient(params, metric='kge')
else:
# Fallback to standard evaluation
metrics = worker.calculate_metrics(output_dir, config)
Switching from mizuRoute#
To switch from mizuRoute to dRoute:
Change routing model in config:
model: routing_model: DROUTE # was: MIZUROUTE
Run preprocessing (will reuse existing mizuRoute topology):
symfluence preprocessRun model:
symfluence run
The network topology from mizuRoute will be automatically detected and converted.
Troubleshooting#
Import Error: droute not found#
dRoute Python bindings are not installed. Either:
Install using:
symfluence tools install drouteBuild from source with
-DDROUTE_BUILD_PYTHON=ONInstall pre-built wheel:
pip install droute
AD/Gradient computation not available#
dRoute was not compiled with AD support. Rebuild with:
cmake .. -DDROUTE_ENABLE_AD=ON -DDROUTE_AD_BACKEND=codipack
No topology file found#
dRoute requires a network topology file. Either:
Run mizuRoute preprocessing first to generate topology
Provide a custom topology file in config
Disabling Experimental Warning#
To disable the experimental warning when importing dRoute:
export SYMFLUENCE_DISABLE_EXPERIMENTAL=1
Note: This will disable ALL experimental modules.
References#
Cunge, J.A. (1969). On the Subject of a Flood Propagation Method (Muskingum Method). Journal of Hydraulic Research.
mizuRoute: ESCOMP/mizuRoute
CoDiPack: SciCompKL/CoDiPack
Enzyme: https://enzyme.mit.edu/
See Also#
mizuRoute Routing Model Guide - Alternative routing model
Calibration and Optimization - Calibration framework documentation
SUMMA Model Guide - SUMMA model (common source for routing)