Add grid model: event-constrained power flow on IEEE 14-bus#101
Conversation
bernalde
left a comment
There was a problem hiding this comment.
Blocking issues:
build_model()resets NumPy's process-global RNG.- The new grid model only has generic smoke coverage; it needs grid-specific tests for the public behavior and transformation path.
Nonblocking issues:
gdplib/grid/grid.pydoes not pass the repo Black check.- The branch currently conflicts with
mainafter #98 addedmultiperiod_blending; rebase/merge main and keep both modules in the import and test lists. - Consider tightening validation for integer parameters and
num_samples > 0.
Questions:
None.
Tests run and outcomes:
pytest tests/test_module_imports.py::TestModuleImports::test_build_model_callable[grid] tests/test_comprehensive_coverage.py::TestComprehensiveCoverage::test_model_construction_and_execution[grid] tests/test_model_structure.py::TestModelStructure::test_build_model_has_docstring[grid] -v --tb=short: passed, 3 tests.python -c "from gdplib.grid import build_model; from pyomo.environ import TransformationFactory; m=build_model(num_samples=3); TransformationFactory('core.logical_to_linear').apply_to(m); TransformationFactory('gdp.bigm').apply_to(m)": passed.pytest tests/ -v --tb=short: passed, 212 passed, 1 skipped, 4 warnings, under local Python 3.13.5.black gdplib/grid/grid.py --check --diff -S -C: failed; Black would reformat the new file.flake8 gdplib/grid/grid.py --count --select=E9,F63,F7,F82 --show-source --statistics: passed.typos --config ./.github/workflows/typos.toml gdplib/grid/README.md gdplib/grid/grid.py: not run becausetyposis not installed locally.- Supported-version local pytest was attempted with Python 3.12, but that interpreter has neither
pytestnorpyomoinstalled here. GitHub Actions reports test-python-3.9, 3.10, 3.11, 3.12, coverage-report, and test-pip-installation passing; lint/style-and-typos failing at Black Formatting Check.
This PR should not be merged as-is. I would not merge this until the blocking issues above are addressed.
|
bernalde
left a comment
There was a problem hiding this comment.
Blocking issues:
- Runtime dependency metadata and the committed Pixi lock are inconsistent after adding
sympy. - The new model is not registered with the generated model-size reporting workflow.
Nonblocking issues:
- The PR introduces trailing whitespace/line-ending churn in
gdplib/kaibel/main_gdp.py. - Focused flake8 on the new grid files reports avoidable lint debt.
Questions:
None.
Tests run and outcomes:
pixi run --locked pytest tests/test_grid.py -v --tb=short: failed immediately withlock-file not up-to-date with the workspace.pixi run pytest tests/test_grid.py -v --tb=short: passed, 20 tests, after Pixi resolved the missing lock entries locally.pixi run test: passed, 313 passed, 1 skipped, after Pixi resolved the missing lock entries locally.pixi run lint: passed.git diff --check origin/main...HEAD: failed on trailing whitespace ingdplib/kaibel/main_gdp.py.pixi run flake8 gdplib/grid tests/test_grid.py --max-complexity=10 --max-line-length=88 --statistics: failed on unused imports, long lines, ambiguousl, and complexity.- Small solve smoke test with
build_model(num_samples=5),core.logical_to_linear,gdp.bigm, and GLPK: optimal, objective 0.0.
This PR should not be merged as-is. I would not merge this until the blocking issues above are addressed.
|
Addressed the blocking and nonblocking items from the latest review:
|
…etwork Adds a GDP model for capacity expansion of the IEEE 14-bus power network under stochastic nodal demands. Uses ATLEAST logic to enforce an event constraint (alpha=0.9 via SAA) requiring a minimum number of generators and lines to simultaneously satisfy capacity bounds across sampled scenarios. Reference: Ovalle et al. (2025). Event constrained programming. Computers & Chemical Engineering, 199, 109145. https://doi.org/10.1016/j.compchemeng.2025.109145
- Add sympy>=1.0 to pixi.toml, setup.py; regenerate pixi.lock so pixi run --locked works correctly - Register grid in generate_model_size_report.py, generate gdplib/grid/model_size_report.md, update root README.md size table - Remove unused imports (Constraint, Disjunction in grid.py; Disjunct in test_grid.py); rename ambiguous loop variable l -> ln
|
Pushed Main changes made:
Tests and checks run:
Comments intentionally not addressed:
Remaining risks or follow-up:
|
bernalde
left a comment
There was a problem hiding this comment.
Fresh maintainer review at f490890.
I do not see remaining blocking or nonblocking issues in the current diff. The previous review comments appear adequately addressed: RNG isolation, grid-specific tests, parameter validation, dependency and Pixi lock alignment, generated model-size reporting, whitespace cleanup, and focused grid lint cleanup are all in place.
Verification:
- Inspected the current PR diff, commits since the prior reviews, generated docs, dependency manifests, tests, and surrounding registration code.
- GitHub Actions on
f490890are all passing. git diff --check origin/main...HEAD: passed.pixi run --locked pytest tests/test_grid.py tests/test_generate_model_size_report.py -v --tb=short: 26 passed.pixi run --locked flake8 gdplib/grid tests/test_grid.py --max-complexity=10 --max-line-length=88 --statistics: passed.- Focused model-size check for
gdplib.grid.build_model()matched the committed report values. - Small transformed GLPK smoke test with
num_samples=5: optimal, objective0.0.
Residual risk: no solver-backed default optimality evidence for the full benchmark instance was added, which is appropriate for this repository because optional solvers should stay out of default CI.
Summary
This PR adds a new GDP benchmark model for event-constrained optimal power flow on the IEEE 14-bus network.
Model description
The model minimizes the total capacity slack added to generators and transmission lines so that power balance constraints are satisfied across a set of Monte Carlo load scenarios (default: 500 samples drawn from a multivariate normal distribution).
Rather than requiring all equipment to stay within limits in every scenario (a joint chance constraint), an event constraint with ATLEAST logic requires that at least
active_gensgenerators andactive_linestransmission lines simultaneously satisfy their capacity bounds. This event must hold in at least 90% of scenarios (\alpha = 0.9), approximated via Sample Average Approximation.The GDP formulation encodes whether each capacity constraint is satisfied or violated per scenario using disjunctions, and connects them to a per-scenario Boolean event variable via a logical equivalence (
equivalent+land+atleast).Reference
Problem size (default:
active_gens=4,active_lines=20,num_samples=500)Changes
gdplib/grid/grid.py— new model withbuild_model(active_gens=4, active_lines=20, num_samples=500)gdplib/grid/__init__.py— exposesbuild_modelfollowing library conventionsgdplib/grid/README.md— model documentation with problem description, reference, and size tablegdplib/__init__.py— registersgdplib.gridtests/test_comprehensive_coverage.py,tests/test_model_structure.py,tests/test_module_imports.py— added"grid"to the manual module lists