Wiki source code of Widget PSE
Version 17.1 by teodoramisan on 2023/07/21 12:15
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
7.1 | 1 | (% class="wikigeneratedid" id="HWidgetPSE" %) |
| |
6.1 | 2 | Source code: [[https:~~/~~/github.com/the-virtual-brain/tvb-widgets>>https://github.com/the-virtual-brain/tvb-widgets]] |
| 3 | |||
| 4 | == **Purpose** == | ||
| 5 | |||
| 6 | |||
| |
11.1 | 7 | It is composed of two separate Jupyter Widgets(PSE Launcher and PSE Visualizer) intended for the visualization of launching custom simulations. The launcher works locally and on HPC. |
| |
6.1 | 8 | |
| 9 | The simulation can be customized by: | ||
| 10 | |||
| |
12.1 | 11 | * Getting a list of connectivities and an HPC configuration given as APIs |
| |
6.1 | 12 | * Setting up parameters and ranges |
| 13 | * Selecting multiple metrics | ||
| |
11.1 | 14 | * Observing the progress of the launch by a monitor progress bar |
| |
6.1 | 15 | |
| 16 | == **Inputs** == | ||
| 17 | |||
| |
13.1 | 18 | * PSELauncher(Simulator, List of Connectivities, HPC Configuration) |
| |
6.1 | 19 | * PSEVisualizer(Filename), the file will contain all the customized parameters from the launcher |
| 20 | |||
| 21 | == **Requirements and installation** == | ||
| 22 | |||
| 23 | Before installing the tvb-widgets library containing the PSE widgets, the following python library and Jupyter extensions should be installed: | ||
| 24 | |||
| 25 | * Libraries | ||
| 26 | ** [[plotly>>https://plotly.com/python/getting-started/#installation]] | ||
| 27 | * Extensions | ||
| 28 | |||
| 29 | (% class="box" %) | ||
| 30 | ((( | ||
| 31 | jupyter labextension install @jupyter-widgets/jupyterlab-manager | ||
| 32 | |||
| 33 | jupyter labextension install jupyter-matplotlib | ||
| 34 | ))) | ||
| 35 | |||
| 36 | Then, to install the tvb-widgets library, just type: | ||
| 37 | |||
| 38 | (% class="box" %) | ||
| 39 | ((( | ||
| 40 | pip install tvb-widgets | ||
| 41 | ))) | ||
| 42 | |||
| 43 | == **API usage ** == | ||
| 44 | |||
| 45 | First, the correct matplotlib backend must be set, which enables the interaction with the PSE widgets, by running the following command: | ||
| 46 | |||
| 47 | (% class="box" %) | ||
| 48 | ((( | ||
| 49 | %matplotlib widget | ||
| 50 | ))) | ||
| 51 | |||
| 52 | Then, the PSELauncher and PSEWidget(from the tvb-widgets API) and the package lab(from tvb simulator) should be imported: | ||
| 53 | |||
| 54 | (% class="box" %) | ||
| 55 | ((( | ||
| 56 | from tvbwidgets.api import PSELauncher, PSEWidget | ||
| 57 | from tvb.simulator.lab import * | ||
| 58 | ))) | ||
| 59 | |||
| |
17.1 | 60 | The launcher widget can be initialized with more parameters: a simulator, a list of connectivities and an HPC configuration (only the simulator being a required argument). For HPC launch, besides the configuration part, an EBrains token needs to be stored. A custom initialization, which includes the HPC launch, is shown below: |
| |
6.1 | 61 | |
| 62 | (% class="box" %) | ||
| 63 | ((( | ||
| |
17.1 | 64 | os.environ['CLB_AUTH'] = 'PUT YOUR EBRAINS TOKEN HERE IF YOU WANT HPC RUNS' |
| 65 | |||
| 66 | from pyunicore.helpers.jobs import Resources | ||
| 67 | res = Resources(cpus_per_node=4) | ||
| 68 | |||
| 69 | # !! Pay attention to env name and dir you might need to change if in conflict on the SAME project with another colleague of yours!! | ||
| 70 | |||
| 71 | hpc_config = HPCConfig(site="JUSUF", project="icei-hbp-2021-0007", | ||
| 72 | env_dir="tvb_widget", env_name="venv_tvb", n_threads=None, resources=res) | ||
| 73 | ))) | ||
| 74 | |||
| 75 | (% class="box" %) | ||
| 76 | ((( | ||
| |
6.1 | 77 | sim = simulator.Simulator(connectivity = connectivity.Connectivity.from_file()) |
| 78 | conn_66 = connectivity.Connectivity.from_file("connectivity_66.zip") | ||
| 79 | conn_68 = connectivity.Connectivity.from_file("connectivity_68.zip") | ||
| 80 | conn_76 = connectivity.Connectivity.from_file() | ||
| |
17.1 | 81 | launch = PSELauncher(sim, [conn_66, conn_68, conn_76], hpc_config) |
| |
6.1 | 82 | ))) |
| 83 | |||
| 84 | The outcome will be something like in the image bellow. | ||
| 85 | You can create a customized simulation by choosing different values for parameters, by setting ranges for them and by selecting the metrics for the simulation. | ||
| 86 | |||
| |
10.1 | 87 | [[image:setup_parameters.png||alt="setup_parameters" style="float:left"]] |
| |
6.1 | 88 | |
| |
17.1 | 89 | |
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | |||
| |
6.1 | 99 | Then, a file name has to be inserted in the indicated box(for storing the data) and as a last set-up, a launch type has to be chosen. |
| 100 | |||
| 101 | |||
| |
17.1 | 102 | The progress of the launch can be monitored by a progress bar, as shown below: |
| |
6.1 | 103 | |
| |
17.1 | 104 | (% style="text-align:center" %) |
| 105 | [[image:image-20230721150554-1.png]] | ||
| 106 | |||
| 107 | A file with the name you specified will be generated in both approaches, HPC or local launch. | ||
| 108 | |||
| |
6.1 | 109 | Then, the PSEVisualizer can be called with the required parameter(file_name) as it shows below: |
| 110 | |||
| 111 | (% class="box" %) | ||
| 112 | ((( | ||
| 113 | pse = PSEWidget("test.h5") | ||
| 114 | ))) | ||
| 115 | |||
| 116 | The outcome will be something like in the image bellow. | ||
| 117 | |||
| 118 | There will be a representation for every metric that was chosen before, in the launcher. The widget has some features for the type of visualization, the change of color and the option for choosing between metrics. | ||
| 119 | |||
| |
10.1 | 120 | [[image:result.png||alt="result" style="float:left"]] |