Revised vapor composition constraints fix ZeroDivisionError when gdp.hull reformulation is applied#47
Conversation
…hull reformulation is applied
|
As long as there are no errors, this PR is ready to be merged. @bernalde |
bernalde
left a comment
There was a problem hiding this comment.
Besides some small changes the most important part is verifying that both the Big-M and HR can provided the right solution to the problem and that the new introduced variables/constraints did not modify the optimal solution
| m.dHvap[comp] = dHvapb[comp] / m.Hscale | ||
|
|
||
| ## Heat capacity calculation for liquid and vapor phases using Ruczika-D method for each component in the feed, section, and tray | ||
| ## Heat capacity calculation for liquid and vapor phases for each component in the feed, section, and tray |
There was a problem hiding this comment.
Why remove the comment on the method? Is that method not used? If it is used, leave the comment and add a reference
There was a problem hiding this comment.
Addressed in a70395b by restoring the Ruczika-D method comments on the Kaibel heat-capacity and enthalpy calculations.
There was a problem hiding this comment.
Addressed in 90e289d. The method comments are kept, corrected to Ruzicka-Domalski, and the README now includes the source reference.
| m.prop[comp, 'TC'] / m.Tup, | ||
| m.prop[comp, 'TC'] / m.Tlo, | ||
| ), # (0, None), | ||
| initialize=lambda m, sec, tray, comp: m.T0[sec, tray] / m.Tlo, |
There was a problem hiding this comment.
I like this way of defining bounds and initializations!
There was a problem hiding this comment.
Addressed while handling the newer reduced-temperature issue in a70395b: m.Tr now initializes from TC / T0, with a regression test for initial values staying within bounds.
There was a problem hiding this comment.
Not applicable as a change request; this was informational. The reduced-temperature bounds and initializer remain, and tests/test_pr47_regressions.py now covers both bounds and algebra equivalence.
| m.prop[comp, 'TC'] | ||
| / m.T[1, n_tray] | ||
| m.Tr[1, n_tray, comp] | ||
| # m.prop[comp, 'TC'] |
There was a problem hiding this comment.
Why leave these lines here? If the code works, remove the comments as they become confusing
There was a problem hiding this comment.
Addressed in a70395b by removing the stale commented TC / T algebra from the vapor-composition expressions.
| ) | ||
| ) | ||
| / m.P[1, n_tray] | ||
| # / m.P[1, n_tray] |
There was a problem hiding this comment.
Remove comment as pressure multiplied in the other side of the equality
There was a problem hiding this comment.
Addressed in a70395b. The stale commented pressure-division lines were removed from the vapor-composition expressions.
| """ | ||
| return m.Tr[4, n_tray, comp] * m.T[4, n_tray] == m.prop[comp, 'TC'] | ||
|
|
||
| @disj.Constraint(m.comp, doc="Top scetion 4 vapor composition") |
f798d9d to
2838304
Compare
|
This should be resolved by Pyomo/pyomo#3880 |
bernalde
left a comment
There was a problem hiding this comment.
Blocking issues:
gdplib.hda.HDA_model()no longer constructs because the newm.gammascalar Param is overwritten by the existing indexed activity-coefficientm.gammaVar, and compressor/valve expressions then try to use that IndexedVar as a scalar heat-capacity ratio.- The new Kaibel
m.Trvariable is initialized inconsistently with its definition (TC / T), producing 381 out-of-boundsTrinitial values duringbuild_model()in the Pixi environment.
Nonblocking issues:
git diff --checkreports trailing whitespace on the added Kaibel lines, and the changed-file black check saysgdplib/kaibel/kaibel_solve_gdp.pywould be reformatted.
Questions:
- None.
Tests run and outcomes:
- Discovered commands from the PR branch README/CI and current repo conventions. The PR worktree has no
tests/,pyproject.toml, or Pixi manifest, so I used/home/bernalde/repos/gdplib/pixi.tomlwith cwd/tmp/gdplib-pr47to run PR code on Python 3.12.13 / Pyomo 6.10.0. /home/bernalde/.pixi/bin/pixi run --manifest-path /home/bernalde/repos/gdplib/pixi.toml --frozen python -m pytest tests/ -v --tb=short: failed becausetests/does not exist in the PR branch.- Kaibel build/initializer check: failed the new
Trconsistency check; 381Trvalues are outside bounds. - Kaibel
TransformationFactory('gdp.hull').apply_to(m): passed (hull ok). - HDA
HDA_model()construction: failed withTypeError: unsupported operand type(s) for -: 'IndexedVar' and 'float'atm.gamma - 1.0. black -S -C --target-version py310 --check --diff gdplib/kaibel/kaibel_solve_gdp.py gdplib/hda/HDA_GDP_gdpopt.py: failed; Kaibel would be reformatted.flake8 gdplib/ --count --select=E9,F63,F7,F82 --show-source --statistics: passed (0).typos --config ./.github/workflows/typos.toml: failed on existing repository typos, including old Kaibelscetionstrings.git diff --check origin/kaibel...HEAD: failed on trailing whitespace in added Kaibel lines.
The PR should not be merged as-is. I would not merge this until the blocking issues above are addressed.
| m.alpha = Param(initialize=0.3665, doc="compressor coefficient") | ||
| m.compeff = Param(initialize=0.750, doc="compressor efficiency") | ||
| m.gam = Param(initialize=1.300, doc="ratio of cp to cv") | ||
| m.gamma = Param(initialize=1.300, doc="ratio of cp to cv") |
There was a problem hiding this comment.
Blocking: This rename collides with the existing m.gamma = Var(m.abs, m.compon, ...) later in HDA_model(). Pyomo replaces this scalar Param with the IndexedVar, and HDA_model() now fails during construction in build_compressor() with TypeError: unsupported operand type(s) for -: 'IndexedVar' and 'float' when evaluating m.gamma - 1.0. This HDA change is unrelated to the Kaibel hull fix. Please restore m.gam for the heat-capacity ratio, or choose a non-conflicting name and update all scalar references without overwriting the activity-coefficient m.gamma variable.
There was a problem hiding this comment.
Addressed in a70395b by renaming the HDA scalar to m.heat_capacity_ratio and updating the dependent equations. tests/test_pr47_regressions.py now checks that m.gamma remains indexed.
There was a problem hiding this comment.
Addressed in 90e289d. The heat-capacity ratio is back to m.gam; the existing indexed activity-coefficient m.gamma is no longer overwritten, and the regression covers both.
| m.prop[comp, 'TC'] / m.Tup, | ||
| m.prop[comp, 'TC'] / m.Tlo, | ||
| ), # (0, None), | ||
| initialize=lambda m, sec, tray, comp: m.T0[sec, tray] / m.Tlo, |
There was a problem hiding this comment.
Blocking: m.Tr represents TC / T because the new reduced-temperature constraints enforce m.Tr[...] * m.T[...] == m.prop[comp, 'TC'], but this initializer uses T0 / Tlo. In the Pixi environment this leaves 381 Tr entries outside their own bounds and emits W1002 warnings during build_model(), giving solvers a bad initial point for the newly added reformulation variable. Initialize with m.prop[comp, 'TC'] / m.T0[sec, tray] or another value consistent with the bounds, and add a regression check that builds Kaibel and applies TransformationFactory('gdp.hull').
There was a problem hiding this comment.
Addressed in a70395b by changing the Kaibel m.Tr initializer to TC / T0. The new regression tests cover Tr bounds and both gdp.hull and gdp.bigm transformation construction.
|
Pushed commit:
Main changes:
Tests run:
Comments intentionally not addressed:
Remaining risks/follow-up:
|
bernalde
left a comment
There was a problem hiding this comment.
Blocking issues:
HDA_model()no longer exposes the existingm.gamscalar component; the fix should avoid them.gammacollision without renaming the pre-existing HDA component.- The Kaibel regression coverage still only proves that Big-M and Hull transform. The PR rewrites the vapor-composition algebra and adds
m.Tr, so it still needs semantic equivalence or solve evidence for the changed model behavior.
Nonblocking issues:
- The PR diff still fails
git diff --check origin/kaibel...HEADbecause several touched Kaibel files contain trailing whitespace or CRLF artifacts. - The restored Ruczika-D method comments still do not include a reference.
Questions:
- None.
Tests run and outcomes:
- Discovered commands from
README.mdandsetup.py; this PR branch has nopyproject.toml, Pixi manifest, Makefile, package.json, or workflow files. I used the repository Pixi environment from/home/bernalde/repos/gdplib/pixi.tomland forcedPYTHONPATH=/tmp/gdplib-pr47because that shared.venvis editable-installed against the main checkout. env PYTHONPATH=/tmp/gdplib-pr47 PYTHONDONTWRITEBYTECODE=1 /home/bernalde/.pixi/bin/pixi run --manifest-path /home/bernalde/repos/gdplib/pixi.toml --frozen pytest tests/ -v --tb=short -p no:cacheprovider: passed, 7 tests./home/bernalde/.pixi/bin/pixi run --manifest-path /home/bernalde/repos/gdplib/pixi.toml --frozen black -S -C --target-version py310 --check --diff .: passed./home/bernalde/.pixi/bin/pixi run --manifest-path /home/bernalde/repos/gdplib/pixi.toml --frozen flake8 gdplib/ --count --select=E9,F63,F7,F82 --show-source --statistics: passed./home/bernalde/.pixi/bin/pixi run --manifest-path /home/bernalde/repos/gdplib/pixi.toml --frozen typos --config ./.github/workflows/typos.toml: passed.git diff --check origin/kaibel...HEAD: failed on trailing whitespace in touched Kaibel files.- GitHub
lint/style-and-typos: passed.
The PR should not be merged as-is. I would not merge this until the blocking issues above are addressed.
| m.alpha = Param(initialize=0.3665, doc="compressor coefficient") | ||
| m.compeff = Param(initialize=0.750, doc="compressor efficiency") | ||
| m.gam = Param(initialize=1.300, doc="ratio of cp to cv") | ||
| m.heat_capacity_ratio = Param(initialize=1.300, doc="ratio of cp to cv") |
There was a problem hiding this comment.
Blocking: This removes the existing m.gam scalar component from HDA_model() and replaces it with m.heat_capacity_ratio. That avoids the m.gamma collision, but it also breaks existing HDA scripts that access the pre-existing heat-capacity ratio as model.gam, and this PR is otherwise about Kaibel. Please preserve the existing component name (m.gam) and use it in the compressor/valve expressions, while keeping the indexed activity-coefficient variable as m.gamma; update the regression to assert that model.gam still exists and model.gamma remains indexed.
There was a problem hiding this comment.
Addressed in 90e289d. m.gam is restored in HDA_model(), compressor/valve references use it again, and the regression now asserts model.gam remains available while model.gamma remains indexed.
| | | | | | | | ||
| -------> D -------> C -------> B | ||
| Figure 2. Sequence of columns for the separation of a quaternary mixture | ||
| Calculation of the theoretical minimum number of trays and initial |
There was a problem hiding this comment.
Nonblocking: The current PR diff still fails git diff --check origin/kaibel...HEAD; many touched Kaibel lines have trailing whitespace or CRLF artifacts. Please normalize the touched files to the repository line-ending style and remove trailing whitespace so the diff check is clean.
There was a problem hiding this comment.
Addressed in 90e289d. Normalized touched Kaibel line endings and trailing whitespace; git diff --check origin/kaibel...HEAD now passes.
| m.dHvap[comp] = dHvapb[comp] / m.Hscale | ||
|
|
||
| ## Heat capacity calculation for liquid and vapor phases using Ruczika-D method for each component in the feed, section, and tray | ||
| ## Heat capacity calculation using the Ruczika-D method for each component in the feed, section, and tray |
There was a problem hiding this comment.
Nonblocking: The Ruczika-D method comment is restored, but the requested reference is still missing. Please add a citation in this module or gdplib/kaibel/README.md so future maintainers can trace the property and enthalpy calculations.
There was a problem hiding this comment.
Addressed in 90e289d. Added the Ruzicka-Domalski reference to gdplib/kaibel/README.md and corrected the local method comments to use that name.
|
Pushed commit:
Main changes:
Tests run and results:
Comments intentionally not addressed:
Remaining risks or follow-up:
|
bernalde
left a comment
There was a problem hiding this comment.
Blocking issues: none.
Nonblocking issues: none requiring inline comments. Residual risk: this review does not add solver-backed optimality evidence for the Kaibel objective; prior bounded SCIP benchmark attempts timed out without a primal solution, so I am treating the algebra-equivalence and GDP transformation regressions as adequate for this targeted Hull failure fix.
Questions: none.
Tests run and outcomes:
- Targeted PR regressions: 11 passed.
- Broader test suite: 11 passed.
- Black check: passed.
- Critical flake8 check: passed.
- Typos check: passed.
- Full advisory flake8 ran with exit-zero and reported existing repository-wide style issues.
- GitHub lint/style-and-typos checks: passing.
This PR should be merged as-is.
This PR fix the ZeroDivisionError when gdp.hull reformulation is applied in the Kaibel instance.
File:
gdplib/kaibel/kaibel_solve_gdp.py