Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SDK Overview

hydra-sdk is the umbrella crate for Hydra’s public API. Add it to your Cargo.toml:

[dependencies]
hydra-sdk = "6"

It re-exports every type needed to parse networks, run simulations, query results, run post-simulation analytics, and generate reports — with all internal dependency versions pre-pinned.

Modules and Key Types

Session API

The primary entry point. Import Simulation to parse, run, and query a network.

Type / functionPurpose
SimulationCreates and drives a simulation session
SessionErrorError type returned by all session methods
SimWarning / WarningKindNon-fatal diagnostics produced during a run
NodeQuantityEnum of per-node result variables (Head, GaugePressure, Demand, Quality)
LinkQuantityEnum of per-link result variables (Flow, MeanVelocity, UnitHeadLoss, FrictionFactor, Quality, Status, Setting)
NodeResult / LinkResultBatch result containers
ResultRangesMin/max envelopes across all nodes/links/time
HydSnapshotSingle-step hydraulic state snapshot
PumpEnergyPer-pump energy and efficiency metrics
FlowBalance / MassBalanceNetwork-wide accounting at simulation end
WritableSimulationTrait required by the I/O writers

Analytics

Post-simulation analysis functions that operate on a saved .out file.

Type / functionPurpose
compute_demand_reliability_from_outPer-junction demand reliability metrics
compute_service_compliance_from_outPer-node pressure compliance metrics
DemandReliabilityReport / DemandReliabilitySummaryDemand reliability results
ServiceComplianceReport / ServiceComplianceSummaryPressure compliance results
DemandReliabilityNode / ServiceComplianceNodePer-node entries within each report’s nodes list
DemandReliabilityOptionsOptions for reliability computation (deficit tolerance)
compute_demand_reliability_from_out_with_optionsReliability variant taking explicit DemandReliabilityOptions
ServiceComplianceThresholdsMin/max pressure thresholds for compliance check

Data Model

The full network data model, mirroring the EPANET .inp structure.

TypePurpose
NetworkTop-level container returned by io::parse
Node / NodeKindPolymorphic node (Junction, Reservoir, Tank)
Link / LinkKindPolymorphic link (Pipe, Pump, Valve)
Pattern / CurveTime patterns and XY curves
SimulationOptionsAll [OPTIONS] and [TIMES] settings
QualityModeChemical, age, or source-trace quality mode
FlowUnits / HeadLossFormulaUnit system and head-loss formula enums
ValidationErrorStructural network validation errors

I/O

#![allow(unused)]
fn main() {
use hydra_sdk::io;
}
Function / modulePurpose
io::parse(&bytes)Parse EPANET .inp bytes into a Network, failing if the result would not be simulable. Match io::ReadError::ForeignDialect separately: it means the bytes are another engine’s model, not a bad file — see Foreign .inp dialects
io::parse_tolerant(&bytes)Parse and return the Network with its validation errors instead of failing — for editors and inspectors that must show an invalid model. A non-empty error list means it must not be simulated
io::write_inp(&network)Serialise a Network back to .inp bytes
io::rpt_writer::build_text_report(&sim)Build a plain-text .rpt report string
io::rpt_writer::build_json_report(&sim)Build a JSON report string
io::out_writer::write_binary_output(&mut w, &sim, input_file, report_file, units)Write EPANET-compatible .out binary
io::out_readerRead and inspect existing .out files
io::compute_network_digestStable content digest of a Network (also re-exported at the crate root)

Engine Identity

#![allow(unused)]
fn main() {
use hydra_sdk::common;
}

Every Hydra engine publishes an immutable descriptor. Applications resolve a project’s stored engine key against the registry rather than hardcoding names, colours, or file filters. See Engines for the current roster and what Planned means in practice.

Type / functionPurpose
common::ENGINESEvery engine compiled into this distribution, in presentation order
common::engine_by_key(key)Resolve a key to its descriptor, or an UnknownEngineError
common::EngineDescriptorkey, label, pill, accent, summary, status, import
common::EngineStatusAvailable or Planned — a planned engine is registered but has no implementation
common::ImportFormatA source-model format the engine reads: label plus extensions

import is a file-picker filter, never a validity test — wds and uds both claim .inp with incompatible contents, so only the owning engine’s parser can decide whether a file really is its model.

Reports

#![allow(unused)]
fn main() {
use hydra_sdk::{report, report_catalog, produce_report_block};
}

Report generation is split in two: the engine produces neutral content fragments, and report turns them into documents. The report layer knows nothing about engines.

Type / functionPurpose
report_catalog()The engine’s block catalog — queryable without running a simulation
report_block_options(id, network)The options a given block accepts, with labels, defaults, and bounds — enough to build an editor without hardcoding them. Advisory: an unknown id or a block with nothing to configure yields an empty list rather than an error
produce_report_block(id, out_path, network, options)Materialise one block for a completed run
report::ReportTemplateAn ordered list of block references plus a document title (JSON)
report::assemble(template, catalog, context, produce)Pair a template with a producer to build a render-ready document
report::render_txt / render_csv / render_htmlDeterministic renderers — identical inputs give byte-identical output
report::render_pdfTypeset PDF; behind hydra-sdk’s report-pdf feature, and the only renderer that can fail (PdfError)
common::BlockDescriptor / FragmentThe catalog entry and produced-content types the two halves exchange

Also re-exported

Beyond the tables above, hydra-sdk re-exports several supporting items:

  • Version constantsHYDRA_VERSION and the per-subsystem HYDRA_*_VERSION strings.
  • Runtime estimationestimate_simulation_runtime, estimate_simulation_runtime_from_summary, and RuntimeEstimate. The millisecond-level forms estimate_simulation_runtime_millis_from_summary and classify_simulation_runtime_millis are also available when you want the raw prediction or the bucketing separately.
  • Threshold binningthreshold_bands(values, edges) counts values into the bands defined by ascending edges, with the outer two unbounded so nothing is dropped. It is the same binning the wds.*-thresholds report blocks use, so an interface presenting that view counts identically.
  • Threshold binningthreshold_bands, the shared band-counting used by the *-thresholds report blocks, so an interface presenting the same view counts identically.