BDSim(load=False) + sim.blockdiagram() raises AssertionError, defeating the point of load=False
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start in src/bdsim/run_sim.py at blockdiagram(), especially the assertion and factory-method-binding loop around the linked lines. Reproduce the BDSim(load=False) example, then verify that blockdiagram() works without the library while setting bd.runtime, and that the documented non-factory construction path remains usable.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 267
- Forks
- 39
- Avg merge
- 11d 18h
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from petercorke/bdsim
-
tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
petercorke/bdsim#78 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
petercorke/bdsim#28 · 1 comment ·
-
tech-debt
Difficulty 5/5 Over a week Newbie friendliness 30/100
petercorke/bdsim#92 · 1 comment ·
-
tech-debt
Difficulty 3/5 1-2 days Newbie friendliness 68/100
petercorke/bdsim#91 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
petercorke/bdsim#84 · 1 comment ·
All issues in petercorke/bdsim
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100