-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #517 from AllenInstitute/analysis
Running bootstraps on hpc
- Loading branch information
Showing
5 changed files
with
282 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import os | ||
import argparse | ||
import time | ||
import pandas as pd | ||
|
||
from simple_slurm import Slurm | ||
import visual_behavior_glm.PSTH as psth | ||
|
||
parser = argparse.ArgumentParser(description='deploy glm fits to cluster') | ||
parser.add_argument('--env-path', type=str, default='visual_behavior', metavar='path to conda environment to use') | ||
|
||
|
||
def already_fit(row): | ||
filename = psth.get_hierarchy_filename( | ||
row.cell_type, | ||
row.response, | ||
row['data'], | ||
'all', | ||
row.nboots, | ||
['visual_strategy_session'], | ||
'running_{}'.format(row.bin_num)) | ||
return os.path.exists(filename) | ||
|
||
def get_bootstrap_jobs(): | ||
nboots=10000 | ||
base_jobs = [ | ||
{'cell_type':'exc','response':'image','data':'events','nboots':nboots}, | ||
{'cell_type':'sst','response':'image','data':'events','nboots':nboots}, | ||
{'cell_type':'vip','response':'image','data':'events','nboots':nboots}, | ||
{'cell_type':'exc','response':'omission','data':'events','nboots':nboots}, | ||
{'cell_type':'sst','response':'omission','data':'events','nboots':nboots}, | ||
{'cell_type':'vip','response':'omission','data':'events','nboots':nboots} | ||
] | ||
jobs = [] | ||
for b in range(-5,21): | ||
for j in base_jobs: | ||
temp = j.copy() | ||
temp['bin_num'] = b | ||
jobs.append(temp) | ||
jobs = pd.DataFrame(jobs) | ||
return jobs | ||
|
||
def make_job_string(row): | ||
arg_string = '' | ||
arg_string += ' --cell_type {}'.format(row.cell_type) | ||
arg_string += ' --response {}'.format(row.response) | ||
arg_string += ' --data {}'.format(row['data']) | ||
arg_string += ' --bin_num {}'.format(row.bin_num) | ||
arg_string += ' --nboots {}'.format(row.nboots) | ||
return arg_string | ||
|
||
if __name__ == "__main__": | ||
args = parser.parse_args() | ||
python_executable = "{}/bin/python".format(args.env_path) | ||
print('python executable = {}'.format(python_executable)) | ||
python_file = "/home/alex.piet/codebase/GLM/visual_behavior_glm/scripts/running_bootstrap.py" | ||
stdout_basedir = "/allen/programs/braintv/workgroups/nc-ophys/visual_behavior/ophys_glm" | ||
stdout_location = os.path.join(stdout_basedir, 'job_records_running_bootstraps') | ||
if not os.path.exists(stdout_location): | ||
print('making folder {}'.format(stdout_location)) | ||
os.mkdir(stdout_location) | ||
print('stdout files will be at {}'.format(stdout_location)) | ||
|
||
job_count = 0 | ||
jobs = get_bootstrap_jobs() | ||
|
||
for index, row in jobs.iterrows(): | ||
if not already_fit(row): | ||
job_count += 1 | ||
args_string = make_job_string(row) | ||
print('starting cluster job. job count = {}'.format(job_count)) | ||
print(' ' + args_string) | ||
job_title = 'bootstraps' | ||
walltime = '24:00:00' | ||
mem = '100gb' | ||
job_id = Slurm.JOB_ARRAY_ID | ||
job_array_id = Slurm.JOB_ARRAY_MASTER_ID | ||
output = stdout_location+"/"+str(job_array_id)+"_"+str(job_id)+"_bootstrap.out" | ||
|
||
# instantiate a SLURM object | ||
slurm = Slurm( | ||
cpus_per_task=4, | ||
job_name=job_title, | ||
time=walltime, | ||
mem=mem, | ||
output= output, | ||
partition="braintv" | ||
) | ||
|
||
slurm.sbatch('{} {} {}'.format( | ||
python_executable, | ||
python_file, | ||
args_string, | ||
) | ||
) | ||
time.sleep(0.001) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
# Make sure you run conda activate <env> first | ||
# to run this from an environment where the allenSDK is installed | ||
|
||
python deploy_running_bootstraps.py --env-path /home/alex.piet/codebase/miniconda3/envs/visbeh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import visual_behavior_glm.PSTH as psth | ||
import psy_output_tools as po | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description='compute hierarchy bootstraps') | ||
parser.add_argument( | ||
'--cell_type', | ||
type=str, | ||
default='', | ||
metavar='cell', | ||
help='cell_type' | ||
) | ||
parser.add_argument( | ||
'--response', | ||
type=str, | ||
default='', | ||
metavar='response', | ||
help='response' | ||
) | ||
|
||
parser.add_argument( | ||
'--data', | ||
type=str, | ||
default='', | ||
metavar='', | ||
help='data' | ||
) | ||
|
||
parser.add_argument( | ||
'--nboots', | ||
type=int, | ||
default=0, | ||
metavar='', | ||
help='data' | ||
) | ||
|
||
parser.add_argument( | ||
'--bin_num', | ||
type=int, | ||
default=0, | ||
metavar='', | ||
help='data' | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
args = parser.parse_args() | ||
print('Starting bootstrap with the following inputs') | ||
print('cell_type {}'.format(args.cell_type)) | ||
print('response {}'.format(args.response)) | ||
print('data {}'.format(args.data)) | ||
print('nboots {}'.format(args.nboots)) | ||
print('bin_num {}'.format(args.bin_num)) | ||
print('') | ||
summary_df = po.get_ophys_summary_table(21) | ||
psth.load_df_and_compute_running( | ||
summary_df, | ||
args.cell_type, | ||
args.response, | ||
args.data, | ||
args.nboots, | ||
args.bin_num | ||
) | ||
print('finished') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters