Co-Simulation The Virtual Brain Multiscale

Last modified by ldomide on 2024/04/08 12:55

TVB Co-Simulation   

Multiscale: TVB, NEST, ANNarchy, NetPyNE , Elephant, PySpike

Authors: D. Perdikis, A. Blickensdörfer, V. Bragin, L. Domide, J. Mersmann, M. Schirner, P. Ritter 

For more details on TVB see:

Running TVB-MULTISCALE at EBRAINS JupyterLab

TVB-multiscale is made available at EBRAINS JupyterLab.

All the user has to do is log in with their EBRAINS credentials, and start a Python console or a Jupyter notebook using the kernel "EBRAINS-23.09" (or a more recent version), where TVB-multiscale can be imported (e.g., via "import tvb_multiscale"). All necessary TVB-multiscale dependencies (NEST, ANNarchy, NetPyNE (NEURON), Elephant, Pyspike) are also installed and available.

This collab contains various examples of using TVB-Multiscale with all three supported spiking simulators. We suggest copying the contents of this collab to your Library or to any collab owned by you, and running them there (note that the user's drive offers persistent storage, i.e. users will find their files after logging out and in again), as follows:

1. Select `Drive` on the left of the current page (or use this link).

2. Check the `tvb-multiscale-collab` folder checkbox, and copy it to your `My Library` ("copy" icon will appear above the files/folders list).

3. Select `Lab` (on the left), and navigate to the destination where you just copied the folder.

4. Enter the `tvb-multiscale-collab` folder, and open either of example notebooks. Ensure you select the appropriate ipykernel (EBRAINS-23.09 or a more recent one)

Running TVB-MULTISCALE locally

See more on Github https://github.com/the-virtual-brain/tvb-multiscale .

Documented notebooks and other examples will be ok to download and try yourself locally, after you have also prepared and launched locally a Docker env: https://hub.docker.com/r/thevirtualbrain/tvb-multiscale

This is the path recommended for people working closely with tvb-multiscale. They are able to download it in their local work env and code freely and fast with it.

Running TVB-MULTISCALE jobs on HPC infrastructure from HBP collab

tvb-multiscale can run with an HPC backend. This will be efficient when the simulation jobs are very large. From our experience, with small jobs, the stage-in/out time is considerable, and then the user might be better with just a local run. Also, such a deployment requires that the user have an active HPC personal account and allocation project active. More details on how to use this deployment can be found in this movie: https://drive.google.com/open?id=1osF263FK_NjhZcBJfpSy-F7qkbYs3Q-E

  • Create a collab space of your own
  • Clone and run in your HBP Collab Hub (https://lab.ebrains.eu/) the notebooks from here: https://drive.ebrains.eu/d/245e6c13082f45bcacfa/
    • test_tvb-nest_installation.ipynb  Run the cosimulate_tvb_nest.sh script on the HPC supercomputer where you have an account active. In this example, basically we are running the installation_test.py file which is in the docker folder.
    • run_custom_cosimulation.ipynb For this example we are using the cosimulate_with_staging.sh script in order to pull the tvb-multiscale docker image and we are using a custom simulation script (from Github page) which will be uploaded in the staging in phase
    • run_custom_cosimulation_from_notebook.ipynb  This example is running the same simulation as the example above but instead of using an external file with the simulation code we will build a simulation file from a few notebook cells and we will pass this file to the HPC.

Few technical details about what we do in these notebooks:

  1. Prepare UNICORE client api.

PYUNICORE client library is available on PYPI. In order to use it you have to install it using:

pip install pyunicore

Next step is to configure client registry and what supercomputer to use

tr = unicore_client.Transport(oauth.get_token())
r = unicore_client.Registry(tr, unicore_client._HBP_REGISTRY_URL)
# we used "DAINT-CSCS", but you should change it to another supercomputer where you have a project active
client = r.site('DAINT-CSCS')

2. Prepare job submission

In this step we have to prepare a JSON object which will be used in the job submission process.

# What job will execute (command/executable)
my_job['Executable'] = 'job.sh'

# To import files from remote sites to the job’s working directory
my_job['Imports'] = [{
    "From": "https://raw.githubusercontent.com/the-virtual-brain/tvb-multiscale/update-collab-examples/docker/cosimulate_tvb_nest.sh",
    "To" : job.sh
}]

# Specify the resources to request on the remote system
my_job['Resources'] = { 
    "CPUs": "1"}

3. Actual job submission

In order to submit a job we have to use the JSON built in the previous step and also if we have some local files, we have to give their paths as a list of strings (inputs argument) so the UNICORE library will upload them in the job's working directory in the staging in phase, before launching the job.

job = site_client.new_job(job_description=my_job, inputs=['/path1', '/path2'])
job.properties

4. Wait until job is completed and check the results

Wait until the job is completed using the following command

# TRUE or FALSE
job.is_running()

Check job's working directory for the output files/directories using

wd = job.working_dir
wd.listdir()

From working job you can preview files content and download files

# Read 'stdout' file
out = wd.stat("stdout")
f = out.raw()
all_lines = f.read().splitlines()
all_lines[-20:]

# Download 'outputs/res/results.npy' file
wd.stat("outputs/res/results.npy").download("results.npy")