Skip to content

Commit

Permalink
Feature/local execution (#178)
Browse files Browse the repository at this point in the history
* Delete old evaluation notebook

* Add local execution parameter

* FiX
  • Loading branch information
felixmzd authored and jrebstadt committed Oct 24, 2018
1 parent b936984 commit e410368
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions deep_bottleneck/run_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def main():
create_output_directory()
args = parse_command_line_args()
start_experiments(args.configpath)
start_experiments(args.configpath, bool(args.local_execution))


def create_output_directory():
Expand All @@ -20,37 +20,42 @@ def parse_command_line_args():
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--configpath',
help='The folder containing the experiment configurations or a single configuration file.')
parser.add_argument('-l', '--local_execution',
default=False,
help='Whether the experiments should be run locally or on the grid.')
args = parser.parse_args()
return args


def start_experiments(config_dir_or_file):
def start_experiments(config_dir_or_file, local_execution):
"""Recursively walk through the config dir and submit all experiment
configurations in there to the grid.
"""
n_experiments = 0
if os.path.isdir(config_dir_or_file):
for root, _, files in os.walk(config_dir_or_file):
for file in files:
start_experiment(root, file)
start_experiment(root, file, local_execution)
n_experiments += 1

else:
root, file = os.path.split(config_dir_or_file)
start_experiment(root, file)
start_experiment(root, file, local_execution)
n_experiments += 1

print(f'Submitted {n_experiments} experiments.')


def start_experiment(root, file):
def start_experiment(root, file, local_execution):
submission_name, extension = os.path.splitext(file)
is_valid_config_file = extension == '.json'
if is_valid_config_file:
config_path = os.path.join(root, file)
experiment_name, _ = os.path.splitext(config_path)

command = f'qsub -N {submission_name} experiment.sge {experiment_name} {config_path}'
if local_execution:
command = f'python experiment.py --name {experiment_name} with {config_path} seed=0'
else:
command = f'qsub -N {submission_name} experiment.sge {experiment_name} {config_path}'
print(f'Executing command: {command}')
os.system(command)

Expand Down

0 comments on commit e410368

Please sign in to comment.