{{ message }}
Repository navigation
Fix Block.linearize() DynamicOperator crash, Register 0-d array bug, and duplicate TestLUT1D class - #240
Merged
milanofthe merged 2 commits intoJul 26, 2026
Conversation
added 2 commits
July 25, 2026 20:05
… op_alg Block.linearize()'s no-engine branch called op_alg.linearize(u) with a single argument regardless of operator type, which raised TypeError for any stateless block whose op_alg is a DynamicOperator (e.g. DynamicalFunction), since DynamicOperator.linearize requires (x, u, t). Dispatch on the operator type instead. No test previously exercised this combination.
Found while building an aircraft trim example using LUT1D as a CL(alpha)/ Cm(alpha) lookup table. LUT1D's underlying scipy interp1d call, for a single scalar output, returns a 0-d numpy array; Register.update_from_array did len(arr) on anything isinstance(arr, np.ndarray), which raises TypeError for 0-d arrays. Special-case 0-d arrays as scalars. Root cause of why this went uncaught: tests/pathsim/blocks/test_table.py had two classes both named TestLUT1D. Python silently let the second shadow the first at module import, so pytest never collected the first class's tests (test_embedding_siso, test_update_siso, etc.) -- including the coverage that would have caught this. Renamed the first class to TestLUT1DEmbedding to restore it. Unshadowing surfaced two more latent issues, fixed here: - Register.__setitem__ didn't tolerate a 1-element numpy array assigned to a scalar int index (numpy 2.x: "setting an array element with a sequence") -- extended the existing 0-d scalar-coercion branch. - test_linearization_siso asserted the wrong expected value: linear interpolation between grid points (1, 1) and (2, 4) at x=1.5 correctly gives 2.5, not the exact quadratic 1.5**2=2.25 the test asserted. test_sensitivity in the same file imports pathsim.optim.value.Value, which does not exist anywhere in the current src/ tree -- looks like a stale test for removed/never-merged AD functionality. Marked @unittest.skip with an explicit reason instead of guessing at reimplementing it; worth reporting separately.
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Three independent bugs found while building the aircraft trim/linearize example in #237, split out on their own per review there — none of them touch the linearization design discussed in #195/#239.
Changes
blocks/_block.py: fixBlock.linearize()TypeErrorfor stateless blocks whoseop_algis aDynamicOperator(e.g.DynamicalFunction); regression test intest_function.py.utils/register.py:update_from_arraynow handles 0-d numpy arrays (e.g. fromscipy.interpolate.interp1dcalled on a scalar) as scalars instead of crashing onlen();__setitem__now tolerates a 1-element array assigned to a scalar index.tests/pathsim/blocks/test_table.py: two classes were both namedTestLUT1D, silently shadowing 8 tests — including the ones that would have caught the register bug above. Renamed the first toTestLUT1DEmbedding; fixed one test's wrong expected value (2.25 -> 2.5, LUT1D interpolates linearly); skippedtest_sensitivitywith an explicit reason (importspathsim.optim.value.Value, which doesn't exist anywhere insrc/).Test plan
pytest -m "slow or not slow"passes (1171 passed, 14 skipped, 1 pre-existing unrelated FMU failure also present onmaster)tests/pathsim/