Skip to content

fix: migrate bdsim %run -m subprocess pattern to %run -i (chap4-9/15/16) - #36

Merged
petercorke merged 4 commits into
mainfrom
fix/run-i-migration
Aug 16, 2026
Merged

petercorke merged 4 commits into
mainfrom
fix/run-i-migration

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

IPython's %run -m resolves names through Python's import machinery, which rejects hyphenated module names -- breaks for every RVC3/models script using the repo's hyphenated-filename convention (walking, jointspace, IBVS-*, computed-torque-main, feedforward-main). It also meant bdsim's older subprocess/run_shell()/pickle-file dance (needed to work around animation issues that no longer exist -- bdsim's notebook animation support now works directly in-kernel) was still hanging around in several notebooks. This branch finishes migrating every remaining bdsim script cell to %run -i $models_dir/<script>.py, which runs the script in place sharing the notebook's own namespace, and removes run_shell() entirely (confirmed zero references remain repo-wide).

  • chap8: RRMC/RRMC2 migrated; out.clock0.x fixed to out.clock0.X (bdsim uses capital X for discrete state).
  • chap7/15/16: jointspace, walking, IBVS-main, and all 5 chap16 IBVS-*-main cells migrated. chap15/16 had no models_dir/sys.path setup at all -- added it (chap16 was missing its entire setup cell, root cause of separate NameErrors there).
  • chap5/chap9: braitenberg and all 6 remaining bdsim scripts (vloop_test, ploop_test, zerotorque, feedforward-main, computed-torque-main, opspace, SEA) migrated; run_shell() def removed from chap5/7/8/9's imports cells.
  • RRMC.py/RRMC2.py: DINTEGRATOR -> INTEGRATOR_S, dropped the deprecated matrix= kwarg.
  • Two real bugs caught during verification and fixed as part of this migration (not pre-existing content, bugs in this migration's own targets): chap9's feedforward cell pointed at a nonexistent feedforward.py (actual file is feedforward-main.py); chap16's IBVS-arm-main cell used out.clock1.x instead of .X (same bug class as chap8's fix).

Deliberately left unfixed, matching the precedent already set for walking.py's crash (fixed separately, RTB PR #595) -- downstream bugs inside the scripts themselves, only surfaced now that %run -i actually reaches them:

  • chap5: braitenberg.py -- BlockCreationError creating VehiclePlot.
  • chap9: feedforward-main.py -- AttributeError: y0. opspace.py -- RuntimeError: could not compile system (already known, unrelated to this migration).
  • chap15/16: IBVS-main.py and 4 of chap16's 5 IBVS scripts -- BlockCreationError on their first custom block (Camera/Function/MultiRotorMixer).

Test plan

  • tests/notebook_runner.py across chap5/7/8/9/15/16: run_shell fully gone, no invocation-mechanics failures remain. Only the pre-existing/deferred script-content bugs listed above remain as errors -- everything else that used to fail from the old subprocess pattern now runs clean.

🤖 Generated with Claude Code

petercorke and others added 4 commits August 17, 2026 08:17
…x= kwarg

Both were raising DeprecationWarnings on every run: DINTEGRATOR is
deprecated in favour of INTEGRATOR_S (block names are always allcaps
in bdsim's own convention), and PROD's matrix= kwarg has had no
effect since matrix-vs-elementwise became auto-detected from input
type. Verified both scripts run with zero warnings after the change.
Same run_shell()/subprocess-pickle removal as the chap7/15/16 pass:
add models_dir/examples_dir, replace the COLAB if/else with a single
%run -i $models_dir/RRMC[2].py. Downstream of that, out.clock0.x was
also wrong -- bdsim uses capital X for discrete state (x is for
continuous state, empty here since this system is discrete-only) --
which was silently masking a stale q from an unrelated earlier
section once out.clock0 itself started raising cleanly instead of
falling through a subprocess pickle. Verified end-to-end: RRMC and
RRMC2 both run clean under the current (already-fixed) bdsim, and
puma.fkine(q) no longer hits the reshape error that was really just
a symptom of q never having been correctly assigned.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…del scripts

IPython's %run -m resolves names through Python's import machinery,
which rejects hyphenated module names -- breaks for every RVC3/models
script using the repo's hyphenated-filename convention (walking,
jointspace, IBVS-*). Switch to %run -i (file-path mode), matching the
pattern already proven in chap4.

- chap7: jointspace (COLAB branch) and walking cells; walking.py lives
  in RVC3/examples/ not RVC3/models/, so add an examples_dir alongside
  models_dir
- chap15: IBVS-main cell; notebook had no models_dir/sys.path setup at
  all, added it
- chap16: same gap plus a bigger one -- the notebook was missing its
  entire setup/import cell (zero imports anywhere), which was also the
  root cause of the NameError: SphericalCamera/CentralCamera cells.
  Added a standard setup cell (imports + models_dir) and fixed all 5
  %run -m cells (partitioned/arm/holonomic/nonholonomic/quadrotor)

Two things intentionally left out of this migration:
- app.ipynb's eigdemo cell: not an RVC3-python file at all -- lives in
  RTB's own repo with inconsistent packaging (entry_points expects
  src/roboticstoolbox/examples/, actual file is at repo-root
  examples/). Needs its own investigation, not a mechanical swap.
- Downstream failures once %run -i actually reaches the scripts
  (walking.py's PyPlot crash, now fixed separately in RTB PR #595; the
  IBVS scripts' bdsim BlockCreationError, not yet investigated) are out
  of scope here -- this commit only fixes the invocation mechanics.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Same subprocess-pickle removal as the already-migrated chap4/7/8/15/16:
chap5's braitenberg cell and chap9's six bdsim script cells
(vloop_test, ploop_test, zerotorque, feedforward, computed-torque-main,
opspace, SEA) all switch from the COLAB if/else + run_shell() subprocess
pattern to a single unconditional %run -i $models_dir/<script>.py.
chap7's jointspace cell (left on the old if/else + run_shell() pattern
by the previous migration pass) is fully migrated to match. The
now-dead run_shell() def is removed from chap5/7/8/9's imports cells --
confirmed zero remaining references repo-wide.

Two bugs caught during verification, fixed here since they're bugs in
this migration's own targets, not pre-existing content:
- chap9's feedforward cell pointed at a nonexistent feedforward.py --
  the actual script is feedforward-main.py (hyphenated, like
  computed-torque-main.py alongside it).
- chap16's IBVS-arm-main cell used out.clock1.x; bdsim uses capital X
  for discrete state (x is for continuous state) -- same bug class as
  chap8's clock0.x fix.

Downstream bugs newly surfaced now that %run -i actually reaches these
scripts are deliberately left unfixed here, matching the precedent set
by the original chap7/15/16 migration (walking.py's crash, the IBVS
scripts' BlockCreationError):
- chap5: braitenberg.py -- BlockCreationError creating VehiclePlot.
- chap9: feedforward-main.py -- AttributeError: y0, once the missing-file
  error above stopped masking it. opspace.py -- RuntimeError: could not
  compile system (already known, unrelated to this migration).
- chap16: IBVS-partitioned/holonomic/nonholonomic/quadrotor-main.py --
  BlockCreationError on their first custom block (Camera, Function,
  MultiRotorMixer) -- same bucket as IBVS-main's failure in chap15,
  already flagged as not yet investigated.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@petercorke
petercorke merged commit 26b35f0 into main Aug 16, 2026
@petercorke
petercorke deleted the fix/run-i-migration branch August 16, 2026 23:48
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.

1 participant