Integration Guide

Sparlectra in your own scripts, jobs and tools: one API call, one configuration file, one result contract. Details live on the linked pages.

Quickstart

using Sparlectra
using SparlectraApp   # service API: environment app/, or app/ on the load path

result = run_sparlectra_api(
  casefile = "case118.m",
  output_dir = "runs/first",
  config_overrides = Dict("power_flow.mode" => "auto"),
)

println(result.status)          # :succeeded or :not_converged
println(result.metadata["auto_profile"])
println(result.output_dir)      # artifacts live here

The case file (MATPOWER, CGMES ZIP, PowSyBl IIDM, SCF or DTF) is imported, auto mode picks the solver strategy, and the run directory carries every artifact. Call surface and result fields: Programmatic API; request dictionaries and the run registry: Local PowerFlow Service.

Loading both packages

using Sparlectra, SparlectraApp works in a Julia started in the checkout with --project=app. In the default environment neither package is found (the registry offers Sparlectra, the library alone); activate the application environment first:

using Pkg
Pkg.activate("path/to/Sparlectra/app")   # the checkout's app/ directory
Pkg.instantiate()                        # first time only
using Sparlectra, SparlectraApp

On the library project (julia --project=.) only SparlectraApp is missing: put app/ on the load path, as start_webui.jl does, or activate app/ as above:

push!(LOAD_PATH, joinpath(pwd(), "app"))   # from the checkout root
using Sparlectra, SparlectraApp

The configuration file

Every option is a key in one YAML file; effective_config.yaml in the run directory states what took effect. Precedence, scopes and key reference: Configuration; power-flow options: PowerFlow Configuration. The packaged template carries every key with its default and a comment:

using Sparlectra
using SparlectraApp   # service API: environment app/, or app/ on the load path
cp(Sparlectra.DEFAULT_SPARLECTRA_CONFIG_PATH, "my_configuration.yaml")

Per run, or once per session:

result = run_sparlectra_api(casefile = "case118.m", output_dir = "runs/a",
                            config_file = "my_configuration.yaml")

Sparlectra.load_sparlectra_config!("my_configuration.yaml"; reload = true)
runpf!(net)                    # every later call uses it

Single values need no file: config_overrides = Dict("power_flow.tol" => 1e-6) in the API call, or --set power_flow.tol=1e-6 on the command line. Unknown keys and invalid values are refused by name before anything runs. A <stem>.config.yaml next to a case file carries the case's own settings and wins over the machine configuration (Configuration precedence); the Web UI edits the machine file on its Settings page.

Startup latency

The first run in a fresh Julia process compiles and is slow, later runs are fast: keep the process running, or build a sysimage once. output.startup_latency_hint: false silences the one-line hint at the first run.

Auto mode

power_flow.mode = auto inspects the imported network (size, AC islands, R/X profile, phase shifters, start profile, generator Q limits) and fills the start-value, step-control and Q-limit strategy. On non-convergence a bounded escalation ladder retries with stronger strategies, up to an APSLF-seeded Newton-Raphson run and an optional DC fallback (power_flow.dc.fallback, off by default, API-only). It never changes the tolerance, mutates the network, overrides an option you set explicitly, or reports a DC result as an AC solution. Every decision, precedence conflict, escalation attempt and hint lands in the auto_mode_decision.log artifact of the run.

Q limits

When a generator's reactive limit binds, its bus switches from voltage control (PV) to fixed injection (PQ): physics, not an error. Bad or missing limit data is the most common cause of non-convergence and strange voltages. Auto mode handles switching, guards and enforcement mode, and reports what it did as one-line hints (auto_hints in the result metadata, the decision log, the Web UI result page) that name the buses and generators to check in the source data.

Result contract

Field / artifactMeaning
result.run_idunique id, also the run directory name
result.status:succeeded or :not_converged
result.convergedthe AC solution converged and was accepted (a run the solver rejected, wrong branch or Q-limit rejection, reports false; the numerical state is result.metadata["numerical_converged"]); never true for a DC fallback
result.metadata["dc_fallback_solution"]true when the net carries a DC approximation after AC failure
result.metadata["auto_hints"]advisory hint texts; auto_hint_ids carries stable keys for programmatic matching
result.metadata["auto_profile"], auto_final_stage, auto_final_solver, auto_final_strategy, auto_escalation_stageswhat auto mode decided, how far it escalated, and which solver-internal rescue strategy converged inside the final stage (none when the stage's own solve did)
result.jsonthe machine-readable result in the run directory
effective_config.yamlthe exact configuration the run used
auto_mode_decision.logfeatures, profile, reasons, conflicts, attempts, hints

When auto mode fails

Read the hints and auto_mode_decision.log first. If the case still does not converge, open an issue and attach result.json and the case file.