Skip to content

Fix kinetics custom params and equilibrium indexing#111

Merged
bernalde merged 1 commit into
masterfrom
fix/issue-71-kinetics-custom-equilibrium
Jul 14, 2026
Merged

Fix kinetics custom params and equilibrium indexing#111
bernalde merged 1 commit into
masterfrom
fix/issue-71-kinetics-custom-equilibrium

Conversation

@parkyr

@parkyr parkyr commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #71.

Triage / Acceptance Criteria

Uses the maintainer triage artifact at #71 (comment).

Covered:

  • Custom RxnKinetics(..., kinetic_model=fn, params_f=arr) constructs and stores the f-parameters.
  • Missing custom params_f still raises the intended RuntimeError.
  • Flat parameter-vector updates preserve custom params_f shape and update values.
  • Vectorized array-temperature equilibrium_model matches scalar per-time evaluation.
  • 2-D deltah_rxn from heat-of-reaction style inputs no longer goes through np.outer flattening.

Related Issues

Tests

  • Red first: .venv/bin/python -m pytest tests/test_kinetics_custom_and_equilibrium.py -v failed on unchanged base with the recorded custom-model UnboundLocalError and vectorized-equilibrium mismatch.
  • Green after fix: .venv/bin/python -m pytest tests/test_kinetics_custom_and_equilibrium.py -v
  • Green after fix: .venv/bin/python -m pytest tests/ -m "not assimulo" (38 passed, 8 deselected)
  • Green after fix: .venv/bin/python -m pytest --collect-only (46 tests collected)
  • Green after fix: git -c core.whitespace=cr-at-eol diff --check

Local environment: repository .venv with Python 3.11.15. The changed kinetics code is pure NumPy and does not require the assimulo backend.

Branch Hygiene

  • Base branch: master
  • Source branch: fix/issue-71-kinetics-custom-equilibrium
  • Branch point: origin/master at 1a3ab3155216f07e9a18c60687a7b6b1c5959202
  • upstream/master was fetched at 400e1e13ad4ecd3ba202d5fae8c70ec73bdf9c3e and is already an ancestor of origin/master.
  • Open PR overlap check found no same-file overlap for PharmaPy/Kinetics.py or tests/test_kinetics_custom_and_equilibrium.py.
  • No prerequisite or stacked PR.

@parkyr
parkyr marked this pull request as ready for review July 10, 2026 16:36

@parkyr parkyr left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer review — PR #111 (fix for #71)

Reviewed the diff against origin/master merge-base. The PR resolves both defects from the #71 triage artifact: the custom-kinetic_model construction crash in set_params and the array-temp equilibrium reverse-term indexing. The fix is broader than the minimal patch (handles the parameter-estimation round-trip and 2-D deltah_rxn), and the changes are internally consistent.

What I verified

  • Correctness of the fix path. set_params dict-branch else now assigns params_f/records params_f_shape for elem_flag=False; the flat-vector else restores it via reshape(self.params_f_shape); concat_params ravels custom params_f. The round-trip is coherent and the elem_flag=True path is untouched.
  • equil_term guards 2-D deltah_temp with inv_temp[:, None] * deltah/gas_ct instead of np.outer (which flattened), and equilibrium_model now selects keq_temp[:, ind] when keq_temp is 2-D (array temp) while keeping keq_temp[ind] for the scalar-temp/1-D case. Both indexing cases are correct.
  • Tests (local, repo .venv, Python 3.11.15):
    • pytest tests/test_kinetics_custom_and_equilibrium.py -v5 passed. The two equilibrium tests use the trusted scalar/1-D path as an implementation-independent oracle; the flat-update test genuinely exercises the concat_paramsset_params round-trip.
    • pytest tests/ -m "not assimulo"38 passed, 8 deselected.
    • pytest tests/ -m assimulo8 passed (reactor/flowsheet integration; no regression in the touched kinetics paths).
    • git -c core.whitespace=cr-at-eol diff --check → clean.
  • GitHub checks (head 1066d67): Core tests SUCCESS, Assimulo integration tests SUCCESS.
  • Closes #71 is the correct link — the PR fully resolves both defects in that issue.

Findings

Nonblocking — Custom-model coverage stops at construction and parameter plumbing; no test drives a user kinetic_model through an actual rate evaluation (e.g. in a reactor integration) to confirm the restored params_f produces correct rates end to end.

  • Why it matters: the regression suite proves the feature no longer crashes and that parameters round-trip, but not that the custom rate law is wired correctly downstream.
  • Concrete step: this is appropriately scoped for the #71 regression fix (an end-to-end custom-model reactor run needs the assimulo backend and is broader than the defect). Fine to defer; worth a follow-up issue if custom rate laws become a supported/documented path.

Summary

  • Blocking: none.
  • Nonblocking: 1 (custom-model end-to-end coverage — deferrable).
  • Questions: none.
  • Tests run: regression (5), non-assimulo suite (38), assimulo integration (8), whitespace check — all green.
  • Merge-readiness: mergeStateStatus: CLEAN, PR-head checks green. No blocking findings.

This account authored the PR, so GitHub does not accept a self-APPROVE; posting as COMMENT. reviewDecision is currently empty (no reported approval gate) — if branch protection later requires an approval, an eligible maintainer will need to provide it.

@bernalde
bernalde merged commit ab25336 into master Jul 14, 2026
2 checks passed
@bernalde
bernalde deleted the fix/issue-71-kinetics-custom-equilibrium branch July 14, 2026 14:18
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.

High: [Kinetics] Custom rate-law setup and vectorized equilibrium reverse term crash

2 participants