Simulation
Source-generated reference for simulation ownership, advancement, files, and scenario operations. See Run a model for workflows.
Hotstarts, checkpoints, and forks
See the continuation guide for choosing a mechanism. The method and bundle contracts are generated below.
Simulation
One isolated project, worker pool, and in-memory file system. Open with open, not the private constructor, and always await close. Handles and collections share this owner's lifecycle. Only one iterator or manual advancement may own the solver; result reads and allowed controls can run between observations. Records already returned remain usable after close.
Implements
AsyncIterable<ModelTime>AsyncDisposable
Properties
nodes
Configured-order node handles and aligned snapshot reads.
links
Configured-order link handles and aligned snapshot reads.
subcatchments
Configured-order subcatchment handles and aligned snapshot reads.
rainGages
Configured-order rain-gage handles; no collection snapshot API.
options
Stable model-option view, distinct from worker creation options.
pollutants
Pollutant identities; definition editing is not exposed.
landUses
Land-use identities.
timePatterns
Time-pattern identities.
curves
Curve identities.
timeSeries
Time-series identities; data editing is not exposed.
controls
Control-rule identities.
transects
Transect identities.
aquifers
Editable aquifer definitions.
snowmeltSets
Editable snowmelt parameter sets.
shapes
Custom cross-section shape identities.
streets
Street identities.
inletDesigns
Inlet-design identities.
ammModels
Editable AMM definitions; node assignments are separate.
unitHydrographs
Editable RTK definitions; RDII assignments are separate.
lidControls
Editable LID-control layers; unit placements belong to subcatchments.
Methods
open()
static open(
input: FileContents,
files?: Readonly<Record<string, FileContents>>,
options?: SimulationOptions
): Promise<Simulation>;
Parse an INP in a new independent worker.
Parameters
| Parameter | Type | Description |
|---|---|---|
input |
FileContents |
INP contents, never a host path. |
files |
Readonly<Record<string, FileContents>> |
Supporting-file contents keyed by INP-relative paths; defaults to an empty record. |
options |
SimulationOptions |
Worker URL and thread capacity; defaults to an empty record. |
Returns
Promise<Simulation>
An owner in open; close it when finished.
Throws
Rejects malformed input, invalid thread capacity, unavailable runtime prerequisites, or solver parse failures.
resume()
Restore a checkpoint in an independent worker without rerunning the model.
Parameters
| Parameter | Type | Description |
|---|---|---|
checkpoint |
CheckpointBundle |
Complete bundle, including manifest sidecars and dependencies. |
options |
SimulationOptions |
Worker creation options (the second argument); defaults to an empty record. |
Returns
Promise<Simulation>
An independent owner; no worker or mutable state is shared with the source.
Throws
Rejects unsupported, corrupt, mismatched, or incomplete checkpoint bundles.
getState()
Read native lifecycle state, including after cleanup.
Returns
Promise<SimulationState>
The current state, or closed after close completes.
info()
Read model identities, units, solver build, effective threads, and schedule while healthy.
Returns
Promise<SimulationInfo>
Detached model information.
status()
Read lifecycle and progress before close.
Returns
Promise<SimulationStatus>
Detached status; unavailable after cleanup.
updateSchedule()
Update calendar boundaries in open or ended; accepted edits return ended to open.
Parameters
| Parameter | Type | Description |
|---|---|---|
patch |
SchedulePatch |
Sparse timezone-free schedule. Omitted times retain their values. |
Returns
Promise<void>
Resolves after the schedule update is accepted.
ammAssignments()
Read the complete AMM node-assignment list.
Returns
Promise<readonly AmmAssignment[]>
Canonical node/model IDs and areas in project land-area units.
replaceAmmAssignments()
Atomically replace all AMM assignments in open or ended; accepted edits return the owner to open.
Parameters
| Parameter | Type | Description |
|---|---|---|
assignments |
readonly AmmAssignment[] |
Complete replacement list; an empty list clears all assignments. |
Returns
Promise<void>
Resolves after all assignments are accepted.
rdiiAssignments()
Read the complete RTK RDII assignment list.
Returns
Promise<readonly RdiiAssignment[]>
Canonical node/unit-hydrograph IDs and project land areas.
replaceRdiiAssignments()
Atomically replace all RTK assignments in open or ended; accepted edits return the owner to open.
Parameters
| Parameter | Type | Description |
|---|---|---|
assignments |
readonly RdiiAssignment[] |
Complete replacement list; an empty list clears all assignments. |
Returns
Promise<void>
Resolves after all assignments are accepted.
useHotstart()
Configure hotstart input in open or ended; accepted edits return the owner to open.
Parameters
| Parameter | Type | Description |
|---|---|---|
input |
FileContents | null |
Hotstart file contents, or null to clear the configured input. |
Returns
Promise<void>
Resolves after the configuration write.
saveHotstart()
Save current hydraulic state in running or complete.
Returns
Promise<Uint8Array<ArrayBufferLike>>
Caller-owned EPA hotstart bytes.
saveCheckpoint()
Capture a quiescent running or complete owner, including validated dependencies.
Returns
Promise<CheckpointBundle>
Complete portable checkpoint bundle with manifest sidecars.
loadCheckpointState()
Stage physical and numerical checkpoint state in an open owner.
Declarations, files, and persistent forcings remain those of the receiver.
Parameters
| Parameter | Type | Description |
|---|---|---|
checkpoint |
CheckpointBundle |
Compatible bundle with all required dependencies. |
Returns
Promise<void>
Resolves with the owner still open; state is applied by its next start.
Throws
Rejects incompatible identity, unsupported dependencies, corrupt manifests, or missing sidecars.
fork()
Save a checkpoint and resume it in a new independent owner.
Parameters
| Parameter | Type | Description |
|---|---|---|
options |
SimulationOptions |
Worker options for the child; defaults to an empty record. |
Returns
Promise<Simulation>
Independent simulation with copied run state and forcings.
start()
Start an open or ended model.
Parameters
| Parameter | Type | Description |
|---|---|---|
options |
RunOptions |
Run options; saveResults defaults to true. |
Returns
Promise<void>
Resolves after solver initialization succeeds.
step()
Advance one routing step in a started run, without an active iterator.
Returns
Promise<string | null>
New model time, or null at natural completion.
stride()
Advance an observation interval in a started run.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
seconds |
number |
undefined |
Positive 32-bit integer interval in seconds. |
strict |
boolean |
true |
Defaults to true: land exactly on the boundary. False allows whole-step overshoot. |
Returns
Promise<string | null>
New model time, or null at natural completion.
[asyncIterator]()
Automatic start and routing-step advancement; exhaustion retains final statistics.
Returns
AsyncGenerator<string, void, unknown>
The same async generator as steps with default options.
Implementation of
steps()
Iterate observations, lazily starting open or ended owners on the first next().
Early exit releases advancement ownership, leaving the run available to finish or resume.
Parameters
| Parameter | Type | Description |
|---|---|---|
options |
StepOptions |
Observation/run options; routing-step cadence, strict boundaries, and retained results by default. |
Returns
AsyncGenerator<string, void, unknown>
Generator of observation times. Natural exhaustion leaves final statistics available.
Throws
Rejects invalid intervals/flags or competing advancement/finalization.
terminate()
End active iteration at its next observation boundary, without closing the owner.
Returns
void
Immediately; the iterator performs the end operation at its next boundary.
Throws
Synchronously throws LifecycleError if no iterator owns advancement.
node()
Direct node result read retained for prototype callers; requires results to be available.
Parameters
| Parameter | Type | Description |
|---|---|---|
id |
string |
Node ID resolved in the worker, not by a local collection lookup. |
Returns
Promise<NodeResults>
Detached node hydraulics; unknown IDs reject the promise.
link()
Direct link result read retained for prototype callers.
Parameters
| Parameter | Type | Description |
|---|---|---|
id |
string |
Link ID resolved in the worker. |
Returns
Promise<LinkResults>
Detached link hydraulics; unknown IDs reject the promise.
setNodeExternalInflow()
Direct equivalent of nodes.get(id).setExternalInflow(flow).
Parameters
| Parameter | Type | Description |
|---|---|---|
id |
string |
Node ID resolved in the worker. |
flow |
number |
Persistent additive inflow in project flow units. |
Returns
Promise<void>
Resolves after updating the forcing in open, running, or ended.
setLinkTargetSetting()
Direct equivalent of links.get(id).setTargetSetting(setting); requires running.
Parameters
| Parameter | Type | Description |
|---|---|---|
id |
string |
Link ID resolved in the worker. |
setting |
number |
Dimensionless opening or pump speed factor. |
Returns
Promise<void>
Resolves after updating the target; unknown IDs reject the promise.
statistics()
Read system statistics in running or complete, before ending the run.
Returns
Promise<SimulationStatistics>
Detached cumulative totals, continuity balances, and routing diagnostics.
finish()
End the run, write requested reports, and finalize binary output; safe to repeat in ended.
Supports partial runs and retains the owner for result reads and reruns.
Returns
Promise<RunResults>
Finalized report and caller-owned output bytes; output is empty with saveResults: false.
run()
Start, run to completion, and finalize with one worker request.
Parameters
| Parameter | Type | Description |
|---|---|---|
options |
RunOptions |
Run options; saveResults defaults to true. |
Returns
Promise<RunResults>
Finalized files, retaining the owner in ended until closed or reused.
end()
End a running or complete run without detailed report tables.
Returns
Promise<void>
Resolves after flushing output/summary statistics and entering ended.
finalizeReport()
Append and flush only the runtime footer in ended, once, even without saved results.
JavaScript exposes this before close removes its in-memory files; Python report paths survive close.
Returns
Promise<void>
Resolves after the footer is flushed, without detailed report tables.
report()
Generate requested detailed report tables and footer in ended, once.
Returns
Promise<void>
Resolves after flushing the report.
Throws
Rejects when the run did not retain binary results.
resetSolver()
Discard run/results/output state in open or ended without reparsing the INP.
Retains declarations and persistent forcings; clears staged checkpoint state.
Returns
Promise<void>
Resolves with the owner in open.
sleepWorkers()
Put active Dynamic Wave workers to sleep; requires running.
Returns
Promise<void>
Resolves after the power-state operation; lifecycle state is unchanged.
readFile()
Copy a project or generated file before close; does not flush or finalize a run.
Parameters
| Parameter | Type | Description |
|---|---|---|
name |
string |
Path in the worker's project file system, not a host path. |
Returns
Promise<Uint8Array<ArrayBufferLike>>
Caller-owned bytes. Call finish first for finalized report/output files.
close()
Release the project, workers, and in-memory files. Repeated calls share cleanup.
Returns
Promise<void>
Resolves when cleanup finishes; all owner-bound handles then become unusable.
[asyncDispose]()
Await resource cleanup for await using.
Returns
Promise<void>
The same cleanup promise as close.
Implementation of
CheckpointBundle
Transferable bytes and files captured at one quiescent simulation boundary.
Properties
ScenarioMethod
Low-level scenario operation names; prefer the methods on Simulation for execution.
ScenarioArgs
Argument tuple for a low-level scenario operation.
Type Parameters
| Type Parameter | Description |
|---|---|
K extends ScenarioMethod |
Scenario operation name. |
ScenarioResult
Resolved result type for a low-level scenario operation.
Type Parameters
| Type Parameter | Description |
|---|---|
K extends ScenarioMethod |
Scenario operation name. |
runSwmm()
function runSwmm(
input: FileContents,
files?: Readonly<Record<string, FileContents>>,
options?: SimulationOptions & RunOptions
): Promise<RunResults>;
Open, run, finalize, and close one INP model. Also exported as the package default.
Parameters
| Parameter | Type | Description |
|---|---|---|
input |
FileContents |
INP contents, never a host path. |
files |
Readonly<Record<string, FileContents>> |
Supporting-file contents keyed by INP-relative paths; defaults to an empty record. |
options |
SimulationOptions & RunOptions |
Worker and run options; retained results by default. |
Returns
Promise<RunResults>
Finalized report and caller-owned binary output after cleanup.
Throws
Preserves the run error if cleanup also fails, attaching the secondary failure as cleanupError.