BDSim(load=False) is documented (see Coding-patterns) as the way to construct a block diagram without dynamically loading the block library, and instead build it from block classes imported directly (from bdsim.blocks import Step, Gain, ...) with bd=bd passed to each constructor.
In practice, sim.blockdiagram() unconditionally asserts the block library exists, even when load=False was explicitly passed to skip loading it:
https://github.com/petercorke/bdsim/blob/main/src/bdsim/run_sim.py#L2124
import bdsim
sim = bdsim.BDSim(load=False)
bd = sim.blockdiagram() # AssertionError
sim.blockdiagram() needs the block library only to bind the upper-case factory methods (.GAIN, .STEP, etc.) onto the returned BlockDiagram — methods the "non factory" pattern deliberately doesn't use. The assert fires regardless, defeating the point of load=False.
Workaround (used to keep the wiki's Coding-patterns page accurate): construct BlockDiagram directly, bypassing sim.blockdiagram(), and set the one attribute it would otherwise have set for you:
from bdsim.blockdiagram import BlockDiagram
bd = BlockDiagram(name="main")
bd.runtime = sim # normally set inside sim.blockdiagram()
This works, but it's a rough edge — reaching into an attribute that's commented # set by BDSim before compilation shouldn't be necessary for a documented usage pattern.
Suggested fix: in blockdiagram(), skip the factory-method-binding loop (rather than asserting) when self._blocklibrary is None, and set bd.runtime = self either way.
Found while auditing the wiki against current main — the Coding-patterns page's "Non factory" example predates this and was silently broken.
BDSim(load=False)is documented (see Coding-patterns) as the way to construct a block diagram without dynamically loading the block library, and instead build it from block classes imported directly (from bdsim.blocks import Step, Gain, ...) withbd=bdpassed to each constructor.In practice,
sim.blockdiagram()unconditionally asserts the block library exists, even whenload=Falsewas explicitly passed to skip loading it:https://github.com/petercorke/bdsim/blob/main/src/bdsim/run_sim.py#L2124
sim.blockdiagram()needs the block library only to bind the upper-case factory methods (.GAIN,.STEP, etc.) onto the returnedBlockDiagram— methods the "non factory" pattern deliberately doesn't use. The assert fires regardless, defeating the point ofload=False.Workaround (used to keep the wiki's Coding-patterns page accurate): construct
BlockDiagramdirectly, bypassingsim.blockdiagram(), and set the one attribute it would otherwise have set for you:This works, but it's a rough edge — reaching into an attribute that's commented
# set by BDSim before compilationshouldn't be necessary for a documented usage pattern.Suggested fix: in
blockdiagram(), skip the factory-method-binding loop (rather than asserting) whenself._blocklibrary is None, and setbd.runtime = selfeither way.Found while auditing the wiki against current
main— the Coding-patterns page's "Non factory" example predates this and was silently broken.