Fix semibatch reactor energy flow term#102
Conversation
6626194 to
f8dad35
Compare
parkyr
left a comment
There was a problem hiding this comment.
Maintainer review — Fix semibatch reactor energy flow term (#102, closes #87)
Reviewed head f8dad35 against base 1c3a046. The fix is correct, minimal, and well-scoped. Posting as COMMENT because I authored this PR (GitHub rejects an author APPROVE).
Correctness — verified
The change branches the convective second-enthalpy term on 'vol' in self.states_uo, weighting h_temp by inlet composition for the semibatch (no outlet stream) and keeping holdup composition for the CSTR outflow. I independently confirmed:
SemibatchReactor.nomenclatureis the only path that appends'vol'tostates_uo, and it runs during__init__(viaCSTR.__init__ → self.nomenclature()), so the guard isTruefor a semibatch andFalsefor CSTR/Batch/PFR both at construction and in the real solve. The fix also reuses the exact idiom already present atReactors.py:1084.- Regression tests are not vacuous: run against true base source (
1c3a046),test_semibatch_flow_term_...fails with-1.037e7 ≠ 0and passes on head;test_cstr_flow_term_keeps_holdup_composition_for_outflowasserts-1.037e7and passes on both base and head, so it locks in "no CSTR regression" (issue #87 acceptance criterion #3).
Tests run locally (env pharmapy, assimulo present)
tests/test_reactors_energy.py— 2 passed (head); semibatch case fails on base as expected.pytest tests/ -m "not assimulo"— 29 passed, 6 deselected.test_SB_BC_FILT(assimulo integration) — passed.- CI on this head: Core tests SUCCESS, Assimulo integration tests SUCCESS.
Warnings observed are pre-existing invalid-escape DeprecationWarnings in unrelated modules; not introduced here.
Nonblocking
Nonblocking: The integration test test_SB_BC_FILT still only asserts the solve completes (no assertion on the corrected temperature trajectory), so the full-solve path would not catch a future regression of this term — the new algebra tests are what guard it. Consider adding a lightweight assertion there (e.g. an energy-balance/temperature check or a golden trace) so the integration path also protects the fix. The unit-level coverage already makes this optional.
Nonblocking: tests/test_reactors_energy.py stubs assimulo and rewrites sys.path/sys.modules (_prefer_source_package, _stub_assimulo_modules) so the algebra test can import PharmaPy.Reactors in the no-assimulo Core job. This is justified (the top-level from assimulo... import would otherwise fail), but it diverges from the repo's existing pattern of guarding the import behind if HAS_ASSIMULO: (see tests/integration/reactor_tests.py). Fine to keep; noting for consistency.
Merge readiness
No blocking findings. mergeStateStatus is CLEAN and reviewDecision is empty (no required-review gate reported by branch protection). This COMMENT does not constitute a formal approval, and this account cannot self-approve its own PR; if an approval is required before merge, an eligible maintainer account will need to submit it.
|
Adding a quick note to connect this test workaround with the PR body's Related Issues / Priority section. The Assimulo monkeypatch in this test is temporary glue, not the desired long-term design. Right now, That broader problem is already tracked in #10, which proposes lazy solver imports plus a solver interface / SciPy fallback. I think #10 should be prioritized before broad solver-adjacent test expansion or larger unit-operation refactors, because it would remove the need for import-time stubs in core tests. That said, #10 does not need to block this PR. This PR is a focused correctness fix for #87, and the workaround is only here so the regression test can run under the current package structure. Related roadmap context: #3 is the broader CI / engineering baseline umbrella, #7 covers test expansion, and #8 covers packaging / dependency cleanup. |
bernalde
left a comment
There was a problem hiding this comment.
An issue should be created and some commented units should be standarized
| h_temp = (mole_conc * h_tempj).sum(axis=1) * 1000 # J/m**3 | ||
|
|
||
| if 'vol' in self.states_uo: # Semibatch: no outlet enthalpy stream | ||
| h_temp = (inlet_conc * h_tempj).sum(axis=1) * 1000 # J/m**3 |
There was a problem hiding this comment.
Let’s have this be the chance that if we are adding units in the comments, we switch them to [unit] with the same units than the package pint. I would suggest, let’s open an issue for this but also while adding new code, let’s start pushing for this standard
|
Answering to the last comment, the order of the merging would affect the work here. We can merge this now, but once #10 is tackled we would need to come and revisit this code to fix it. Otherwise, we merge the solution to #10 and from there we resolve the merge conflicts here. Do as you wish, but just let me (and GitHub) know |
Summary
volstate.Closes #87.
Related Issues / Priority
Tests
conda run -n pharmapy python -m pytest tests/test_reactors_energy.py -qconda run -n pharmapy python -m pytest --collect-onlyconda run -n pharmapy python -m pytest tests/ -m "not assimulo"timeout 180s conda run -n pharmapy python -m pytest tests/Flowsheet/flowsheet_tests.py::TestFlowsheets::test_SB_BC_FILT -qtimeout 180s conda run -n pharmapy python -m pytest tests/ -m assimulo -qgit -c core.whitespace=blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol diff --check --cachedNotes: pytest emitted existing invalid-escape deprecation warnings in several modules and one existing runtime warning in the PFR flowsheet test.
Branch Hygiene
masterfix/issue-87-semibatch-energyorigin/masterat1c3a046fceb5c4da8b5fdb6e8b254f657d6e3cc7origin/masterincludesupstream/masterat400e1e13ad4ecd3ba202d5fae8c70ec73bdf9c3e