feat(api): unify results API; add backend selection and multiperiod/pyomo support#2
Merged
nathantgray merged 11 commits intodevelopfrom Jan 22, 2026
Merged
Conversation
- Extract _get_control_variable(), _warn_unsupported(), _add_time_column() to Backend base class - Implement BACKEND_FACTORY dictionary for backend instantiation - Add _check_results_available() helper to OpfResult for DRY validation - Remove unused import warnings from multiperiod_backend and pyomo_backend - Add BackendSelector for route_opf() delegation - Add CaseValidator for centralized validation - Add OpfResult wrapper for result DataFrames with plotting/export - All 154 tests passing with 0 regressions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature: API Improvements — Summary of Changes
Branch: feature/api-improvements
Compared against: origin/develop (head)
Overview
This feature unifies the results API and improves backend selection and multi-period support. The main goals were:
Key Changes
Added
PowerFlowResultdataclass (src/distopf/results.py) as the unified results container for PF/OPF/FBS.plot_*), save/export (save()), and summary (summary()) on the result object.Case API updates
Case.run_pf(),Case.run_opf(), andCase.run_fbs()now return aPowerFlowResult(optionallyraw_resultpreserved).Case._select_backend()helper (wrapper for backend auto-selection).Backend selection and backends
BackendSelector(src/distopf/backend_selector.py) implements auto-selection rules and routing.matrix(single-period, CVXPY/clarabel)multiperiod(time-series/battery support)pyomo(NLP/IPOPT)Multiperiod & Pyomo
tfor single-period to ensure consistent shapes).FBS (Forward-Backward Sweep)
run_fbs()anddistopf.fbsutilities for fast 3-phase radial power flows.examples/11_fbs_power_flow.pyadded demonstrating FBS and comparison withcase.run_pf().Examples & docs
examples/and consolidated example README intoexamples/README.md.MIGRATION.md(cleared by request).docs/FEATURE_API_IMPROVEMENTS_SUMMARY.md(this file).Tests
tests/test_results_api.py,tests/test_fbs_validation.py,tests/test_case_validation.py.Files of Note (selected)
New/Added
src/distopf/results.py(PowerFlowResult)src/distopf/backend_selector.pysrc/distopf/backends/*(backend implementations)src/distopf/api.py(formerlyimporter.py)examples/11_fbs_power_flow.pytests/test_results_api.py,tests/test_fbs_validation.pyModified
src/distopf/*(matrix and pyomo model integrations, fbs, plot interfaces)examples/*(added/normalized examples)tests/*(updated to new API)Removed
MIGRATION.mdcontents cleared (file removed from branch in final commit)src/distopf/result.py(replaced byresults.py)Migration Notes for Users
Minimal friction: the key change is that analysis methods return a
PowerFlowResultobject.result.voltages,result.p_flows,result.p_gens,result.q_gens.examples/).Caseno longer exposes result DataFrames as persistent properties; use the return value.How to run smoke checks
Run examples and tests locally:
uv run examples/11_fbs_power_flow.py uv run pytest tests/test_results_api.py -q uv run pytest -m "not slow"If you'd like, I can push the branch to the remote and/or open a PR draft with this summary as the PR description. Let me know which you prefer.