def run_remotely(command, task, remote_dir, runtime='01:00:00', submit_helper=uclClusterSubmit): variables = {} task_full = '%s_%s'%(task, time.ctime().replace(' ','_' ).replace(':','.' )) variables['command'] = command variables['task'] = task_full variables['remote_dir'] = remote_dir variables['runtime'] = runtime t = Template(submit_helper.template) contents = t.render(variables) tmp_script_name = 'submit_%s'%(task_full) tmp_script = open(tmp_script_name,'w') tmp_script.write(contents) tmp_script.close() ''' print("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") print(contents) print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")''' scp_cmd = 'scp "%s" "%s@%s:%s"' % (tmp_script_name, submit_helper.username, submit_helper.host, remote_dir) print execute_command_in_dir(scp_cmd, '.', True) ssh_cmd = "ssh %s@%s \"cd %s;/bin/bash -ci 'qsub %s'\"" % (submit_helper.username, submit_helper.host, remote_dir, tmp_script_name) print execute_command_in_dir(ssh_cmd, '.', True) return tmp_script_name
def run_remotely(command, task, remote_dir, runtime='01:00:00', submit_helper=uclClusterSubmit): variables = {} task_full = '%s_%s' % (task, time.ctime().replace(' ', '_').replace( ':', '.')) variables['command'] = command variables['task'] = task_full variables['remote_dir'] = remote_dir variables['runtime'] = runtime t = Template(submit_helper.template) contents = t.render(variables) tmp_script_name = 'submit_%s' % (task_full) tmp_script = open(tmp_script_name, 'w') tmp_script.write(contents) tmp_script.close() ''' print("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") print(contents) print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")''' scp_cmd = 'scp "%s" "%s@%s:%s"' % (tmp_script_name, submit_helper.username, submit_helper.host, remote_dir) print execute_command_in_dir(scp_cmd, '.', True) ssh_cmd = "ssh %s@%s \"cd %s;/bin/bash -ci 'qsub %s'\"" % ( submit_helper.username, submit_helper.host, remote_dir, tmp_script_name) print execute_command_in_dir(ssh_cmd, '.', True) return tmp_script_name
def run(a=None, **kwargs): try: import neuroml import pyneuroml import xlrd except Exception as e: print_("Cannot import one of the required packages. Please install!\n" "Exception: %s\n" % e) try: if os.environ.has_key('C302_HOME'): os.environ['C302_HOME'] sys.path.append(os.environ['C302_HOME']) print_('Python path now: %s' % sys.path) import c302 import c302_utils except Exception as e: print_( "Cannot import c302!\n" "Exception: %s\n" % e + "Please set environment variable C302_HOME to point to the directory: CElegansNeuroML/CElegans/pythonScripts/c302!\n" ) exit() a = build_namespace(a, **kwargs) gen_start = time.time() ref = a.reference if not os.path.isdir('simulations'): os.mkdir('simulations') sim_ref = "%s_%s_%s" % (a.c302params, ref, time.ctime().replace( ' ', '_').replace(':', '.')) sim_dir = "simulations/%s" % (sim_ref) os.mkdir(sim_dir) #exec('from %s import ParameterisedModel'%a.c302params) #params = ParameterisedModel() id = '%s_%s' % (a.c302params, ref) exec('from c302_%s import setup' % ref) setup(a.c302params, generate=True, duration=a.duration, dt=a.dt, target_directory=sim_dir) lems_file0 = '%s/LEMS_c302_%s.xml' % (sim_dir, id) lems_file = '%s/LEMS_c302.xml' % (sim_dir) print_("Renaming %s -> %s" % (lems_file0, lems_file)) os.rename(lems_file0, lems_file) announce("Generating NEURON files from: %s..." % lems_file) pynml.run_lems_with_jneuroml_neuron(lems_file, only_generate_scripts=True, nogui=True, load_saved_data=False, verbose=True) main_nrn_py = open('%s/LEMS_c302_nrn.py' % (sim_dir), 'r') updated = '' for line in main_nrn_py: line = line.replace('GenericCell.hoc', '%s/GenericCell.hoc' % sim_dir) line = line.replace('GenericNeuronCell.hoc', '%s/GenericNeuronCell.hoc' % sim_dir) line = line.replace('GenericMuscleCell.hoc', '%s/GenericMuscleCell.hoc' % sim_dir) line = line.replace("open('time.dat", "open('%s/time.dat" % sim_dir) line = line.replace("open('c302_", "open('%s/c302_" % sim_dir) updated += line main_nrn_py.close() main_nrn_py = open('%s/LEMS_c302_nrn.py' % (sim_dir), 'w') main_nrn_py.write(updated) main_nrn_py.close() run_dir = '.' command = 'nrnivmodl %s' % sim_dir announce("Compiling NMODL files for NEURON...") pynml.execute_command_in_dir(command, run_dir, prefix="nrnivmodl: ") command = './Release/Sibernetic -c302 -f worm -no_g -l_to lpath=%s timelimit=%s timestep=%s' % ( sim_dir, a.duration / 1000.0, a.dt / 1000) env = {"PYTHONPATH": "./src:./%s" % sim_dir} sim_start = time.time() announce( "Executing main Sibernetic simulation of %sms using: \n\n %s \n\n in %s with %s" % (a.duration, command, run_dir, env)) #pynml.execute_command_in_dir('env', run_dir, prefix="Sibernetic: ",env=env,verbose=True) pynml.execute_command_in_dir(command, run_dir, prefix="Sibernetic: ", env=env, verbose=True) sim_end = time.time() reportj = {} reportj['duration'] = '%s ms' % a.duration reportj['dt'] = '%s ms' % a.dt reportj['sim_ref'] = sim_ref reportj['reference'] = a.reference reportj['c302params'] = a.c302params reportj['generation_time'] = '%s s' % (sim_start - gen_start) reportj['run_time'] = '%s s' % (sim_end - sim_start) reportj['command'] = '%s' % (command) report_file = open("%s/report.json" % sim_dir, 'w') report_file.write(pp.pformat(reportj)) report_file.close() announce("Generating images for neuronal activity...") results = pynml.reload_saved_data(lems_file, plot=False, show_plot_already=False, simulator=None, verbose=True) c302_utils.plot_c302_results(results, config=a.reference, parameter_set=a.c302params, directory=sim_dir, save=True, show_plot_already=False) pos_file_name = os.path.abspath('%s/position_buffer.txt' % sim_dir) announce("Plotting positions of worm body particles in %s..." % pos_file_name) from plot_positions import plot_positions if not os.path.isfile(pos_file_name): time.sleep(2) plot_positions(pos_file_name, rate_to_plot=int(a.duration / 5)) announce("Finished in %s sec!\n\nSimulation saved in: %s\n\n"%((sim_end-sim_start),sim_dir) + \ "Report of simulation at: %s/report.json\n\n"%(sim_dir)+ \ "Rerun simulation with: ./Release/Sibernetic -l_from lpath=%s\n"%(sim_dir))
def run(a=None,**kwargs): try: import neuroml import pyneuroml import xlrd except Exception as e: print_("Cannot import one of the required packages. Please install!\n" "Exception: %s\n"%e) try: if os.environ.has_key('C302_HOME'): os.environ['C302_HOME'] sys.path.append(os.environ['C302_HOME']) print_('Python path now: %s'%sys.path) import c302 import c302_utils except Exception as e: print_("Cannot import c302!\n" "Exception: %s\n"%e +"Please set environment variable C302_HOME to point to the directory: CElegansNeuroML/CElegans/pythonScripts/c302!\n") exit() a = build_namespace(a,**kwargs) gen_start = time.time() ref = a.reference if not os.path.isdir('simulations'): os.mkdir('simulations') sim_ref = "%s_%s_%s"%(a.c302params,ref, time.ctime().replace(' ','_' ).replace(':','.' )) sim_dir = "simulations/%s"%(sim_ref) os.mkdir(sim_dir) #exec('from %s import ParameterisedModel'%a.c302params) #params = ParameterisedModel() id = '%s_%s'%(a.c302params,ref) exec('from c302_%s import setup'%ref) setup(a.c302params, generate=True, duration = a.duration, dt = a.dt, target_directory=sim_dir) lems_file0 = '%s/LEMS_c302_%s.xml'%(sim_dir,id) lems_file = '%s/LEMS_c302.xml'%(sim_dir) print_("Renaming %s -> %s"%(lems_file0,lems_file)) os.rename(lems_file0,lems_file) announce("Generating NEURON files from: %s..."%lems_file) pynml.run_lems_with_jneuroml_neuron(lems_file, only_generate_scripts=True, nogui=True, load_saved_data=False, verbose=True) main_nrn_py = open('%s/LEMS_c302_nrn.py'%(sim_dir),'r') updated ='' for line in main_nrn_py: line = line.replace('GenericCell.hoc','%s/GenericCell.hoc'%sim_dir) line = line.replace('GenericNeuronCell.hoc','%s/GenericNeuronCell.hoc'%sim_dir) line = line.replace('GenericMuscleCell.hoc','%s/GenericMuscleCell.hoc'%sim_dir) line = line.replace("open('time.dat","open('%s/time.dat"%sim_dir) line = line.replace("open('c302_","open('%s/c302_"%sim_dir) updated += line main_nrn_py.close() main_nrn_py = open('%s/LEMS_c302_nrn.py'%(sim_dir),'w') main_nrn_py.write(updated) main_nrn_py.close() run_dir = '.' command = 'nrnivmodl %s'%sim_dir announce("Compiling NMODL files for NEURON...") pynml.execute_command_in_dir(command, run_dir, prefix="nrnivmodl: ") command = './Release/Sibernetic -c302 -f worm -no_g -l_to lpath=%s timelimit=%s timestep=%s'%(sim_dir,a.duration/1000.0,a.dt/1000) env={"PYTHONPATH":"./src:./%s"%sim_dir} sim_start = time.time() announce("Executing main Sibernetic simulation of %sms using: \n\n %s \n\n in %s with %s"%(a.duration, command, run_dir, env)) #pynml.execute_command_in_dir('env', run_dir, prefix="Sibernetic: ",env=env,verbose=True) pynml.execute_command_in_dir(command, run_dir, prefix="Sibernetic: ",env=env,verbose=True) sim_end = time.time() reportj = {} reportj['duration'] = '%s ms'%a.duration reportj['dt'] = '%s ms'%a.dt reportj['sim_ref'] = sim_ref reportj['reference'] = a.reference reportj['c302params'] = a.c302params reportj['generation_time'] = '%s s'%(sim_start-gen_start) reportj['run_time'] = '%s s'%(sim_end-sim_start) reportj['command'] = '%s'%(command) report_file = open("%s/report.json"%sim_dir,'w') report_file.write(pp.pformat(reportj)) report_file.close() announce("Generating images for neuronal activity...") results = pynml.reload_saved_data(lems_file, plot=False, show_plot_already=False, simulator=None, verbose=True) c302_utils.plot_c302_results(results, config=a.reference, parameter_set=a.c302params, directory=sim_dir, save=True, show_plot_already=False) pos_file_name = os.path.abspath('%s/position_buffer.txt'%sim_dir) announce("Plotting positions of worm body particles in %s..."%pos_file_name) from plot_positions import plot_positions if not os.path.isfile(pos_file_name): time.sleep(2) plot_positions(pos_file_name,rate_to_plot = int(a.duration/5)) announce("Finished in %s sec!\n\nSimulation saved in: %s\n\n"%((sim_end-sim_start),sim_dir) + \ "Report of simulation at: %s/report.json\n\n"%(sim_dir)+ \ "Rerun simulation with: ./Release/Sibernetic -l_from lpath=%s\n"%(sim_dir))