fix: add error handling and resolve blocking plt.show in TVB components#78
Open
SandeepChauhan00 wants to merge 1 commit intothe-virtual-brain:devfrom
Open
fix: add error handling and resolve blocking plt.show in TVB components#78SandeepChauhan00 wants to merge 1 commit intothe-virtual-brain:devfrom
SandeepChauhan00 wants to merge 1 commit intothe-virtual-brain:devfrom
Conversation
liadomide
approved these changes
Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 wasimported at the top of the file and then again inside
execute(). Cleaned that up by removing the one insidethe method.
plt.show()was blocking the entire workflow when runningin non-interactive environments like JupyterLab or on a
remote server. Changed it to
plt.show(block=False)witha 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 messagetelling the user to connect a ConnectivityFromFile component.
Wrapped
simulator.configure()andsimulator.run()intry/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
timetotime_datatoavoid shadowing the
timemodule that's now imported atthe 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
Type of Change
Tests
Tested locally by:
Running ConnectivityFromFile with a valid default path —
loads correctly and shows the plot without blocking.
Running ConnectivityFromFile with a bad file path —
confirms the new error message appears instead of a
raw traceback.
Running Simulator without connectivity connected —
confirms the validation catches it and shows a clear
message.
Tested on:
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.