Skip to content

Show independent Python models for two instances of a component - #10

Open
ru551n wants to merge 1 commit into
VUnit:mainfrom
ru551n:independent-model-sessions
Open

ru551n wants to merge 1 commit into
VUnit:mainfrom
ru551n:independent-model-sessions

Conversation

@ru551n

@ru551n ru551n commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Adds accumulator_model, a component with a stateful Python model, to the embedded_python example. The new test case Test independent models of two instances instantiates it twice; each instance makes a session with new_session(accumulator_model'instance_name), executes the same accumulator_model.py into it with exec_file after test_runner_setup, and passes the session to every call. The two instances get different inputs, and the test checks that each one keeps its own total.

The user guide gets a new section, Independent models of component instances, under Sessions. It explains why repeated instances need a session each, why a fixed name doesn't separate them and how 'instance_name does, and that NVC, GHDL or Questa is needed. It links to the runnable example and shows the class-based alternative (one object per session, state on self). The caveats now also say that state in the globals of an imported module isn't isolated.

The session is made in the statement part of the process. GHDL (7.0.0-dev) leaves the instance labels out of 'instance_name (and 'path_name) when it is evaluated in a declaration: both instances got :tb_example(tb)accumulator_model(python):, so they shared one session. The docs mention this.

Fixes #8

Testing

  • examples/embedded_python/run.py --without-attributes .optional_deps --without-attributes .expected_failure: 18 of 18 pass on NVC and on GHDL.
  • tests/run.py: 106 of 106 pass on NVC and on GHDL. pytest tests/test_python_bridge.py: 85 passed.
  • Checked that the test catches sharing: with a fixed session name, it fails (Got 12. Expected 3.).
  • Ran the class-based doc snippet in a scratch testbench with two instances: passes on NVC and GHDL.
  • sphinx-build of the docs: no warnings.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Document and demonstrate independent Python models for multiple VHDL instances

1 participant