Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
nni
Commits
44954e0c
Unverified
Commit
44954e0c
authored
Aug 12, 2020
by
Tab Zhang
Committed by
GitHub
Aug 12, 2020
Browse files
add nnictl command to list trial results with highest/lowest metric (#2747)
parent
10c177c2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
2 deletions
+30
-2
docs/en_US/Tutorial/Nnictl.md
docs/en_US/Tutorial/Nnictl.md
+5
-1
tools/nni_cmd/nnictl.py
tools/nni_cmd/nnictl.py
+2
-0
tools/nni_cmd/nnictl_utils.py
tools/nni_cmd/nnictl_utils.py
+23
-0
tools/nni_cmd/url_utils.py
tools/nni_cmd/url_utils.py
+0
-1
No files found.
docs/en_US/Tutorial/Nnictl.md
View file @
44954e0c
...
@@ -305,12 +305,14 @@ Debug mode will disable version check function in Trialkeeper.
...
@@ -305,12 +305,14 @@ Debug mode will disable version check function in Trialkeeper.
*
Description
*
Description
You can use this command to show trial's information.
You can use this command to show trial's information.
Note that if `head` or `tail` is set, only complete trials will be listed.
*
Usage
*
Usage
```bash
```bash
nnictl trial ls
nnictl trial ls
nnictl trial ls --head 10
nnictl trial ls --tail 10
```
```
*
Options
*
Options
...
@@ -318,6 +320,8 @@ Debug mode will disable version check function in Trialkeeper.
...
@@ -318,6 +320,8 @@ Debug mode will disable version check function in Trialkeeper.
|Name, shorthand|Required|Default|Description|
|Name, shorthand|Required|Default|Description|
|------|------|------ |------|
|------|------|------ |------|
|id| False| |ID of the experiment you want to set|
|id| False| |ID of the experiment you want to set|
|--head|False||the number of items to be listed with the highest default metric|
|--tail|False||the number of items to be listed with the lowest default metric|
*
__nnictl trial kill__
*
__nnictl trial kill__
...
...
tools/nni_cmd/nnictl.py
View file @
44954e0c
...
@@ -103,6 +103,8 @@ def parse_args():
...
@@ -103,6 +103,8 @@ def parse_args():
parser_trial_subparsers
=
parser_trial
.
add_subparsers
()
parser_trial_subparsers
=
parser_trial
.
add_subparsers
()
parser_trial_ls
=
parser_trial_subparsers
.
add_parser
(
'ls'
,
help
=
'list trial jobs'
)
parser_trial_ls
=
parser_trial_subparsers
.
add_parser
(
'ls'
,
help
=
'list trial jobs'
)
parser_trial_ls
.
add_argument
(
'id'
,
nargs
=
'?'
,
help
=
'the id of experiment'
)
parser_trial_ls
.
add_argument
(
'id'
,
nargs
=
'?'
,
help
=
'the id of experiment'
)
parser_trial_ls
.
add_argument
(
'--head'
,
type
=
int
,
help
=
'list the highest experiments on the default metric'
)
parser_trial_ls
.
add_argument
(
'--tail'
,
type
=
int
,
help
=
'list the lowest experiments on the default metric'
)
parser_trial_ls
.
set_defaults
(
func
=
trial_ls
)
parser_trial_ls
.
set_defaults
(
func
=
trial_ls
)
parser_trial_kill
=
parser_trial_subparsers
.
add_parser
(
'kill'
,
help
=
'kill trial jobs'
)
parser_trial_kill
=
parser_trial_subparsers
.
add_parser
(
'kill'
,
help
=
'kill trial jobs'
)
parser_trial_kill
.
add_argument
(
'id'
,
nargs
=
'?'
,
help
=
'the id of experiment'
)
parser_trial_kill
.
add_argument
(
'id'
,
nargs
=
'?'
,
help
=
'the id of experiment'
)
...
...
tools/nni_cmd/nnictl_utils.py
View file @
44954e0c
...
@@ -9,6 +9,7 @@ import time
...
@@ -9,6 +9,7 @@ import time
import
re
import
re
import
shutil
import
shutil
import
subprocess
import
subprocess
from
functools
import
cmp_to_key
from
datetime
import
datetime
,
timezone
from
datetime
import
datetime
,
timezone
from
pathlib
import
Path
from
pathlib
import
Path
from
subprocess
import
Popen
from
subprocess
import
Popen
...
@@ -248,6 +249,20 @@ def stop_experiment(args):
...
@@ -248,6 +249,20 @@ def stop_experiment(args):
def
trial_ls
(
args
):
def
trial_ls
(
args
):
'''List trial'''
'''List trial'''
def
final_metric_data_cmp
(
lhs
,
rhs
):
metric_l
=
json
.
loads
(
json
.
loads
(
lhs
[
'finalMetricData'
][
0
][
'data'
]))
metric_r
=
json
.
loads
(
json
.
loads
(
rhs
[
'finalMetricData'
][
0
][
'data'
]))
if
isinstance
(
metric_l
,
float
):
return
metric_l
-
metric_r
elif
isinstance
(
metric_l
,
dict
):
return
metric_l
[
'default'
]
-
metric_r
[
'default'
]
else
:
print_error
(
'Unexpected data format. Please check your data.'
)
raise
ValueError
if
args
.
head
and
args
.
tail
:
print_error
(
'Head and tail cannot be set at the same time.'
)
return
nni_config
=
Config
(
get_config_filename
(
args
))
nni_config
=
Config
(
get_config_filename
(
args
))
rest_port
=
nni_config
.
get_config
(
'restServerPort'
)
rest_port
=
nni_config
.
get_config
(
'restServerPort'
)
rest_pid
=
nni_config
.
get_config
(
'restServerPid'
)
rest_pid
=
nni_config
.
get_config
(
'restServerPid'
)
...
@@ -259,6 +274,14 @@ def trial_ls(args):
...
@@ -259,6 +274,14 @@ def trial_ls(args):
response
=
rest_get
(
trial_jobs_url
(
rest_port
),
REST_TIME_OUT
)
response
=
rest_get
(
trial_jobs_url
(
rest_port
),
REST_TIME_OUT
)
if
response
and
check_response
(
response
):
if
response
and
check_response
(
response
):
content
=
json
.
loads
(
response
.
text
)
content
=
json
.
loads
(
response
.
text
)
if
args
.
head
:
assert
args
.
head
>
0
,
'The number of requested data must be greater than 0.'
content
=
sorted
(
filter
(
lambda
x
:
'finalMetricData'
in
x
,
content
),
key
=
cmp_to_key
(
final_metric_data_cmp
),
reverse
=
True
)[:
args
.
head
]
elif
args
.
tail
:
assert
args
.
tail
>
0
,
'The number of requested data must be greater than 0.'
content
=
sorted
(
filter
(
lambda
x
:
'finalMetricData'
in
x
,
content
),
key
=
cmp_to_key
(
final_metric_data_cmp
))[:
args
.
tail
]
for
index
,
value
in
enumerate
(
content
):
for
index
,
value
in
enumerate
(
content
):
content
[
index
]
=
convert_time_stamp_to_date
(
value
)
content
[
index
]
=
convert_time_stamp_to_date
(
value
)
print
(
json
.
dumps
(
content
,
indent
=
4
,
sort_keys
=
True
,
separators
=
(
','
,
':'
)))
print
(
json
.
dumps
(
content
,
indent
=
4
,
sort_keys
=
True
,
separators
=
(
','
,
':'
)))
...
...
tools/nni_cmd/url_utils.py
View file @
44954e0c
...
@@ -28,7 +28,6 @@ def metric_data_url(port):
...
@@ -28,7 +28,6 @@ def metric_data_url(port):
'''get metric_data url'''
'''get metric_data url'''
return
'{0}:{1}{2}{3}'
.
format
(
BASE_URL
,
port
,
API_ROOT_URL
,
METRIC_DATA_API
)
return
'{0}:{1}{2}{3}'
.
format
(
BASE_URL
,
port
,
API_ROOT_URL
,
METRIC_DATA_API
)
def
check_status_url
(
port
):
def
check_status_url
(
port
):
'''get check_status url'''
'''get check_status url'''
return
'{0}:{1}{2}{3}'
.
format
(
BASE_URL
,
port
,
API_ROOT_URL
,
CHECK_STATUS_API
)
return
'{0}:{1}{2}{3}'
.
format
(
BASE_URL
,
port
,
API_ROOT_URL
,
CHECK_STATUS_API
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment