fix(blocks): FDyn_X.output() crashed/asserted on unset xdd before deriv() ran - #647
Merged
Conversation
…iv() ran FDyn_X.output() returned xdd=None until self._qdd got set as a side effect of deriv() running at least once. That's fine when deriv() always runs first, but bdsim calls a continuous block's output() wherever the compute graph needs its state-derived ports (q, qd, x, xd here) -- including during compile()'s dry-run connectivity check and sim.run()'s t=0 IC-sample pass, both before any deriv() call. Any watch=[...] or wiring that reads xdd at that point hit bdsim's outport_value() assertion: "output value 4 not set". Confirmed via RVC3-python's opspace.py example: robot_x.w depends on robot_x.xd through the force-control feedback loop, so xdd's only input (w) is only resolvable *after* this same output() call has already returned xd -- output() genuinely cannot compute xdd itself here, in one atomic call, regardless of caching. Filed the general case as petercorke/bdsim#81 (stateful blocks whose output() needs a resolved input, unlike e.g. INTEG which only needs it in deriv()). Fix: cache a zero-acceleration placeholder for xdd from __init__ instead of None, overwritten by every real deriv() call. output() never touches inports, matching every other continuous block's state-only assumption. Only the very first watched/logged xdd sample reads 0 instead of the true value; every step from deriv()'s first real call onward is exact. Test plan: - opspace.py (RVC3-python's task-space operational-space-control example, the model that surfaced this) now runs to completion end-to-end under a real bdsim simulation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #647 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 143 143
Lines 14035 14033 -2
=====================================
+ Misses 14035 14033 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merged
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
FDyn_X.output()returnedxdd=Noneuntilself._qddgot set as a side effect ofderiv()running at least once. That's fine whenderiv()always runs first, but bdsim calls a continuous block'soutput()wherever the compute graph needs its state-derived ports (q, qd, x, xdhere) -- including duringcompile()'s dry-run connectivity check andsim.run()'s t=0 IC-sample pass, both before anyderiv()call. Anywatch=[...]or wiring that readsxddat that point hit bdsim'soutport_value()assertion:AssertionError: block fdyn_x.0 output value 4 not set.Found via RVC3-python's
opspace.pyexample (task-space operational-space control,bd.FDYN_X(...)withwatch=[..., robot_x.xdd]).Confirmed this isn't just an initialization-ordering bug fixable by caching more cleverly:
robot_x.w(this block's own input) depends onrobot_x.xd(this block's own output) via the force-control feedback loop inopspace.py(robot_x.w = fsum + pprod,fprod[1] = ... * robot_x.xd). Sowis only resolvable after this sameoutput()call has already returnedxd--output()genuinely can't computexdditself in one atomic call, regardless of timestamp-based staleness tracking. Filed the general case as petercorke/bdsim#81 (stateful blocks whoseoutput()needs a resolved input, unlike e.g.INTEGwhich only needs its input insidederiv()).Fix
Cache a zero-acceleration placeholder for
xddfrom__init__instead ofNone, overwritten by every realderiv()call.output()never touchesinports, matching every other continuous block's state-only assumption. Only the very first watched/loggedxddsample reads0instead of the true value; every step fromderiv()'s first real call onward is exact.Test plan
opspace.py(the example that surfaced this) now runs to completion end-to-end under a real bdsim simulation -- previously crashed with the assertion abovetests/test_notebooks.py::test_notebook[chap9.ipynb](which runs this model via%run -i) now passes clean