HydroForge
HydroForge is a toolkit for uncertainty injection and scenario generation in water distribution network (WDN) simulations. It provides probability distributions and uncertain parameters, sampling strategies, sensor-imperfection models, network modifiers, EPANET file I/O, graph analysis, sensor placement, and a common simulation-backend facade.
Project status
HydroForge is alpha software. hydroforge.wdn_modelling.backends is the
supported simulation entry point and sole supported implementation.
The legacy hydroforge.simulation, hydroforge.scenario_generation,
hydroforge.topology, and hydroforge.uncertainty_sampling packages have been
retired in favour of hydroforge.wdn_modelling.backends and
hydroforge.sampling.
Installation
HydroForge requires Python 3.10 or newer. After a release is available on PyPI, install the distribution with:
pip install hydroforge-tools
For an editable development installation, use a source checkout:
git clone https://github.com/tomjanus/HydroForge.git
cd HydroForge
# Runtime installation
pip install -e .
# Development installation (black, flake8, mypy, pytest)
pip install -e ".[dev]"
The core dependencies are declared in pyproject.toml and include NumPy, SciPy,
pandas, NetworkX, Matplotlib, PyYAML, Rich, pygad, cloudpickle, SALib, and WNTR.
Transient solver backends are optional extras. Install only the backend you need:
| Backend | Solver package |
|---|---|
wntr |
WNTR (core dependency) |
tsnet |
pip install "git+https://github.com/glorialulu/TSNet.git" |
tsnetplus |
pip install "git+https://github.com/tomjanus/TSNetPlus.git" |
ptsnet |
pip install "hydroforge-tools[ptsnet]" |
TSNet and TSNetPlus are installed directly from GitHub because PyPI does not
allow direct URL requirements in published package metadata. ptsnet installs
the package from PyPI. If code requests a transient backend whose package is
missing, HydroForge explains which package is required and asks whether to
install it. Installation happens only after an explicit y or yes; pressing
Enter (or answering n) leaves the environment unchanged.
Quick start
from hydroforge import __version__
from hydroforge.measurements import RandomNoiseSensor
print(f"HydroForge version {__version__}")
sensor = RandomNoiseSensor(sigma=0.05, seed=42)
measurement = sensor.measure(1.0)
The command-line interface is currently a placeholder. hydroforge --version
works, but run-analysis, localize, and sensor-placement report that they
are not implemented and exit with a non-zero status.
Package layout
Generic (domain-agnostic, importable without any WDN modelling package dependencies)
| Package | Purpose | Current state |
|---|---|---|
hydroforge.uncertainty |
Distributions, uncertainty transforms, parameters, CDFs | Supported |
hydroforge.sampling |
Monte Carlo, LHS, Sobol, Halton, stratified, conditional, nested, scenario-tree and mixed sampling | Supported (SALib is a core dependency) |
hydroforge.measurements |
Imperfect-sensor models and window averaging (renamed from sensors) |
Supported |
hydroforge.auxiliary |
Configuration I/O, logging, exceptions, utility helpers | Supported |
WDN / EPANET-specific modelling
| Package | Purpose | Current state |
|---|---|---|
hydroforge.wdn_modelling.backends |
Common backend facade for WNTR, EPANET, TSNet, TSNetPlus, and PTSNet | Supported; optional solvers required |
hydroforge.wdn_modelling.epanetfile_io |
Typed EPANET .inp parsing, editing, and writing without WNTR |
Supported |
hydroforge.wdn_modelling.graphs |
EPANET network graph analysis and visualization | Supported |
hydroforge.wdn_modelling.networks |
Model/graph selectors and JunctionLeaks |
Supported |
hydroforge.wdn_modelling.modifiers |
WNTR model and graph modifiers | Supported |
hydroforge.wdn_modelling.uncertainty |
Apply realized parameters and generic sensors to WNTR models/results | Supported |
hydroforge.wdn_modelling.measurement_placement |
Sensor placement and sensor-network graph (depends on graphs) |
Supported |
API overview
Uncertainty distributions and parameters
from hydroforge.uncertainty import (
NormalDistribution,
UniformDistribution,
AdditiveUncertainty,
Parameter,
ParameterType,
)
diameter = Parameter(
name="diameter",
nominal_value=200.0,
uncertainty=AdditiveUncertainty(NormalDistribution(mean=0.0, std_dev=2.5)),
type=ParameterType.NUMERICAL,
)
value = diameter.sample()
controlled = diameter.sample_from_unit(0.5)
cdf_at_200 = diameter.cdf(200.0)
Available distributions include NormalDistribution, UniformDistribution,
DiscreteNormalDistribution, DiscreteUniformDistribution,
DiscreteHistogramDistribution, DiracDeltaDistribution, the categorical
variants, and DistributionChecker.
Sampling
from hydroforge.sampling import MonteCarloSampler, LatinHypercubeSampler
sampler = LatinHypercubeSampler([diameter], seed=42)
for scenario in sampler.generate(100):
print(scenario.id, scenario.values)
The sampling package also exports SobolSampler, HaltonSampler,
StratifiedSampler, ConditionalMonteCarloSampler,
NestedMonteCarloSampler, ScenarioTreeSampler, MixedStrategySampler,
GibbsSampler (a legacy independent marginal resampler, not MCMC), and
supporting specification types. See
src/hydroforge/sampling/README.md for the
statistical assumptions and current limitations.
Sensors and sensor placement
from hydroforge.measurements import (
FixedPrecisionSensor,
RandomNoiseSensor,
CompositeSensor,
WindowAverager,
)
sensor = CompositeSensor(
FixedPrecisionSensor(delta_y=0.01),
RandomNoiseSensor(sigma=0.005, seed=42),
)
measured = sensor.measure(1.234)
averager = WindowAverager(window_size=3)
averaged = averager.average([1.0, 1.1, 0.9, 1.2, 1.0, 1.1])
Placement strategies are available through hydroforge.wdn_modelling.measurement_placement:
GreedySensorPlacement, KCentreSensorPlacement, RandomSensorPlacement,
CentralityBasedSensorPlacement, CoverageBasedSensorPlacement,
DominatingSetBasedSensorPlacement, and FixedLocationSensorPlacement, all
orchestrated by SensorPlacer.
Applying realized parameters to a WNTR model
WDN parameter bindings connect a component property to a named value in a caller-owned mapping. The adapter does not sample or run the simulator; it preflights the complete binding set, updates the supplied model in place, and returns an ordered audit report.
Supported properties are diameter, diameter_multiplier, and roughness on
pipes; base_demand on a junction with exactly one demand timeseries; and
valve_setting. PRV/PSV/FCV settings must be positive numbers, TCV settings
must be non-negative, GPV settings reference an existing HEADLOSS curve, and
PBV settings are OPEN or CLOSED. Multiple junction demand entries are
rejected rather than partially updated.
from hydroforge.wdn_modelling.uncertainty import (
WNTRParameterAdapter,
WNTRParameterBinding,
)
adapter = WNTRParameterAdapter(
[WNTRParameterBinding("P1", "diameter", "pipe_diameter")]
)
audit = adapter.apply(model, {"pipe_diameter": 0.25})
After running WNTR, bind generic sensor definitions to selected points and
variables. Only the bound result columns are measured; the raw results are left
unchanged. The example assumes specification, model, and results have
already been created by the caller.
from hydroforge.wdn_modelling.uncertainty import (
WNTRSensorAdapter,
WNTRSensorBinding,
)
sensor_adapter = WNTRSensorAdapter(
[WNTRSensorBinding("J1", "pressure_sensor", "pressure")],
specification.sensors,
)
measured = sensor_adapter.apply(model, results)
Simulation backends
from hydroforge.wdn_modelling.backends import get_backend
backend = get_backend("wntr")
model = backend.load_model("tests/base_networks/Net1_shortened.inp")
results = backend.create_simulator().run(model)
pressure = results.get_node_variable(
"pressure",
list(model.junction_name_list)[:3],
as_dataframe=True,
)
Backend configuration is split into persistent model options
(backend.apply_config(...)) and simulator runtime options
(backend.create_simulator(...)). WNTR uses WNTRConfig,
WNTRSimulatorConfig, and EPANETSimulatorConfig; the transient backends
currently use one configuration type for both scopes.
EPANET file I/O
from hydroforge.wdn_modelling.epanetfile_io import EPANETNetworkModelIO
network = EPANETNetworkModelIO.from_inp_file("network.inp")
network.junctions.modify_by_field("id", "J1", elevation=105.0)
EPANETNetworkModelIO.to_inp_file(network, "modified.inp")
Graphs
from hydroforge.wdn_modelling.graphs.graph import EPANETNetworkGraph
from hydroforge.wdn_modelling.graphs.visualization import EPANETGraphPlotter
network = EPANETNetworkGraph.from_epanet_file("network.inp")
print(network.find_total_length())
print(network.find_bridges())
EPANETGraphPlotter(network).plot(title="Water network")
Examples
Examples are grouped under examples/. The following example is verified to run
with the core dependencies:
PYTHONPATH=src python examples/measurements/ex1_sensors.py
Other examples demonstrate the backend registry, EPANET file I/O, graph
analysis, sampling, uncertainty distributions, and sensor placement. Some
examples require optional solvers or SALib; those are only runnable when the
corresponding dependency is installed.
Configuration
hydroforge.auxiliary.load_config() reads YAML with yaml.safe_load. The
repository contains legacy configuration files under data/config/; they
reference retired modules and are not working templates.
Development
# Formatting
black --check .
# Linting
flake8 --config=.flake8 .
# Type checking
mypy .
# Tests
pytest
The CI workflow runs the same commands on Python 3.12 and builds the package.
Repository conventions and the development workflow are described in
WORKFLOW_GUIDELINES.md. Domain terminology is in
GLOSSARY.md.
Citation
If you use HydroForge in research, cite the HydroForge repository and record the version or commit used. A formal archived citation and DOI have not yet been assigned for this project, so no DOI is provided here.
License
HydroForge is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
HydroForge is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with HydroForge. If not, see https://www.gnu.org/licenses/.
Contributing
Bug reports and feature requests can be opened on the GitHub issue tracker.
Contributions should follow the repository style checks (black, flake8,
mypy) and include tests for new behaviour. Do not open a pull request that
claims validation for a backend or optional dependency that was not actually
exercised.
Metadata
Release files for hydroforge-tools 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hydroforge_tools-1.0.1.tar.gz | 199.8 kB | With provenance | Details for hydroforge_tools-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hydroforge_tools-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for hydroforge_tools-1.0.1-py3-none-any.whl |
Total release size: 401.3 kB
Release files / hydroforge_tools-1.0.1.tar.gz
| Download URL | hydroforge_tools-1.0.1.tar.gz |
|---|---|
| Size | 199.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9dfe3bdf2769fe064747b5b4ddffb40cabfa9e0b657214a369be93dbd6f6f102
|
|
BLAKE2b-256 checksum How to use checksums |
2bc0f90901a8a2d728d4f2325829b1849e426036681cee821e031a9b21a73cf1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logRelease files / hydroforge_tools-1.0.1-py3-none-any.whl
| Download URL | hydroforge_tools-1.0.1-py3-none-any.whl |
|---|---|
| Size | 201.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6fbd8f443d3363eca5fde2ca8bd9d30443e913c0e4895a7c63a4a35b01500848
|
|
BLAKE2b-256 checksum How to use checksums |
70e835c2792f0f51af12b3a35776f1bdd7505553b1d140bc1cb03aecafed1d98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logSecurity for hydroforge-tools 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for hydroforge_tools-1.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.