Library
Embed the decision engine and supply its topology, observations and clock.
use fms::prelude::*;
let grid = GridSpec { v_nom_kv: 0.4, transformer, lines }; // e.g. from a CIM export
let mut engine = Engine::new(Topology::new(grid)?, connections, RuleSet::bk6_22_300())?;
let mut log = Log::new();
loop {
let now = clock.now();
log.extend(now, engine.step(Input::Measurements(meters.drain()), now));
log.extend(now, engine.step(Input::Profiles(forecast.at(now)), now));
for out in engine.step(Input::Tick, now) {
if let Output::Command(c) = &out { transport.send(c)?; }
if let Output::Release(r) = &out { transport.release(r)?; }
log.append(now, out);
}
for ack in transport.acknowledgements() {
log.extend(now, engine.step(Input::Ack { connection: ack.connection, msg: ack.msg }, now));
}
}
Engine::newrefuses a rule set that breaks a legal bound, and master data that does not fit the topology.- Every
Commandcarrieslimit ≥ floor, an end timevalid_until, and areason. Eachcommand::InputRefinreason.inputsrecords the source, measurement time and aReadingTarget::ConnectionorReadingTarget::Asset. A retry retains the original references. engine.view()gives the last cycle's transformer estimate and congestions for a display.fms::evidence::{documentation, publication}turn the log into reports.
Read a complete evidence file with Log::from_jsonl to verify the chain. For a single JSON event, use Output::from_json. Both use FMS's replay decoder for fractional readings and integer identifiers, including in a build that enables arbitrary-precision JSON through another dependency.
The default cli feature builds the command-line tool and enables sim. Use default-features = false to embed only the decision engine. Run cargo doc --locked -p fms --no-deps --open from the workspace root for the API reference.
Commissioned feeders🔗
Deserialize a feeder's inventory to Vec<fms::commission::Premises> and pass it to Commissioning::resolve. Call preview(&rules, date) for a dated, serializable explanation. Move the validated layout into Engine::commissioned(topology, layout, rules). Measurements and profiles reference IDs from engine.connections(). Commands and replies reference IDs from engine.targets(). Each commissioned command includes the parent premises, eligible units and floor calculation. The connection field of a dispatch record identifies its addressable target. Executable example
Observe a decision cycle🔗
Engine::tick_with_snapshot(now, observe) returns the same outputs as a tick and gives the observer a borrowed estimator snapshot. The observer receives None when the rule set is inactive. Each physical load exposes Quality::Measured, Reconciled or Pseudo. The estimator reports excluded asset observations as RejectedAsset with the asset, source, measurement time and reason. A rejected engine event carries the original InputRef and its rejection reason. Observation coverage
A commissioned Release carries the original command’s assignment. Read its parent connection from assignment.premises. The Control Measures adapter checks the recorded SR-ID and control mode against the supplied registration before it encodes either a limit or a release.
EvidenceHead incrementally hashes engine output using the same sequence and encoding as Log. The paired replay CLI uses it to compare both evidence heads while retaining only the first detailed difference. The library's static-register publication projection is a simulation preview. The field workflow uses the dated register and reviewer approval. Monthly review
fms::congestion::assess(&topology, asset, &forecast) gives each ISP's forecast flow through one asset, its spread, rating and the excess of the P95 band. fmsd's flexibility market commands build on it.