Skip to content

Instantly share code, notes, and snippets.

@maedoc
Created January 9, 2016 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maedoc/6de1fba6ebb5ea965cb2 to your computer and use it in GitHub Desktop.
Save maedoc/6de1fba6ebb5ea965cb2 to your computer and use it in GitHub Desktop.
avoid storing temporary files in home if needed in TVB
class BaseSettingsProfile(object):
TVB_USER_HOME = os.environ.get('TVB_USER_HOME', '~')
TVB_CONFIG_FILE = os.path.expanduser(os.path.join(TVB_USER_HOME, '.tvb.configuration'))
DEFAULT_STORAGE = os.path.expanduser(os.path.join(TVB_USER_HOME, 'TVB' + os.sep))
FIRST_RUN_STORAGE = os.path.expanduser(os.path.join(TVB_USER_HOME, '.tvb-temp'))
@maedoc
Copy link
Author

maedoc commented Jan 9, 2016

use like so

$ TVB_USER_HOME=/scratch python my_simulation.py

@JohnGriffiths
Copy link

So would the idea here be to add these lines to the BaseSettingsProfile class definition in basic/config/profile_settings.py?

@JohnGriffiths
Copy link

Here's what I came up with. Will do for now as a hack (just replaces from tvb.simulator.lab import * with from scinet_tvb_lab import *).

I'll log this on Jira after I've done a few more tests.

"""
scinet_tvb_lab.py
=================

Usage: 

  from scinet_tvb_lab import *

Alternative to calling

  from tvb.simulator.lab import *

The difference is that we specify alternative locations
for some folders that by default are located in /home
(~/), which are used for some minimal logging purposes.

This needs to be modified because scinet compute nodes
do not have write access to /home, only to /scratch.
So that's where we change the locations to.

"""

# Specify the paths we will change in the TvbProfile

orig_base_dir = '/home/r/rmcintos/johngrif'
new_base_dir =  '/scratch/r/rmcintos/johngrif'

tochange = ['DEFAULT_STORAGE', 'FIRST_RUN_STORAGE',
                   'TVB_LOG_FOLDER', 'TVB_CONFIG_FILE',
                  'TVB_STORAGE', 'TVB_TEMP_FOLDER']


# Initial imports

import os,pdb,numpy,numpy as np
from time import time
from numpy import * # for load & save not available in pylab

from tvb.basic.profile import TvbProfile


# Now import the library profile, modify the paths, a bit more fiddling, and initialize:


# First run set_profile but don't do any initializing 
# (not doing this gives some errors to do with logging)
TvbProfile.set_profile('LIBRARY_PROFILE', run_init=False)


# This is where we change the folders from home to scratch
for c in tochange:
  tmp = getattr(TvbProfile.current, c)
  setattr(TvbProfile.current, c, i
          tmp.replace(orig_base_dir, new_base_dir))

# This creates the folders if they're not there already
TvbProfile.current.initialize_profile()


# Now can get on with importing the various tvb modules

from tvb.simulator import (simulator, models, coupling, integrators, monitors, noise)

from tvb.datatypes import connectivity, surfaces, equations, patterns, region_mapping, sensors, cortex, local_connectivity

from tvb.simulator.common import get_logger
LOG = get_logger(__name__)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment