Unverified Commit 80e35db1 authored by SparkSnail's avatar SparkSnail Committed by GitHub
Browse files

Add time parser for 'nnictl update duration' (#632)

Current nnictl update duration only support seconds unit, add a parser for this command to support {s, m, h, d}
parent e0b7d205
...@@ -35,18 +35,18 @@ def parse_relative_path(root_path, experiment_config, key): ...@@ -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)) print_normal('expand %s: %s to %s ' % (key, experiment_config[key], absolute_path))
experiment_config[key] = absolute_path experiment_config[key] = absolute_path
def parse_time(experiment_config): def parse_time(time):
'''Parse time format''' '''Change the time to seconds'''
unit = experiment_config['maxExecDuration'][-1] unit = time[-1]
if unit not in ['s', 'm', 'h', 'd']: if unit not in ['s', 'm', 'h', 'd']:
print_error('the unit of time could only from {s, m, h, d}') print_error('the unit of time could only from {s, m, h, d}')
exit(1) exit(1)
time = experiment_config['maxExecDuration'][:-1] time = time[:-1]
if not time.isdigit(): if not time.isdigit():
print_error('time format error!') print_error('time format error!')
exit(1) exit(1)
parse_dict = {'s':1, 'm':60, 'h':3600, 'd':86400} 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): def parse_path(experiment_config, config_path):
'''Parse path in config file''' '''Parse path in config file'''
...@@ -216,7 +216,7 @@ def validate_all_content(experiment_config, config_path): ...@@ -216,7 +216,7 @@ def validate_all_content(experiment_config, config_path):
'''Validate whether experiment_config is valid''' '''Validate whether experiment_config is valid'''
parse_path(experiment_config, config_path) parse_path(experiment_config, config_path)
validate_common_content(experiment_config) validate_common_content(experiment_config)
parse_time(experiment_config) experiment_config['maxExecDuration'] = parse_time(experiment_config['maxExecDuration'])
if experiment_config.get('advisor'): if experiment_config.get('advisor'):
parse_advisor_content(experiment_config) parse_advisor_content(experiment_config)
validate_annotation_content(experiment_config, 'advisor', 'builtinAdvisorName') validate_annotation_content(experiment_config, 'advisor', 'builtinAdvisorName')
......
...@@ -73,7 +73,7 @@ def parse_args(): ...@@ -73,7 +73,7 @@ def parse_args():
parser_updater_concurrency.set_defaults(func=update_concurrency) parser_updater_concurrency.set_defaults(func=update_concurrency)
parser_updater_duration = parser_updater_subparsers.add_parser('duration', help='update duration') 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('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_duration.set_defaults(func=update_duration)
parser_updater_trialnum = parser_updater_subparsers.add_parser('trialnum', help='update maxtrialnum') 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') parser_updater_trialnum.add_argument('--id', '-i', dest='id', help='the id of experiment')
......
...@@ -26,6 +26,7 @@ from .url_utils import experiment_url ...@@ -26,6 +26,7 @@ from .url_utils import experiment_url
from .config_utils import Config from .config_utils import Config
from .common_utils import get_json_content from .common_utils import get_json_content
from .nnictl_utils import check_experiment_id, get_experiment_port, get_config_filename 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): def validate_digit(value, start, end):
'''validate if a digit is valid''' '''validate if a digit is valid'''
...@@ -92,7 +93,8 @@ def update_concurrency(args): ...@@ -92,7 +93,8 @@ def update_concurrency(args):
print('ERROR: update %s failed!' % 'concurrency') print('ERROR: update %s failed!' % 'concurrency')
def update_duration(args): 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) args.port = get_experiment_port(args)
if args.port is not None: if args.port is not None:
if update_experiment_profile(args, 'maxExecDuration', int(args.value)): if update_experiment_profile(args, 'maxExecDuration', int(args.value)):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment