Skip to content

fix: add error handling and resolve blocking plt.show in TVB components#78

Open
SandeepChauhan00 wants to merge 1 commit intothe-virtual-brain:devfrom
SandeepChauhan00:fix-runtime-bugs
Open

fix: add error handling and resolve blocking plt.show in TVB components#78
SandeepChauhan00 wants to merge 1 commit intothe-virtual-brain:devfrom
SandeepChauhan00:fix-runtime-bugs

Conversation

@SandeepChauhan00
Copy link
Copy Markdown

Description

I ran into a couple of issues while testing the components
locally and wanted to fix them up.

connectivity.py:

  • There was a duplicate import of Connectivity — it was
    imported at the top of the file and then again inside
    execute(). Cleaned that up by removing the one inside
    the method.

  • plt.show() was blocking the entire workflow when running
    in non-interactive environments like JupyterLab or on a
    remote server. Changed it to plt.show(block=False) with
    a try/except fallback so it doesn't freeze things up if
    the environment can't display plots.

  • Added error handling around Connectivity.from_file()
    if someone passes in a bad file path, they now get a
    readable error message instead of a raw Python traceback.

  • Also added a plot title so the connectivity matrix
    visualization is a bit easier to identify.

simulator.py:

  • The simulator would crash with a confusing internal TVB
    error if connectivity wasn't connected. Added a quick
    check at the top of execute() that gives a clear message
    telling the user to connect a ConnectivityFromFile component.

  • Wrapped simulator.configure() and simulator.run() in
    try/except blocks so that configuration or runtime failures
    produce helpful messages instead of raw tracebacks.

  • Added basic timing — logs how long the simulation took,
    which is handy when experimenting with different parameters.

  • Renamed the loop variable from time to time_data to
    avoid shadowing the time module that's now imported at
    the top.

Nothing should break — all the original behavior is preserved,
just with better error messages and a non-blocking plot.

References

N/A

Pull Request Type

  • Xircuits Core (Jupyterlab Related changes)
  • Xircuits Canvas (Custom RD Related changes)
  • Xircuits Component Library
  • Xircuits Project Template
  • Testing Automation
  • Documentation
  • Others (Please Specify)

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Tests

Tested locally by:

  1. Running ConnectivityFromFile with a valid default path —
    loads correctly and shows the plot without blocking.

  2. Running ConnectivityFromFile with a bad file path —
    confirms the new error message appears instead of a
    raw traceback.

  3. Running Simulator without connectivity connected —
    confirms the validation catches it and shows a clear
    message.

Tested on:

  • Windows

Notes

Just wanted to make the components a bit more forgiving
for new users. If the approach looks good I'm happy to
apply similar improvements to other components too.

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.

2 participants