Performance and Profiling Configuration

Runtime

Process-level settings read once at startup: the thread report, the Julia and BLAS thread counts, and the parallel work split of the sweeps.

YAML pathTypeDefaultAllowed valuesMeaning
runtime.print_thread_configBooltruetrue, falsePrint the Julia/BLAS thread summary at startup, including the parallel: enabled=... max_tasks=... line.
runtime.julia_threadsStringkeepkeep, default, off, auto, or integer-like stringJulia thread policy for runner setup. Requires process startup (--threads) or script re-exec.
runtime.blas_threadsStringkeepkeep, default, off, auto, or integer-like stringBLAS thread policy for runner setup; can be applied at runtime.
runtime.parallel.enabledBooltruetrue, falseMaster switch for in-process parallel execution of independent work items (island solves, short-circuit sweeps, contingency batches). false forces every parallel site onto its serial path (the same functions, not copies).
runtime.parallel.max_tasksStringautoauto or positive integer stringTask cap for parallel sites. auto resolves to Threads.nthreads(); the cap is applied via chunking, so it also bounds @threads sites.
runtime.parallel.min_work_itemsInt4integer >= 1Work lists shorter than this run serially.
runtime.parallel.executorStringautoauto, threads, processesHow N-1, scenario and injection batches run: on Julia threads, in the worker processes of the batch pool, or auto (processes from 2000 buses on, threads below). See Parallel Execution.
runtime.parallel.max_processesStringautoauto or positive integer stringCap of the worker processes of the batch pool. auto resolves to Sys.CPU_THREADS, fewer when the free memory holds fewer workers of the size of the network.
runtime.gc_pause.enabledBooltruetrue, falseThe garbage collector is off while a power flow runs and on again when the last run of the process ends.
runtime.gc_pause.max_resident_gbStringautoauto, a number >= 0Memory guard of the GC pause: above this resident size the guard collects once. auto is half of the physical memory, 0 no guard. A worker process of the batch pool gets its share of the limit.

In a single-threaded Julia process the parallel sites run serially even with runtime.parallel.enabled: true; the startup summary then hints at julia --threads=auto. Per-phase timings in the performance profile and performance.log are CPU-time sums over all islands and workers; the elapsed time of a fan-out is accounted separately as parallel_wall_time, and the ratio is the achieved speedup. What runs in parallel: Parallel Execution.

Julia thread priority for examples/powerflow/matpower_import.jl: the CLI override --julia-threads=<N|auto|keep>, then the environment variable SPARLECTRA_JULIA_THREADS, then YAML runtime.julia_threads, else the current process setting.

julia --threads=8 --project=. examples/powerflow/matpower_import.jl
julia --project=. examples/powerflow/matpower_import.jl --julia-threads=8
$env:JULIA_NUM_THREADS = "8"
julia --project=. examples/powerflow/matpower_import.jl

APSLF against Newton: solve times

examples/others/apslf_vs_nr_timing.jl solves the shipped sp_ cases and synthetic tiled grids (500 to 5000 buses, SPARLECTRA_TIMING_SIZES) with the rectangular Newton solver and with APSLF at orders 24, 40 and 60 (higher orders from 300 buses on, SPARLECTRA_TIMING_ORDERS), median of three warm runs, convergence-radius evaluation off. It writes apslf_vs_nr_timing.csv and apslf_vs_nr_timing.svg into results/apslf_vs_nr_timing/; below: Linux, Julia 1.13.0, 16 threads.

On pure-PQ grids (the tiled grids) the series solve is faster than Newton from 500 buses on, with cost about linear in the order; cases with PV buses and reactive limits (the sp_ cases) need outer passes and are Newton's ground. A network with controllers solves under APSLF with the controllers left out (one warning names them); for controllers use the APSLF start values ahead of the Newton solve (External Solver Interface).

APSLF against Newton, solve time over bus count

casebusesPV busessolverorderoutcomeit / passestime
sp_case993NR-converged50.3 ms
sp_case993APSLF24converged10.2 ms
sp_case11811854NR-converged62.3 ms
sp_case11811854APSLF24converged34.5 ms
sp_case30030069NR-converged77.4 ms
sp_case30030069APSLF24converged414.9 ms
sp_case30030069APSLF40converged421.9 ms
sp_case30030069APSLF60converged435.7 ms
sp_case13541354260NR-converged834.7 ms
sp_case13541354260APSLF24converged361.8 ms
sp_case13541354260APSLF40converged388.3 ms
sp_case13541354260APSLF60converged3129.4 ms
sp_case552NR-converged10.2 ms
sp_case552APSLF24converged10.2 ms
tiled_5005001NR-converged57.9 ms
tiled_5005001APSLF24converged16.1 ms
tiled_5005001APSLF40converged18.4 ms
tiled_5005001APSLF60converged114.3 ms
tiled_100010001NR-converged519.4 ms
tiled_100010001APSLF24converged113.3 ms
tiled_100010001APSLF40converged120.9 ms
tiled_100010001APSLF60converged140.4 ms
tiled_200020001NR-converged563.8 ms
tiled_200020001APSLF24converged156.9 ms
tiled_200020001APSLF40converged183.3 ms
tiled_200020001APSLF60converged1110.9 ms
tiled_500050001NR-converged5221.2 ms
tiled_500050001APSLF24converged1162.7 ms
tiled_500050001APSLF40converged1189.3 ms
tiled_500050001APSLF60converged1252.3 ms

Output configuration

What a run writes besides its result: the console summary and its diagnostics, the log files, and the detailed CSV export with its writer settings.

YAML pathTypeDefaultAllowed valuesMeaning
output.console_summaryBooltruetrue, falsePrint the compact run summary to the console.
output.console_auto_profileSymbol/Stringcompactoff, compact, fullMATPOWER auto-profile console detail.
output.console_diagnosticsSymbol/Stringcompactoff, compact, summary, fullDiagnostic detail on the console.
output.console_q_limit_eventsSymbol/Stringsummaryoff, summary, fullQ-limit/PV→PQ event console detail.
output.console_max_rowsInt100non-negative integerMax rows in compact console tables.
output.logfile_resultsSymbol/Stringoff (full in the packaged template)off, compact, classic, fullSolved result table detail in the logfile. A library run without a configuration file stays quiet; the template, which the Web UI and the services start from, logs the full table.
output.detailed_result_csv_write_modeSymbol/Stringautoauto, buffered, streamingDetailed CSV artifact write strategy; auto streams very large outputs.
output.detailed_result_csv_exporterSymbol/Stringautoauto, report, directDetailed CSV row-generation path; auto uses the direct streaming exporter for large bus counts.
output.detailed_result_csv_direct_threshold_busesInt10000positive integerBus count from which auto switches the detailed CSV export from report generation to direct streaming.
output.detailed_result_csv_buffer_initial_bytesInt8388608non-negative integerInitial size hint for buffered detailed CSV writing.
output.detailed_result_csv_buffer_max_bytesInt67108864positive integerEstimated size above which auto prefers streaming.
output.detailed_result_csv_streaming_threshold_rowsInt100000positive integerRow count above which auto prefers streaming.
output.logfile_diagnosticsSymbol/Stringcompactoff, compact, fullDiagnostic logfile detail.
output.logfile_performanceSymbol/Stringcompact (full in the packaged template)off, compact, fullPerformance profile logfile detail.
output.logfile_warningsSymbol/Stringtable (full in the packaged template)off, summary, table, fullWarning representation in the logfile.

The Jacobian cond. line (estimate plus verdict) is always part of the classic result output; a leftover output.condition_number key is ignored (Solver). For API and Web UI runs, classic writes the result output and a compact summary (solver_time, representative_time, iterations, final mismatch, outcome; benchmark median and samples only in benchmark mode); full adds a Full run details section with the effective typed configuration, artifact options and status diagnostics.

Diagnostics configuration

YAML pathTypeDefaultAllowed valuesMeaning
diagnostics.log_effective_configBoolfalsetrue, falseLog the merged effective configuration.

The former diagnostics.console_* and diagnostics.logfile_diagnostics keys are deprecated aliases of the output.* keys above and are ignored with a warning (Configuration).

Performance configuration

The defaults are those of the packaged template (src/config/configuration.yaml.example); a file that omits a key, and a library run without a configuration file, fall back to enabled: false, level: summary and show_iteration_table: false.

YAML pathTypeDefaultAllowed valuesMeaning
performance.enabledBooltruetrue, falseEnable performance instrumentation.
performance.levelSymbol/Stringiterationoff, summary, iteration, fullInstrumentation detail level.
performance.print_to_consoleBooltruetrue, falseEmit performance output to the console.
performance.write_to_logfileBooltruetrue, falseEmit performance output to the logfile.
performance.show_allocationsBoolfalsetrue, falseInclude allocation stats.
performance.show_iteration_tableBooltruetrue, falseShow the iteration-level timing table.
performance.compact_loggingBooltruetrue, falseCompact performance logging format.
performance.skip_reference_comparisonBoolfalsetrue, falseSkip voltage/reference comparisons for speed.
performance.skip_expensive_diagnosticsBooltruetrue, falseSkip high-cost diagnostics.
performance.skip_branch_neighborhood_reportBooltruetrue, falseSkip the branch neighborhood report.
performance.max_diagnostic_rowsInt25non-negative integerRow cap for diagnostics tables.

Power mode for repeated solves

Power mode is for the cases where one network is solved many times: a benchmark on a persistent model, the scenario engine, N-1 contingency sweeps, Monte Carlo, outer control loops. It is off by default; a single run gains nothing from it.

Switch it on with power_flow.power_mode: true in the configuration file (read by the service, the Web UI and run_sparlectra), or with the keyword power_mode = true on runpf! or runpf_rectangular! (runpf!(net, 30, 1e-8, 0; power_mode = true); the cache lives on the network, so every further solve of that net reuses it). Web UI: Settings page, Advanced options, fieldset Solver backend (shown for the Newton solver only, power_flow.solver: rectangular), tick Power mode and save; the N-1 and scenario runs of that case then use it. With the KLU extension (using KLU next to using Sparlectra; the application package loads it, so the service and the Web UI have it) power mode factorises with KLU, without it with UMFPACK and gains less; power_flow.power_mode_lu chooses between the two, see below.

Between solves the network keeps its Ybus (reused while the fingerprint of the branch admittances, terminals and shunts is unchanged), the symbolic analysis of the sparse LU with its factorization object and Jacobian buffers (re-analysed by itself when the Jacobian pattern changes, for example after a bus-type or a topology change; with the fixed Jacobian pattern a bus-type change keeps the UMFPACK analysis) and the Newton work arrays; the ranked mismatch diagnostics of the final status are skipped (the maxima and the worst row stay). Same Jacobian, same polar update, same Q-limit handling, same tolerance, the same solution to 1e-12 pu. reset_power_mode!(net) drops the kept state.

Measured warm solve (second and later solves on the same imported network, median of 20, single thread, flat start, Q limits off, the grid-bench adapter's keywords), without and with the switch, KLU loaded:

casewithoutwith power modefactorallocations per warm solve
case2869pegase47.3 ms7.8 ms6.035.7 MB to 5.7 MB
case9241pegase267.9 ms55.3 ms4.9141 MB to 21 MB
mvlv29840477.4 ms44.7 ms10.7407 MB to 60 MB

Without the KLU extension the same three items (persistent analysis, Ybus, diagnostics) give a factor of 1.2 on case2869pegase. Through the service API every call imports the case anew, so only the diagnostics and the faster LU apply: the solver phase gains a factor of 1.1 to 1.3 and the whole call 3 to 7 percent.

Power-mode LU: KLU or UMFPACK

KLU's numeric refactorization is 6 to 20 times faster than UMFPACK's on power-flow Jacobians of 5k to 60k unknowns. On very large Jacobians it is the other way round: KLU's partial pivoting takes thousands of off-diagonal pivots there, its factor grows well beyond the estimate of its analysis, and on the 82000-bus case_SyntheticUSA a power-mode run with KLU took more than twice as long as one without power mode. Neither backend is right for every network, so auto chooses per network:

power_flow.power_mode_lusparse LU of power mode
auto (default)KLU's symbolic analysis of the first power-mode Jacobian of a network (klu_analyze: block triangular form and AMD ordering, no numeric work) estimates the factorization flops; up to Sparlectra.POWER_MODE_LU_KLU_MAX_FLOPS (5e7) power mode factorizes with KLU, above it with UMFPACK; without the KLU extension always UMFPACK
kluKLU (UMFPACK with a warning when the extension is not loaded)
umfpackUMFPACK

The threshold is fitted on measured Jacobians: KLU refactorized faster on case2869pegase, case9241pegase, mvlv29840, caseACTIVSg2000, case13659pegase and the two small islands of caseSyntheticUSA (estimates 1.8e6 to 2.7e7 flops), UMFPACK on caseACTIVSg25k and the 70000-bus island of caseSyntheticUSA (1.3e8 and 5.6e8). The estimate cannot see KLU's numeric pivoting; it stands in for it through the size of the problem, so a network far from the measured ones may get the slower backend; klu or umfpack then fix the choice.

The choice is made once per network, at the first factorization of its first power-mode solve, and kept for every later solve of that network (outages, other bus types, other Ybus patterns, N-1 and scenario workers, which are copies of the solved base case). An island solved on its own decides for itself; an island an outage splits off takes the choice of its network. A newly imported network decides again, as does a network after reset_power_mode!(net). The decision costs one symbolic analysis, which KLU's factorization continues from when KLU wins. The solution is the same with every value.

The run log names the choice in the result header with the estimate, for example

Power-mode LU  : klu (KLU symbolic estimate 1.95e+06 flops, at most the threshold 5e+07; decided in this solve)

and the run metadata carries it as power_mode_lu_choice, power_mode_lu_source, power_mode_lu_klu_est_flops and power_mode_lu_threshold_flops (one row per island in power_mode_lu_islands). Web UI: the select Power-mode LU directly under the power-mode checkbox, greyed while power mode is off.

Dishonest Newton

power_flow.jacobian_reuse: true (keyword jacobian_reuse = true; Web UI: the checkbox "Dishonest Newton" under Solver backend, below power mode) keeps the Jacobian factorization for the next Newton step while the mismatch falls by at least jacobian_reuse_min_reduction (default 10) per step, at most jacobian_reuse_max_steps (default 3) steps in a row. Off by default; it changes the iteration count, not the solution, and works with and without power mode. The rules are on the Solver Guide.

useeffect of dishonest Newton
repeated solves of one large transmission case, power mode with KLUabout 7 percent faster
the same with UMFPACK (no KLU extension)12 to 15 percent faster
radial distribution gridsnone or slightly slower
N-1 and scenario runs (warm starts, few steps)slower (6 percent in the N-1 measurement below)
a single runno point: the factorization is not the bottleneck

A reused step converges linearly instead of quadratically: on the measured cases three reused steps replace two honest ones, so a run takes two more steps and one factorization less. That pays only where a factorization costs much more than the rest of a step: large meshed cases without KLU.

Measured warm solve as above (median of 20, single thread, one session, the grid-bench adapter's keywords), without and with the switch:

casepower mode, KLUwith dishonest Newtonpower mode, UMFPACKwith dishonest NewtonNewton steps (refactorisations)
case2869pegase7.5 ms7.0 ms30.1 ms25.4 ms5 (5) to 7 (4)
case9241pegase54.4 ms50.7 ms131.4 ms115.5 ms6 (6) to 8 (5)
mvlv2984044.1 ms45.4 ms203.2 ms173.5 ms5 (5) to 7 (4)

With KLU the gain is close to the cost of the extra steps, and on the radial mvlv29840 the extra steps cost more than the saved factorization; with UMFPACK the factorization is most of a step.

Not for N-1 and scenario runs: a warm-started outage solve converges in a few fast steps, and the switch adds steps per outage to save a factorization that KLU makes cheap. Full branch N-1 of case_ACTIVSg2000 (3206 outages):

variantwall time
serial343 s
parallel83 s
parallel, power mode70 s
parallel, power mode, dishonest Newton74 s

Measured with Sparlectra 0.30.2: runContingencies! on the outages of generateN1Branches, 16 threads for the parallel rows, KLU loaded, the four variants interleaved, median of three series each, after a warm-up of every variant (compile time not included); every variant gives the same per-outage results as the serial one.

Fixed Jacobian pattern

power_flow.jacobian_fixed_pattern (keyword jacobian_fixed_pattern; Web UI: "Fixed Jacobian pattern" under Solver backend) builds the Jacobian with the entries of both bus types: the second row of a PV bus keeps the slots of the Q derivatives as zeros, the second row of a PQ bus the slots of the voltage derivatives. A PV/PQ switch of the Q-limit handling then leaves the sparsity pattern unchanged, and umfpack_reuse keeps its LU analysis: one analysis per solve (per island) instead of one per switch, plus one after a fallback. In power mode the analysis also survives between solves whose bus types differ (N-1 with the warm active set, classic Q-limit passes). The values of the Jacobian and the solution are the same.

ValueKeywordEffect
auto (default):autoOn where the solve has a factorization to keep (umfpack_reuse, power mode) and the solved network (on the island path the island) has at least power_flow.jacobian_fixed_pattern_min_buses buses (default 5000); otherwise off without a message.
true:onOn whatever the size.
false:offOff: the pattern follows the bus types, every switch analyses anew.
  • The extra zeros make the LU factor of a small network a few percent larger; on large networks the size stays about the same while each switch saves an analysis. This is where the threshold of auto comes from.
  • linear_solver = umfpack keeps no factorization; the pattern is not used. With true the console (verbose) and run.log say that it is ignored.
  • KLU (power mode) refactorizes on its old pivot order, which can be wrong for a switched row, so it still factorizes afresh when the bus types differ from those of its last analysis. With KLU the pattern changes, not the number of analyses.

The solver status and the profile say what a solve did: jacobian_fixed_pattern (used or not), jacobian_fixed_pattern_mode (:auto, :on, :off as configured) and jacobian_fixed_pattern_reason (:auto_threshold, :auto_below_threshold, :on, :off, :no_context; :mixed over islands with different reasons). The status field jacobian_fixed_pattern_line is the text of the result header line Fixed pattern : in run.log, for example on (auto, 25000 buses, threshold 5000); the line is left out when the value is false. The analysis count is linear_solver_analyze_count.

Benchmark configuration

The Web UI's performance_timing=off|compact|full option writes performance.log with the phases of one service/API request (request parsing, case resolution, configuration, case loading, network construction, solve, postprocessing, artifact writing, total; full adds the internal profile entries). benchmark.enabled instead makes run_matpower_case repeat the solve and report representative and median timing; it is a scripting feature, a run through the service or the Web UI solves once, and the Web UI has no benchmark option. The repeated timing needs the package BenchmarkTools, which Sparlectra does not install: load it next to Sparlectra (using BenchmarkTools, after Pkg.add("BenchmarkTools") where it is missing); without it a run with benchmark.enabled: true stops before it reads the case and names the package.

YAML pathTypeDefaultAllowed valuesMeaning
benchmark.enabledBoolfalsetrue, falseEnable the benchmark mode of run_matpower_case (needs using BenchmarkTools).
benchmark.methodsVector{Symbol/String}[rectangular]rectangular (current PF core)Methods benchmarked.
benchmark.secondsFloat642.0positive realBenchmark time budget. Not a minimum runtime, solver timeout or iteration limit; a running sample is not interrupted.
benchmark.samplesInt30positive integerMax benchmark samples per method; the run ends at this count or at the time budget, whichever comes first.
benchmark.show_onceBoolfalsetrue, falseRun one full visible solve before the timing loop.
benchmark.show_once_outputSymbol/Stringclassicclassic, dataframe, compactOutput format for show_once.
benchmark.show_once_max_nodesInt0non-negative integerRow cap for the one-shot output.

Solver workspace and warmup keys

Performance-relevant keys outside the performance.* section:

KeyDefaultMeaning
power_flow.rectangular_workspace_reusetrueReuse the rectangular solver's workspace between solves of one session instead of reallocating.
power_flow.rectangular_preallocate_workspaceautoPreallocate the workspace up front (off, on, auto; auto decides by case size).
power_flow.rectangular_workspace_min_buses1000Case size from which auto preallocates.
performance.representative_warmup_runs0Untimed warmup solves before a timed representative run.
performance.compare_cold_warmfalseReport the cold (first) and warm (subsequent) timings side by side.