Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Add time parser for 'nnictl update duration' (#632)
Browse files Browse the repository at this point in the history
Current nnictl update duration only support seconds unit, add a parser for this command to support {s, m, h, d}
  • Loading branch information
SparkSnail authored Jan 18, 2019
1 parent e0b7d20 commit 80e35db
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions tools/nni_cmd/launcher_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ def parse_relative_path(root_path, experiment_config, key):
print_normal('expand %s: %s to %s ' % (key, experiment_config[key], absolute_path))
experiment_config[key] = absolute_path

def parse_time(experiment_config):
'''Parse time format'''
unit = experiment_config['maxExecDuration'][-1]
def parse_time(time):
'''Change the time to seconds'''
unit = time[-1]
if unit not in ['s', 'm', 'h', 'd']:
print_error('the unit of time could only from {s, m, h, d}')
exit(1)
time = experiment_config['maxExecDuration'][:-1]
time = time[:-1]
if not time.isdigit():
print_error('time format error!')
exit(1)
parse_dict = {'s':1, 'm':60, 'h':3600, 'd':86400}
experiment_config['maxExecDuration'] = int(time) * parse_dict[unit]
return int(time) * parse_dict[unit]

def parse_path(experiment_config, config_path):
'''Parse path in config file'''
Expand Down Expand Up @@ -216,7 +216,7 @@ def validate_all_content(experiment_config, config_path):
'''Validate whether experiment_config is valid'''
parse_path(experiment_config, config_path)
validate_common_content(experiment_config)
parse_time(experiment_config)
experiment_config['maxExecDuration'] = parse_time(experiment_config['maxExecDuration'])
if experiment_config.get('advisor'):
parse_advisor_content(experiment_config)
validate_annotation_content(experiment_config, 'advisor', 'builtinAdvisorName')
Expand Down
2 changes: 1 addition & 1 deletion tools/nni_cmd/nnictl.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def parse_args():
parser_updater_concurrency.set_defaults(func=update_concurrency)
parser_updater_duration = parser_updater_subparsers.add_parser('duration', help='update duration')
parser_updater_duration.add_argument('id', nargs='?', help='the id of experiment')
parser_updater_duration.add_argument('--value', '-v', required=True)
parser_updater_duration.add_argument('--value', '-v', required=True, help='the unit of time should in {\'s\', \'m\', \'h\', \'d\'}')
parser_updater_duration.set_defaults(func=update_duration)
parser_updater_trialnum = parser_updater_subparsers.add_parser('trialnum', help='update maxtrialnum')
parser_updater_trialnum.add_argument('--id', '-i', dest='id', help='the id of experiment')
Expand Down
4 changes: 3 additions & 1 deletion tools/nni_cmd/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from .config_utils import Config
from .common_utils import get_json_content
from .nnictl_utils import check_experiment_id, get_experiment_port, get_config_filename
from .launcher_utils import parse_time

def validate_digit(value, start, end):
'''validate if a digit is valid'''
Expand Down Expand Up @@ -92,7 +93,8 @@ def update_concurrency(args):
print('ERROR: update %s failed!' % 'concurrency')

def update_duration(args):
validate_digit(args.value, 1, 999999999)
#parse time, change time unit to seconds
args.value = parse_time(args.value)
args.port = get_experiment_port(args)
if args.port is not None:
if update_experiment_profile(args, 'maxExecDuration', int(args.value)):
Expand Down

0 comments on commit 80e35db

Please sign in to comment.