Examples Overview
This page summarizes the most relevant runnable examples in examples/.
Power flow and network operation
using_links.jlMinimal link workflow (open/close links) and resulting PF behavior.exp_synthetic_tiled_grid_pf_perf.jlSynthetic tiled-grid PF performance example.exp_configured_matpower_cases.jlRuns orderedmatpower_import.casesentries sequentially throughrun_sparlectra_cases.exp_transformer_loss_extension.jlDemonstrates Sparlectra's MATPOWER transformer-loss extension by exporting a small transformer case with active no-load conductance metadata and reimporting it without double-counting the equivalent bus shunts.exp_programmatic_api.jlRuns one MATPOWER case through the GUI-readyrun_sparlectra_apicontract and lists explicit artifacts.exp_current_iteration_start.jlDemonstrates enabling the guarded current-iteration start pre-solve through normal API configuration overrides and prints its metadata/artifact status.exp_powerflow_service.jlStarts a local service run, looks up its serialized result by run ID, and lists its artifacts without an HTTP server.exp_diagnose_self_check.jlRunsrun_fixed_reference_self_checkon a case with a deliberately mis-scaled branch reactance and prints the resulting narrativediagnose.logreport (worst-mismatch bus, mismatch trend, branch-anomaly scan, recommendations).
Transformer and tap control
exp_transformer_tap_changer_model.jlImports the same off-nominal-tap MATPOWER transformer once withtransformer.tap_changer_model = :idealand once with:impedance_correction, and compares the resulting series impedance and power-flow solution.exp_3wt_phase_taps.jlBuilds the same three-winding transformer withcreate3WTWindings!in three separate configurations, demonstrating thephase_tap_side/phase_tapskeywords (Issue #261): Case 1 OLTC only (ratio tap on the HV winding); Case 2 PST/Schrägregler only (asymmetricalPhaseTapChangerModelon the MV winding, no ratio tap anywhere); Case 3 (bonus) both combined on the HV winding (tap_side == phase_tap_side). Data-model only — resolving a phase-tap model into the AUX-bus branch and outer-loop control of a single 3WT winding are not wired yet.tap_control_demo_grid.jlLightweight three-controller demo (OLTC + PST + Schrägregler) usingrun_sparlectra(net = ...), central Sparlectra configuration (examples/configuration.yamlorSPARLECTRA_CONFIGURATION_YAML) plus demo-specificexamples/tap_control_demo_grid.yaml, andlatest_control_result(net)for controller rows and trace rows. Optional classic output:SPARLECTRA_TAP_DEMO_CLASSIC=1; optional raw control-result rows:SPARLECTRA_TAP_DEMO_RAW=1.
Voltage-dependent and Q-limit controls
example_voltage_dependent_control_rectangular.jlDemonstrates P(U)/Q(U) behavior with the rectangular solver workflow.example_q_limit_voltage_adjustment.jlShowsqlimit_mode = :adjust_vsetand related run variants.
Reporting and exports
export_solution.jlExports solved network data for downstream usage and writes outputs underexamples/_out/export_solution/....
DTF validation (Testnetz13 / FOR001-FOR002)
External FOR001/FOR002 validation datasets are not shipped with Sparlectra; place local files under data/DTF/ or pass explicit --dtf-file/--for002-file paths. See the tests page for the full mode/case reference.
validate_dtf_suite.jlUnified CLI runner for all DTF checks: import audit, native base-case validation against FOR002, DTF-listed outage validation, and the DTF -> existing MATPOWER export/import roundtrip. Select checks with--mode=all|audit|base|outages|matpowerand datasets with--case=A,B,.... The former single-purpose scriptsvalidate_dtf_for002_testnetz13.jl,validate_dtf_for002_outages_testnetz13.jl, andvalidate_dtf_matpower_export_testnetz13.jlwere consolidated into this suite; the shared implementations live inexamples/internal/dtf_validation_*.jl, each of which is also directly runnable as a single-purpose CLI entry point.dtf_validation_report.jlCross-case report over the local FOR001/FOR002 case set: transformer loss decomposition, voltage-transfer diagnostics, and transformer-ratio-mode comparisons, written as CSV/Markdown underexamples/_out/dtf_validation/.for002_matpower_metadata_validation.jlStandalone diagnostic for FOR002/MATPOWER metadata fixtures (bus/branch name normalization and comparison artifacts).
State estimation
state_estimation_wls.jlBaseline weighted least squares state estimation run.state_estimation_manual_measurements.jlManual measurement setup and estimation workflow.state_estimation_observability.jlObservability-focused scenario and diagnostics.state_estimation_passive_bus_zib_comparison.jlPassive-bus / ZIB handling comparison.usage_state_estimation_diagnostics.jlPractical diagnostics usage workflow.h_matrix_observability_demo.jlMatrix-level observability/redundancy exploration.
Monte-Carlo studies
mc_probabilistic_powerflow.jlProbabilistic power flow oncase14.m: N = 1000 Monte-Carlo samples scale all loads with a truncated-normal factor (Normal(1.0, 0.1), clipped to[0.5, 1.5], P and Q scaled together) and solve each sample withrunpf!. Reports per-bus mean/std and 5 %/95 % quantiles ofVm, counts of samples outside the[0.95, 1.05]pu band, and the convergence rate. Deterministic via a fixedMersenneTwisterseed; loads are scaled in place and restored after every sample (no network copies, no plotting dependencies).mc_state_estimation_study.jlWLS state-estimation error statistics on the 7-bus workshop network (see Workshop): M = 500 runs each generate a fresh noisy measurement set withsetMeasurementsFromPF!(run-specific RNG) and re-estimate the state withrunse!. Reports RMSE and maximum error ofVm/Vaagainst the reference power-flow state, convergence rate, and mean iteration count; checksevaluate_global_observabilityonce up front.
Utility / analysis scripts
matpower_import.jlConfigurable MATPOWER import utility script using the centralsrc/configuration.yaml.exampledefaults plus optionalexamples/configuration.yamllocal overrides. Supports logfile-only MATPOWER reference diagnostics, effective configuration logging, and configurable branchSHIFTsign/unit handling for phase-shifter convention checks. The YAML options can also diagnose and choose PV/REF voltage references when MATPOWERBUS.VMvalues differ from generatorGEN.VGsetpoints; usecompare_voltage_reference: imported_setpointto validate against the actual imported PV/REF setpoints, orcompare_voltage_reference: bus_vmto reproduce stored bus-matrix voltages strictly.matpower_import_multi_config.jlDeveloper diagnostic that runs one MATPOWER case through several configuration YAML files and compares the final rectangular PF status (auto-profile mode, wrong-branch detection, solver start settings).qlimit_large_case_mode_comparison.jlManual Q-limit comparison workflow over optional large MATPOWER cases (case × start_profile × qlimit_mode); excluded from normal test profiles.network_analyzer.jlDeveloper/exploration script for network diagnostics and inspection helpers.
How to run
From repository root:
julia --project=. examples/tap_control_demo_grid.jlGeneral pattern:
julia --project=. examples/<example_name>.jl