Skip to content

PR 3/7: Pyomo utilities and single-step optimization#8

Open
bernalde wants to merge 1 commit intopr/pyomo-dependenciesfrom
pr/pyomo-utils-singlestep
Open

PR 3/7: Pyomo utilities and single-step optimization#8
bernalde wants to merge 1 commit intopr/pyomo-dependenciesfrom
pr/pyomo-utils-singlestep

Conversation

@bernalde
Copy link
Member

@bernalde bernalde commented Mar 3, 2026

Summary

Core Pyomo building blocks. utils.py provides parameter conversion from LyoPRONTO dicts to Pyomo-compatible formats, variable bound defaults, and warmstart helpers. single_step.py implements a single time-step steady-state optimization (one NLP solve per step), mirroring the scipy optimizer's step-by-step approach.

PR 3 of 7 in the Pyomo integration series.

Changes

  • lyopronto/pyomo_models/utils.py — Shared utilities (variable bounds, parameter loading, warmstart)
  • lyopronto/pyomo_models/single_step.py — Single time-step Pyomo model
  • tests/test_pyomo_models/test_model_single_step.py — 307 lines of tests
  • tests/test_pyomo_models/README.md — Test documentation

Key Design Decisions

  • Variable bounds: Pch (0.05–0.5 Torr), Tsh (-50–50°C), Tsub (-60–0°C)
  • Log-transform: Vapor pressure uses log form to avoid numerical issues with exp()
  • Warmstart: Scipy solution used to initialize Pyomo variables

PR Chain

# PR Status
0 Sync upstream (#5) Merged
1 CI/CD for Pyomo (#6) Open
2 Pyomo dependencies (#7) Open
3 Utils & single-step (this PR)
4 Multi-period model Pending
5 Optimizer functions Pending
6 Benchmarks Pending
7 Docs & examples Pending

Testing

~307 lines of new tests covering single-step model creation, solving, and parameter validation.

@bernalde bernalde force-pushed the pr/pyomo-utils-singlestep branch from fa26a34 to 65fc2c3 Compare March 3, 2026 00:51
@bernalde bernalde force-pushed the pr/pyomo-dependencies branch 2 times, most recently from 6fa03b3 to 58d26cd Compare March 3, 2026 01:09
@bernalde bernalde force-pushed the pr/pyomo-utils-singlestep branch from 65fc2c3 to b8a82c3 Compare March 3, 2026 01:09
bernalde added a commit that referenced this pull request Mar 3, 2026
pytest -m 'pyomo' exits with code 5 when no pyomo-marked tests exist.
This is expected until PR #8 adds the first pyomo tests. Treat exit
code 5 as success so the Pyomo Tests job passes gracefully.
@bernalde bernalde force-pushed the pr/pyomo-dependencies branch from 58d26cd to 72e8b86 Compare March 3, 2026 01:29
@bernalde bernalde force-pushed the pr/pyomo-utils-singlestep branch from b8a82c3 to 53ad6d9 Compare March 3, 2026 01:29
This PR adds the foundational Pyomo modules:

lyopronto/pyomo_models/utils.py (254 lines):
- Warmstart utilities for initializing from scipy solutions
- Variable scaling functions for numerical stability
- Validation helpers for checking physical constraints
- Result extraction and formatting utilities

lyopronto/pyomo_models/single_step.py (427 lines):
- Single time-point optimization formulation
- Direct Pyomo model for one drying step
- Basis for multi-period trajectory optimization
- Physics constraints as Pyomo constraints

Tests:
- tests/test_pyomo_models/test_model_single_step.py
- tests/test_pyomo_models/README.md

These utilities are used by the multi-period model (PR 4)
and the optimizer functions (PR 5).
@bernalde bernalde force-pushed the pr/pyomo-dependencies branch from 72e8b86 to 9b54119 Compare March 3, 2026 18:07
@bernalde bernalde force-pushed the pr/pyomo-utils-singlestep branch from 53ad6d9 to 389c49e Compare March 3, 2026 18:07
bernalde added a commit that referenced this pull request Mar 16, 2026
Source fixes:
- calc_knownRp.py: use constant.Torr_to_mTorr instead of literal 1000.0
  in early-return path, with regression test

Test fixes:
- Fix percent-dried scale bug: 0.99 -> 99.0 across test_regression.py (5),
  test_optimizer.py (1), test_opt_Pch_Tsh_coverage.py (2+2),
  test_opt_Pch_coverage.py (2)
- test_coverage_gaps.py: remove duplicate TestIneqConstraints class
- test_functions.py: add value assertions to TestIneqConstraints
- test_regression.py: skip column 0 (time) in stability test
- test_calculators.py: add meaningful assertion in
  test_higher_pressure_dries_faster
- test_web_interface.py, test_calc_unknownRp_coverage.py: use
  reference_data_path fixture instead of relative paths
- test_calc_knownRp.py: add regression test for mTorr conversion

Config fixes:
- pyproject.toml: remove duplicate [tool.pytest.ini_options] (pytest.ini
  takes precedence)
- pytest.ini: update minversion from 3.8 to 7.4
- requirements-dev.txt: add pytest-mock (matches pyproject.toml [dev])

CI fixes:
- pr-tests.yml, tests.yml, slow-tests.yml: consolidate triple pip install
  into single pip install -e ".[dev]"
- Remove hardcoded PR #8 reference from pyomo fallback messages

Script fixes:
- run_local_ci.sh: remove emojis, replace grep -oP with portable -oE,
  remove set -e/dead-code if-block, remove hardcoded -n 8, use
  pip install -e ".[dev]"

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant