@@ -118,12 +118,14 @@ def check_experiment_id(args, update=True):
118118
119119def parse_ids (args ):
120120 '''Parse the arguments for nnictl stop
121- 1.If there is an id specified, return the corresponding id
122- 2.If there is no id specified, and there is an experiment running, return the id, or return Error
123- 3.If the id matches an experiment, nnictl will return the id.
124- 4.If the id ends with *, nnictl will match all ids matchs the regular
125- 5.If the id does not exist but match the prefix of an experiment id, nnictl will return the matched id
126- 6.If the id does not exist but match multiple prefix of the experiment ids, nnictl will give id information
121+ 1.If port is provided and id is not specified, return the id who owns the port
122+ 2.If both port and id are provided, return the id if it owns the port, otherwise fail
123+ 3.If there is an id specified, return the corresponding id
124+ 4.If there is no id specified, and there is an experiment running, return the id, or return Error
125+ 5.If the id matches an experiment, nnictl will return the id.
126+ 6.If the id ends with *, nnictl will match all ids matchs the regular
127+ 7.If the id does not exist but match the prefix of an experiment id, nnictl will return the matched id
128+ 8.If the id does not exist but match multiple prefix of the experiment ids, nnictl will give id information
127129 '''
128130 update_experiment ()
129131 experiment_config = Experiments ()
@@ -140,7 +142,14 @@ def parse_ids(args):
140142 elif isinstance (experiment_dict [key ], list ):
141143 # if the config file is old version, remove the configuration from file
142144 experiment_config .remove_experiment (key )
143- if not args .id :
145+ if args .port is not None :
146+ for key in running_experiment_list :
147+ if str (experiment_dict [key ]['port' ]) == args .port :
148+ result_list .append (key )
149+ if args .id and result_list and args .id != result_list [0 ]:
150+ print_error ('Experiment id and resful server port not match' )
151+ exit (1 )
152+ elif not args .id :
144153 if len (running_experiment_list ) > 1 :
145154 print_error ('There are multiple experiments, please set the experiment id...' )
146155 experiment_information = ""
@@ -166,8 +175,8 @@ def parse_ids(args):
166175 if len (result_list ) > 1 :
167176 print_error (args .id + ' is ambiguous, please choose ' + ' ' .join (result_list ) )
168177 return None
169- if not result_list and args .id and args .id != 'all' :
170- print_error ('There are no experiments matched, please set correct experiment id... ' )
178+ if not result_list and (( args .id and args .id != 'all' ) or args . port ) :
179+ print_error ('There are no experiments matched, please set correct experiment id or restful server port ' )
171180 elif not result_list :
172181 print_error ('There is no experiment running...' )
173182 return result_list
@@ -665,4 +674,4 @@ def export_trials_data(args):
665674 else :
666675 print_error ('Export failed...' )
667676 else :
668- print_error ('Restful server is not Running' )
677+ print_error ('Restful server is not Running' )
0 commit comments