def createTasks(name="unnamed", mean1_a=[0, 10, 20, 30], sigma1_a=[0, 0.1, 0.5, 1.0], mean2_a=[0, 10, 20, 30], sigma2_a=[0, 0.1, 0.5, 1.0], trials=1, experiment=None, **kwargs): task_directory = 'Tasks/' + name + '' import os if not os.path.exists(task_directory): os.makedirs(task_directory) session = schedule.Session(experiment, task_directory + '/Session') main_task = schedule.Task("Main Task", parallel=True, path=task_directory + "/.", tags=['main_task']) main_task.variables['task_directory'] = task_directory main_task.variables['mean1_a'] = mean1_a main_task.variables['sigma1_a'] = sigma1_a main_task.variables['mean2_a'] = mean2_a main_task.variables['sigma2_a'] = sigma2_a session.root_task = main_task for mean1 in mean1_a: for mean2 in mean2_a: mean_task = schedule.Task("Mean values: " + str(mean1) + " and " + str(mean2), main_task, variables={ 'mean1': mean1, 'mean2': mean2 }) main_task.subtasks.append(mean_task) for sigma1 in sigma1_a: for sigma2 in sigma2_a: t = schedule.Task("Standard Deviations: " + str(sigma1) + " and " + str(sigma2), mean_task, cmd=schedule.Command(""" import numpy as np from numpy import deg2rad with task.data as data: from matplotlib.pylab import * values_1 = mean1 + sigma1 * np.random.randn(100) values_2 = mean2 + sigma2 * np.random.randn(100) plot(values_1,values_2,'k.') data.savefig('Raster',gcf()) data.set('values_1',values_1) data.set('values_2',values_2) time.sleep(randint(0,2)) # sleep between 0 and 2 seconds """), variables={ 'sigma1': sigma1, 'sigma2': sigma2 }, parallel=True, tags=['stimulus']) mean_task.subtasks.append(t) return session
def __init__(self): QtGui.QMainWindow.__init__(self) self.setWindowTitle('Silver Gui') self.exit = QtGui.QAction(QtGui.QIcon('icons/exit.png'), 'Exit', self) self.exit.setShortcut('Ctrl+Q') self.connect(self.exit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()')) self.statusBar() menubar = self.menuBar() filemenu = menubar.addMenu('&File') filemenu.addAction(self.exit) self.main_widget = QWidget() main_widget_layout = QVBoxLayout(self.main_widget) self.toolbar = self.addToolBar('Exit') self.toolbar.addAction(self.exit) self.ipython = SilverIPython() self.tab_widget = QtGui.QTabWidget() self.openWidget = OpenGui(self) self.tab_widget.addTab(self.openWidget, "Open") s = schedule.Session( None, '/home/jacob/Projects/Silversight/Tasks/ex1/Session 1') s.load() self.tab_widget.addTab(SilverSessionWidget(s), "s.name") self.tab_widget.addTab(SilverSessionWidget(None), "Experiment 2") self.tab_widget.addTab(SilverSessionWidget(None), "Experiment 3") main_widget_layout.addWidget(self.tab_widget) self.setCentralWidget(self.main_widget)
def thorough_check(self): if not os.path.exists(self.filename) and not os.path.exists( self.filename + '.json') and not os.path.exists(self.filename + '.tar'): self.type = None return None if os.path.isdir(self.filename): self.type = 'directory' else: if self.filename.endswith('.tar'): # try to make it a tar data container try: self.object = schedule.TaskDataContainerTar( None, name=self.filename) except: raise else: self.type = 'silver.schedule.TaskDataContainerTar' if self.type is None: try: self.object = schedule.Session(None, self.filename) self.object.check_json() except: pass else: self.type = 'silver.schedule.Session' if self.type is None: try: self.object = schedule.Session(None, self.filename + '.json') self.object.check_json() except: pass else: self.filename = self.filename + '.json' self.type = 'silver.schedule.Session' if self.type is None: try: self.object = schedule.Experiment(self.filename) self.object.get_sandbox() except: pass else: self.type = 'silver.schedule.Experiment' return self.type
def to_lazy(self): self.thorough_check() if self.type == 'silver.schedule.Experiment': try: self.object = schedule.Experiment(self.filename) self.object.get_sandbox() except: pass else: print dir(self.object) sessions = [{ "session": s } for s in self.object.load_sessions()] print sessions obj_text = LazyTemplateNode(sessions, [ "<ul><list/></ul>", "<li><a href='/load/<session/>.json'><session/></a></li>" ]) return lazy.LazyPageObject([], self.filename + " (" + str(self.type) + ")<br/>" + str(obj_text) + "<hr/>") elif self.type == 'silver.schedule.Session': self.object = schedule.Session(None, self.filename) self.object.load() print type(self.object) #obj_text = str(self.object.__dict__)#.to_html() ks = [ 'name', 'data_path' ] #,'cmd','command','variables','data_path','data','parallel','blocked'] def r(node): _d = {} for k in ks: if k in node.__dict__: _d[k] = node.__dict__[k] if hasattr(node, 'subtasks') and node.subtasks is not None: _d['subtasks'] = [] for t in node.subtasks: _d['subtasks'].append(r(t)) return _d tree = r(self.object.root_task) obj_text = lazy.LazyPageObject( { 'filename': self.object.filename, 'tasks': lazy.LazyPageObject( tree, template= "<div class='task'><name/> (<a href='/load/<data_path/>.tar'>load Data</a>)<br/><div class='subtasks'><subtasks/></div></div>" ), 'root_task name': self.object.root_task.name, 'guess_total_time': self.object.guess_total_time(), 'commands': self.object.commands }, "<dict/>") return obj_text elif self.type == 'silver.schedule.TaskDataContainerTar': obj_text = str(self.object.__dict__.keys()) + self.object.to_html() else: obj_text = str(self.object) with open(self.filename, 'r') as f: obj_text = f.read( ) #lazy.LazyPageObject([obj_text, f.read()],"<list/>") return lazy.LazyPageObject([], self.filename + " (" + str(self.type) + ")<br/>" + str(obj_text) + "<hr/>")