Central Configuration
Sparlectra uses one central, typed configuration model.
The main entry point is Sparlectra.load_sparlectra_config(...), which:
- loads YAML defaults,
- optionally overlays a user YAML,
- applies programmatic overrides,
- validates key names and value domains,
- builds a typed
SparlectraConfigobject used by runtime modules.
Configuration files and selectors
| Item | Path / mechanism | Role |
|---|---|---|
| Default config | src/configuration.yaml.example | Version-controlled baseline for all options. |
| User override | examples/configuration.yaml | Local override file (project default user path). |
| Explicit config path | load_sparlectra_config("/path/to/file.yaml") | Replaces default user override path for that load call. |
| Environment-based path selection helper | SPARLECTRA_CONFIGURATION_YAML via configuration_path_from_inputs(...) | Used by script/example path resolution workflows. |
Merge precedence
Configuration precedence (low → high):
src/configuration.yaml.exampleexamples/configuration.yaml(or explicituser_path)cli_overridesoverrides
Unknown keys are rejected during validation. Removed keys are also rejected with migration hints (for example matpower_import.benchmark → benchmark.enabled).
Typed central object
The merged YAML is converted into:
SparlectraConfigpowerflow::PowerFlowConfigstate_estimation::StateEstimationConfigmatpower::MatpowerImportConfigtransformer::TransformerConfigperformance::PerformanceConfigbenchmark::BenchmarkConfigruntime::RuntimeConfigdiagnostics::DiagnosticsConfigoutput::OutputConfigcontrol::ControlConfig
This typed model is the canonical internal representation that should be consumed by power-flow, MATPOWER import, state estimation, output/reporting, performance profiling, benchmark runners, and future modules.
YAML structure (section map)
| YAML section | Typed section | Purpose | Status |
|---|---|---|---|
power_flow | PowerFlowConfig | Rectangular power-flow solver controls, start mode, Q-limits | Public / supported |
matpower_import | MatpowerImportConfig | MATPOWER case path + import interpretation options | Public / supported |
transformer | TransformerConfig | Transformer-modeling options shared by all importers (tap-changer model) | Public / supported |
state_estimation | StateEstimationConfig | State-estimation runtime controls | Public / supported |
output | OutputConfig | Console/logfile behavior and result table sizing | Public / supported |
performance | PerformanceConfig | Profiling/reporting toggles and diagnostic volume controls | Public / supported |
benchmark | BenchmarkConfig | Repeated benchmark-run controls | Public / supported |
control | ControlConfig | Generic controller outer-loop orchestration controls (control.controllers reserved for future YAML definitions) | Public / supported |
runtime | RuntimeConfig | Julia/BLAS thread control knobs for entry workflows | Public / supported |
diagnostics | DiagnosticsConfig | Effective-config logging and diagnostics render controls | Public / supported |
webui | WebUIConfig | Web UI presentation preferences (e.g. webui.show_case_settings_notice) | Public / supported |
extensions | reserved (not mapped to typed runtime fields) | Future extension placeholder | Reserved |
Supported power-flow path
The supported public power-flow solver path is rectangular (power_flow.method: rectangular).
Option lifecycle and compatibility policy
Sparlectra docs distinguish option categories:
- Public / supported: keys in
src/configuration.yaml.exampleand typed section constructors. - Reserved: schema placeholders such as
extensions.reservedfor forward compatibility. - Deprecated compatibility aliases: accepted for migration but not preferred in new YAML (for example
max_iteand some start-projection alias keys). - Removed: explicitly rejected keys with migration error guidance (for example
matpower_import.benchmark). - Internal-only implementation details: not documented as stable external user API.
Prefer canonical nested keys shown in the example YAML and module pages.
MATPOWER import metadata and DC-line options
matpower_import.apply_bus_names, apply_branch_names, and apply_branch_kind default to false so existing imports keep numeric bus names and heuristic branch classification. Enable them when MATPOWER cases carry validation metadata such as standard mpc.bus_name and user-defined mpc.branch_name/mpc.branch_kind. import_for001_contingencies defaults to true and preserves user-defined mpc.for001_contingencies for validation workflows. matpower_import.matpower_dcline_mode defaults to :pf_injections; use explicit :reject_active when strict active-row rejection is required. The default uses simple MATPOWER power-flow DC-line terminal injections are desired. OPF and dclinecost remain unsupported.
AC island solving
Disconnected AC islands are not tied together by MATPOWER mpc.dcline terminal injections: those injections affect bus power balance but do not add Ybus branches. power_flow.islands.enabled: true is the default, so these disconnected AC components are solved independently unless the user explicitly disables island solving:
power_flow:
islands:
enabled: true
mode: solve_independent
reference_policy: matpower_likeThe matpower_like policy keeps an existing island REF/Slack bus, otherwise promotes the deterministic first PV/voltage-controlled bus as that island's angle reference. Islands without REF/Slack or PV support fail before NR. When multiple islands are detected, Sparlectra writes ac_islands.csv in the run directory with bus, branch, generator/load, DC-line terminal, power-balance, reference, and status diagnostics.
Transformer tap-changer model
transformer.tap_changer_model selects, for all transformers of an imported case, whether the tap changer is treated as electrically ideal or as affecting the series impedance:
transformer:
# Allowed values: ideal, impedance_correction
tap_changer_model: idealideal(default): tap steps only change the complex winding ratio; the transformer series impedance (R, X) keeps its neutral-position value. This preserves prior Sparlectra behavior.impedance_correction: tap steps additionally re-refer the series impedance through the tapped winding. R and X are scaled with the squared magnitude of the regulating vector,|1 + f·e^(jφ)|², wherefis the longitudinal regulating-voltage fraction andφthe skew angle (0° for a pure longitudinal/ratio tap changer).
The option is read by both the MATPOWER importer (createNetFromMatPowerFile/createNetFromMatPowerCase) and the native DTF importer (DTFImporter.build_net/createNetFromDTFFile), but the correction math itself lives in a single place, calcTapCorrectedRX/calcTapImpedanceCorrectionFactor in src/equicircuit.jl, so importers stay free of duplicated tap-impedance mathematics.
The corrected R/X values are what a subsequent writeMatpowerCasefile export writes out (both the MATPOWER and the native DTF import path use the same Branch.r_pu/Branch.x_pu fields the exporter reads). When such a case was corrected on import, the exporter records a mpc.sparlectra.tap_changer_model = 'impedance_correction' roundtrip marker so a Sparlectra reimport does not reapply the correction a second time; see Tap-impedance correction and reimport.
Loader and validation behavior
Key validation
- User YAML keys and override keys are validated against the default-schema tree from
src/configuration.yaml.example. - Unknown keys throw
ArgumentError. - Type/domain checks are applied while constructing typed config objects (for example Symbol allow-lists and positivity checks).
Alias handling
Some legacy aliases are accepted in constructors for migration convenience, but canonical docs and examples use structured section keys.
Caching
load_sparlectra_config(...) caches the typed result when loading from unchanged files without overrides. File hash/mtime changes invalidate cache reuse automatically.
Module consumption model
The central typed config is intended to be consumed by each module from its own section:
- Power flow: reads
config.powerflow(solver controls, start mode, Q-limit controls). - MATPOWER import: reads
config.matpowerand combines with PF/output/performance sections as needed by example/runner paths. - State estimation: reads
config.state_estimationfor method/tolerances/observability toggles. - Output/reporting: reads
config.outputandconfig.diagnostics. - Performance profiling: reads
config.performanceandconfig.benchmark. - Future modules: should add a dedicated typed section and canonical YAML subtree.
Minimal example YAML
power_flow:
method: rectangular
tol: 1.0e-5
max_iter: 80
autodamp: true
autodamp_min: 0.05
start_mode:
angle_mode: dc
voltage_mode: profile_blend
profile_source: matpower_reference
start_projection: true
try_dc_start: true
try_blend_scan: true
blend_lambdas: [0.25, 0.5, 0.75]
dc_angle_limit_deg: 60.0
start_current_iteration:
enabled: false
max_iter: 10
tol: 1.0e-3
damping: 0.5
accept_only_if_improved: true
min_improvement_factor: 0.98
vm_min_pu: 0.5
vm_max_pu: 1.5
max_angle_step_deg: 30.0
only_for_large_cases: false
qlimits:
enabled: true
enforcement_mode: active_set
start_iter: 3
start_mode: iteration_or_auto
matpower_import:
case: case14.m
# Non-empty cases take precedence for run_sparlectra_cases.
cases: [case14.m, case118.m]
auto_profile: recommend
auto_profile_log: true
pv_voltage_source: gen_vg
state_estimation:
enabled: true
method: wls
output:
console_summary: true
logfile_results: full
performance:
enabled: true
level: iteration
benchmark:
enabled: true
methods: [rectangular]
runtime:
julia_threads: keep
blas_threads: keep
casefile: ""
case_name: ""
case_source: ""
configured_default_casefile: ""
extensions:
reserved: truepower_flow.qlimits.enforcement_mode selects the reactive-limit algorithm. active_set preserves Sparlectra's existing in-iteration PV→PQ active-set behavior. classic_simultaneous and classic_one_at_a_time run a classical/reference-style outer loop: solve the base AC power flow first with Q-limit switching disabled, clamp violating generator Q to the violated limit only after a successful solve, convert affected voltage-controlled buses to PQ, and rerun without PQ→PV re-enable inside that enforcement loop. Legacy aliases matpower_simultaneous and matpower_one_at_a_time are still accepted for old YAML files and are normalized to the corresponding classic_* value.
matpower_import.auto_profile controls a MATPOWER pre-run profile. Use off to disable it, recommend to print/log a recommendation table without changing the active configuration, or apply to apply only unambiguous import-convention recommendations. The runner also logs final effective MATPOWER options; it never rewrites user YAML files.
For complete key references and allowed-value tables, see the module-specific pages below.
Wrong-branch detection semantics (rectangular PF)
power_flow.wrong_branch_detection is a post-convergence plausibility check for rectangular PF results. It is heuristic and does not prove global branch correctness.
off: checker disabled.warn: suspicious solutions are reported in rectangular status metadata; numerical convergence remains accepted.fail: suspicious solutions are treated as failed final convergence.rescue: reserved/request mode. If a suspicious solution is detected, status reportsrescue_requested_but_not_available; active retry/rescue loops are not implemented yet.
The thresholds include voltage magnitude range, global angle spread, and active-branch angle-difference checks via power_flow.wrong_branch_max_branch_angle_deg.
Where the result is visible
The check result — not just the setting — is surfaced in every output surface, so a suspicious solution is visible without reading console warnings:
ACPFlowReport.metadata(src/results.jl,buildACPFlowReport):wrong_branch_statusandwrong_branch_reason.- AC island diagnostics CSV (
ac_island_solver_summary.csv, one row per AC island): trailingwrong_branch_status/wrong_branch_reasoncolumns, alongside the existingwrong_branch_detectionsetting column. The matching per-islandac_island_<id>_solver.logalso lists both fields. - Console/log summary (
printACPFlowResults): a singlewrong-branch check: SUSPECT (...)orwrong-branch check: FAIL (...)line is printed only when the result is neitheroknornot_checked; clean runs andwrong_branch_detection = offprint nothing extra. - Web UI run result page: a
status-badge("Wrong-branch check" row) using the same success/warning/error styling as the run-status badge; omitted entirely when the result isnot_checked. run_sparlectra_apiresult metadata:wrong_branch_status,wrong_branch_reason,wrong_branch_low_vm_count,wrong_branch_high_vm_count,wrong_branch_angle_spread_deg,wrong_branch_branch_angle_violation_count.
status values: ok (checked, no finding), warn (suspicious but the numerical result was still accepted per wrong_branch_detection = warn), fail (suspicious and treated as non-convergence per wrong_branch_detection = fail), wrong_branch_rescue_not_implemented (the reserved rescue mode was requested; no retry loop runs — see below), or not_checked (wrong_branch_detection = off, or the check never ran, e.g. a non-finite solution short-circuits earlier reporting). reason values mirror the case listed above (none, low_voltage_magnitude, high_voltage_magnitude, angle_spread_exceeded, branch_angle_exceeded, nonfinite_voltage, disabled, rescue_requested_but_not_available).
Maintainer decision: the wrong-branch rescue retry loop is intentionally out of scope and will not be implemented as part of this detection work; wrong_branch_detection = rescue stays a reserved mode that reports wrong_branch_rescue_not_implemented rather than retrying. Detection with full output visibility (this section) plus the APSLF solver as an alternative start/solve path (see docs/src/external_solvers.md) are the supported mitigations for hard flat-start cases.
Control configuration (generic outer loop)
control:
enabled: true
max_outer_iterations: 20
trace: true
log_iterations: true
stop_on_pf_failure: true
controllers: []| Key | Type | Default | Meaning |
|---|---|---|---|
enabled | Bool | true | Enables the generic outer-loop control framework. |
max_outer_iterations | Int | 20 | Global outer-loop cap. Does not control inner NR iterations. |
trace | Bool | true | Collect machine-readable control trace rows. |
log_iterations | Bool | true | Enables optional per-iteration control logging hooks. |
stop_on_pf_failure | Bool | true | Stops control orchestration when inner PF fails. |
controllers | Vector | [] | Reserved for future YAML controller definitions; leave empty for current programmatic controller setup. |
In Stage 1, controllers are typically attached programmatically via addTapController! / addPowerTransformerControl!.
Demo controller YAML vs. central control.controllers
The tap-control demo may read examples/tap_control_demo_grid.yaml for example setpoints and transformer tap/phase parameters (oltc, pst, schraeg). This is an example-specific input file consumed by examples/tap_control_demo_grid.jl.
It does not define the central control.controllers schema. Today, control.controllers remains reserved/future and should be left as [] in central configuration files.
Migration notes
| Legacy / old key | Canonical key | Notes |
|---|---|---|
matpower_import.benchmark | benchmark.enabled | Removed from matpower_import; now top-level benchmark section. |
methods (top-level legacy path) | benchmark.methods | Keep benchmark methods in benchmark. |
max_ite | power_flow.max_iter | Legacy alias; prefer canonical nested key. |
Detailed references
- Power-Flow Configuration
- MATPOWER Import Configuration
- State-Estimation Configuration
- Performance and Profiling Configuration
Complete default-key index
The following canonical keys are currently present in src/configuration.yaml.example:
benchmarkbenchmark.enabledbenchmark.methodsbenchmark.samplesbenchmark.secondsbenchmark.show_oncebenchmark.show_once_max_nodesbenchmark.show_once_outputcontrolcontrol.controllerscontrol.enabledcontrol.log_iterationscontrol.max_outer_iterationscontrol.stop_on_pf_failurecontrol.tracediagnosticsdiagnostics.console_auto_profilediagnostics.console_diagnosticsdiagnostics.console_max_rowsdiagnostics.console_q_limit_eventsdiagnostics.console_summarydiagnostics.log_effective_configdiagnostics.logfile_diagnosticsextensionsextensions.reservedmatpower_exportmatpower_export.write_solutionmatpower_importmatpower_import.auto_profilematpower_import.auto_profile_logmatpower_import.bus_shunt_modelmatpower_import.casematpower_import.casesmatpower_import.compare_voltage_referencematpower_import.enable_pq_gen_controllersmatpower_import.preallocate_min_busesmatpower_import.preallocate_networkmatpower_import.pv_voltage_mismatch_tol_pumatpower_import.pv_voltage_sourcematpower_import.ratiomatpower_import.shift_signmatpower_import.shift_unitoutputoutput.console_auto_profileoutput.console_diagnosticsoutput.console_max_rowsoutput.console_q_limit_eventsoutput.console_summaryoutput.logfile_diagnosticsoutput.logfile_performanceoutput.logfile_resultsoutput.logfile_warningsoutput.result_table_large_case_modeoutput.result_table_large_case_threshold_busesoutput.result_table_max_rowsperformanceperformance.compact_loggingperformance.compare_cold_warmperformance.enabledperformance.levelperformance.max_diagnostic_rowsperformance.print_to_consoleperformance.representative_warmup_runsperformance.show_allocationsperformance.show_iteration_tableperformance.skip_branch_neighborhood_reportperformance.skip_expensive_diagnosticsperformance.skip_reference_comparisonperformance.write_to_logfilepower_flowpower_flow.autodamppower_flow.autodamp_minpower_flow.wrong_branch_detectionpower_flow.wrong_branch_rescuepower_flow.wrong_branch_min_vm_pupower_flow.wrong_branch_max_vm_pupower_flow.wrong_branch_max_angle_spread_degpower_flow.wrong_branch_max_branch_angle_degpower_flow.wrong_branch_min_low_vm_countpower_flow.wrong_branch_rescue_max_attemptspower_flow.flatstartpower_flow.max_iterpower_flow.meritpower_flow.merit.armijo_c1power_flow.merit.enabledpower_flow.merit.fallback_max_mismatchpower_flow.merit.scale_ppower_flow.merit.scale_qpower_flow.merit.scale_vpower_flow.trust_regionpower_flow.trust_region.enabledpower_flow.trust_region.initial_radiuspower_flow.trust_region.min_radiuspower_flow.trust_region.max_radiuspower_flow.trust_region.eta_acceptpower_flow.trust_region.shrink_factorpower_flow.trust_region.expand_factorpower_flow.trust_region.expand_thresholdpower_flow.trust_region.step_modepower_flow.methodpower_flow.qlimitspower_flow.qlimits.auto_q_delta_pupower_flow.qlimits.cooldown_iterspower_flow.qlimits.enabledpower_flow.qlimits.enforcement_modepower_flow.qlimits.guardpower_flow.qlimits.guard.accept_bounded_violationspower_flow.qlimits.guard.enabledpower_flow.qlimits.guard.freeze_after_repeated_switchingpower_flow.qlimits.guard.logpower_flow.qlimits.guard.max_remaining_violationspower_flow.qlimits.guard.max_switchespower_flow.qlimits.guard.min_q_range_pupower_flow.qlimits.guard.narrow_range_modepower_flow.qlimits.guard.violation_modepower_flow.qlimits.guard.violation_threshold_pupower_flow.qlimits.guard.zero_range_modepower_flow.qlimits.hysteresis_pupower_flow.qlimits.lock_pv_to_pq_busespower_flow.qlimits.start_iterpower_flow.qlimits.start_modepower_flow.qlimits.trace_busespower_flow.rectangular_preallocate_workspacepower_flow.rectangular_workspace_min_busespower_flow.rectangular_workspace_reusepower_flow.start_modepower_flow.start_mode.accept_unmeasured_dc_startpower_flow.start_mode.angle_modepower_flow.start_mode.blend_lambdaspower_flow.start_mode.branch_guardpower_flow.start_mode.dc_angle_limit_degpower_flow.start_mode.measure_candidatespower_flow.start_mode.profile_sourcepower_flow.start_mode.reuse_import_datapower_flow.start_mode.start_projectionpower_flow.start_mode.try_blend_scanpower_flow.start_mode.try_dc_startpower_flow.start_mode.voltage_modepower_flow.start_current_iterationpower_flow.start_current_iteration.accept_only_if_improvedpower_flow.start_current_iteration.dampingpower_flow.start_current_iteration.enabledpower_flow.start_current_iteration.max_angle_step_degpower_flow.start_current_iteration.max_iterpower_flow.start_current_iteration.min_improvement_factorpower_flow.start_current_iteration.only_for_large_casespower_flow.start_current_iteration.tolpower_flow.start_current_iteration.vm_max_pupower_flow.start_current_iteration.vm_min_pupower_flow.tolruntimeruntime.blas_threadsruntime.case_nameruntime.case_sourceruntime.casefileruntime.configured_default_casefileruntime.julia_threadsruntime.print_thread_configstate_estimationstate_estimation.enabledstate_estimation.flatstartstate_estimation.jac_epsstate_estimation.max_iterstate_estimation.methodstate_estimation.observabilitystate_estimation.observability.enabled-state_estimation.tolstate_estimation.update_nettransformertransformer.tap_changer_modelwebuiwebui.show_case_settings_notice