Skip to content

Commit 81a522a

Browse files
Merge pull request #75 from the-virtual-brain/EBR-188
EBR-188: resolve OpenViewer issues after testing at JSC
2 parents 2c36654 + 2f1bcae commit 81a522a

5 files changed

Lines changed: 22 additions & 11 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tvb-ext-xircuits",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Jupyterlab extension for building TVB workflows in a visual and interactive manner",
55
"keywords": [
66
"jupyter",

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ full = [
6868
"tvb-gdist",
6969
"tvb-framework",
7070
"tvb-widgets>=1.0",
71-
"vbi[inference]",
71+
"vbi[inference]<=0.3",
7272
"torch",
7373
"sbi"
7474
]
@@ -139,5 +139,6 @@ include = [
139139
"xai_components/",
140140
"tvbextxircuits/",
141141
"examples/",
142+
"config/"
142143
]
143144
artifacts = ["tvbextxircuits/labextension"]

tvbextxircuits/nb_generator.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ class NotebookFactory(object):
9292
def get_notebook_for_component(component_name, component_id, component_path, component_inputs, xircuits_id, xircuits_filename):
9393
component_class = determine_component_class(component_name, component_path)
9494

95-
if not (issubclass(component_class, ComponentWithWidget) or issubclass(component_class, ComponentWithViewer)):
95+
if component_class is None:
96+
return None
97+
98+
if not issubclass(component_class, (ComponentWithWidget, ComponentWithViewer)):
9699
return None
97100

98101
if component_class.__name__.startswith('StoreResults'):
@@ -435,6 +438,14 @@ def edit_cell(self):
435438
return True
436439

437440
def determine_component_class(component_name, component_path):
438-
component_module = importlib.import_module(component_path.replace('/', '.')[:-3])
439-
component_class = getattr(component_module, component_name)
440-
return component_class
441+
try:
442+
component_module = importlib.import_module(component_path.replace('/', '.')[:-3])
443+
component_class = getattr(component_module, component_name)
444+
return component_class
445+
except ModuleNotFoundError as e:
446+
LOGGER.error(f"Module not found while loading {component_path}: {e}")
447+
except AttributeError:
448+
LOGGER.error(f"Class {component_name} not found in module {component_path}.")
449+
450+
return None
451+

xai_components/xai_vbi_sample_posterior/sample_posterior.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
from xai_components.base import xai_component, InArg, OutArg
2-
import torch
3-
from vbi.sbi_inference import Inference
42
import os
53
from xai_components.base_tvb import ComponentWithViewer
64
from tvbextxircuits.logger.builder import get_logger
@@ -16,13 +14,14 @@ class SamplePosterior(ComponentWithViewer):
1614
obs_idx: InArg[int]
1715
output_dir: InArg[str]
1816

19-
samples: OutArg[torch.Tensor]
17+
samples: OutArg[any]
2018

2119
def __init__(self):
2220
super().__init__()
2321
self.obs_idx.value = 0
2422

2523
def execute(self, ctx):
24+
from vbi.sbi_inference import Inference
2625

2726
x_idx_st = self.X_scaled.value[self.obs_idx.value,:]
2827

@@ -38,6 +37,7 @@ def execute(self, ctx):
3837

3938
@staticmethod
4039
def persists_artifacts(output_dir, samples):
40+
import torch
4141
# Store the resulted samples for plotting
4242
path = os.path.join(output_dir, "samples.pt")
4343
torch.save(samples, path)

xai_components/xai_vbi_simulation_runner/simulation_runner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from xai_components.base import xai_component, InArg, OutArg
22
import numpy as np
3-
import torch
43
from multiprocessing import Pool
54
from copy import deepcopy
65
from typing import Literal
@@ -40,7 +39,7 @@ def cpp_worker(task):
4039
class SimulationRunner(ComponentWithViewer):
4140
backend: InArg[Literal['cupy', 'cpp']]
4241
model: InArg[any]
43-
theta: InArg[torch.Tensor]
42+
theta: InArg[any]
4443
theta_names: InArg[list]
4544
cfg: InArg[dict]
4645
num_workers: InArg[int]

0 commit comments

Comments
 (0)