Maintainer triage (June 29, 2026)
- Status: Verified bug against the current
master source in this fork.
- Severity: High.
- Area labels: area:metamodeling.
- Tackle batch: P3 - documented-mode crashes and tooling breakages.
The source review confirmed that the cited code path and failure mode are still present. The original audit details are preserved below for reproduction notes and suggested fixes.
Original audit details
Severity: High · Part of #67 (round-2 audit batch)
_All three confirmed defects are in PharmaPy/MetaModeler.py inside the same _write_method codegen routine and break the documented CreatePharmaPyTemplate bootstrap workflow. The concatenate/hstack crash (97/99) and the np.acum_len crash (157/163) are both string-emission typos in the same emitter and would be fixed in one codegen-correctness PR. Two of the three confirmed findings are the same concatenate/hstack defect verified twice (de-duplicated here into a single defect entry).
This issue bundles 2 defects that share one fix/PR.
1. (High) Generated unit_model uses np.concatenate/np.hstack with two arrays as separate positional args (crashes on first RHS evaluation)
Location: PharmaPy/MetaModeler.py:97 (ODE) and :99 (DAE/PDE)
__write_method emits 'balances = np.concatenate(material, energy)' (line 97, ODE) and 'balances = np.hstack(material, energy)' (line 99, DAE/PDE). Both functions take a single sequence; passing two positional arrays makes the second be interpreted as axis/dtype. np.concatenate(material, energy) raises TypeError 'only integer scalar arrays can be converted to a scalar index'; np.hstack(material, energy) raises TypeError 'hstack() takes 1 positional argument but 2 were given'. The block is documented (lines 86-87) as 'This method will work by itself and does not need any user manipulation', so users are told not to edit it.
- Trigger: MetaModelingClass(..., name_states=[...], model_type='ODE' or 'DAE').CreatePharmaPyTemplate() (exactly the file's main example, default model_type='DAE'), fill in material/energy balances, then solve_model -> CVode/IDA invokes unit_model on the first RHS evaluation.
- Wrong result: TypeError on the first unit_model call; every generated ODE/DAE/PDE model is unrunnable. (Corroborated by in-repo DynamicExtraction.py, generated by this main block, which was hand-edited to np.column_stack(material+energy).ravel().)
- Suggested fix: Wrap operands in a tuple: emit 'balances = np.concatenate((material, energy))' (ODE) and 'balances = np.hstack((material, energy))' (DAE/PDE).
- Net-new (not a duplicate): No filed issue references MetaModeler.py.
2. (Medium) Generated retrieve_results references undefined np.acum_len instead of self.acum_len
Location: PharmaPy/MetaModeler.py:157 (ODE) and :163 (DAE)
The retrieve_results body emits 'outputs_split = np.split(states, np.acum_len, axis=1)' for both ODE and DAE. np.acum_len is not a numpy attribute; the cumulative-length array is assigned to self.acum_len at line 129 (and correctly referenced as self.acum_len in unit_model's emitted code at line 58). At runtime this raises AttributeError: module 'numpy' has no attribute 'acum_len'.
- Trigger: Generate an ODE or DAE template via CreatePharmaPyTemplate(), then call retrieve_results(time, states) to post-process solver output (the standard results step).
- Wrong result: AttributeError on every results-retrieval call; the user cannot extract per-state results from the generated model.
- Suggested fix: Emit 'np.split(states, self.acum_len, axis=1)' (use self, not np) in both the ODE and DAE branches.
- Net-new (not a duplicate): No filed issue references MetaModeler.py.
Related existing issues (referenced, not modified): None; no filed issue references MetaModeler.py. (#49 is DistillationColumn, unrelated.)
Found by a multi-agent source audit (round 2); confirmed by re-reading the source and cross-checked against all 80 existing open issues. Each defect was verified by an independent code-truth skeptic and a novelty skeptic.
Maintainer triage (June 29, 2026)
mastersource in this fork.The source review confirmed that the cited code path and failure mode are still present. The original audit details are preserved below for reproduction notes and suggested fixes.
Original audit details
Severity: High · Part of #67 (round-2 audit batch)
_All three confirmed defects are in PharmaPy/MetaModeler.py inside the same _write_method codegen routine and break the documented CreatePharmaPyTemplate bootstrap workflow. The concatenate/hstack crash (97/99) and the np.acum_len crash (157/163) are both string-emission typos in the same emitter and would be fixed in one codegen-correctness PR. Two of the three confirmed findings are the same concatenate/hstack defect verified twice (de-duplicated here into a single defect entry).
This issue bundles 2 defects that share one fix/PR.
1. (High) Generated unit_model uses np.concatenate/np.hstack with two arrays as separate positional args (crashes on first RHS evaluation)
Location:
PharmaPy/MetaModeler.py:97 (ODE) and :99 (DAE/PDE)__write_method emits 'balances = np.concatenate(material, energy)' (line 97, ODE) and 'balances = np.hstack(material, energy)' (line 99, DAE/PDE). Both functions take a single sequence; passing two positional arrays makes the second be interpreted as axis/dtype. np.concatenate(material, energy) raises TypeError 'only integer scalar arrays can be converted to a scalar index'; np.hstack(material, energy) raises TypeError 'hstack() takes 1 positional argument but 2 were given'. The block is documented (lines 86-87) as 'This method will work by itself and does not need any user manipulation', so users are told not to edit it.
2. (Medium) Generated retrieve_results references undefined np.acum_len instead of self.acum_len
Location:
PharmaPy/MetaModeler.py:157 (ODE) and :163 (DAE)The retrieve_results body emits 'outputs_split = np.split(states, np.acum_len, axis=1)' for both ODE and DAE. np.acum_len is not a numpy attribute; the cumulative-length array is assigned to self.acum_len at line 129 (and correctly referenced as self.acum_len in unit_model's emitted code at line 58). At runtime this raises AttributeError: module 'numpy' has no attribute 'acum_len'.
Related existing issues (referenced, not modified): None; no filed issue references MetaModeler.py. (#49 is DistillationColumn, unrelated.)
Found by a multi-agent source audit (round 2); confirmed by re-reading the source and cross-checked against all 80 existing open issues. Each defect was verified by an independent code-truth skeptic and a novelty skeptic.