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
62d74565
Unverified
Commit
62d74565
authored
Apr 30, 2020
by
Yan Ni
Committed by
GitHub
Apr 30, 2020
Browse files
fix trial export (#2303)
parent
2b77ab2d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
4 deletions
+41
-4
test/config/integration_tests.yml
test/config/integration_tests.yml
+16
-0
test/nni_test/nnitest/validators.py
test/nni_test/nnitest/validators.py
+20
-0
tools/nni_cmd/nnictl_utils.py
tools/nni_cmd/nnictl_utils.py
+5
-4
No files found.
test/config/integration_tests.yml
View file @
62d74565
...
@@ -77,6 +77,14 @@ testCases:
...
@@ -77,6 +77,14 @@ testCases:
kwargs
:
kwargs
:
expected_result_file
:
expected_metrics.json
expected_result_file
:
expected_metrics.json
-
name
:
export-float
configFile
:
test/config/metrics_test/config.yml
config
:
maxTrialNum
:
1
trialConcurrency
:
1
validator
:
class
:
ExportValidator
-
name
:
metrics-dict
-
name
:
metrics-dict
configFile
:
test/config/metrics_test/config_dict_metrics.yml
configFile
:
test/config/metrics_test/config_dict_metrics.yml
config
:
config
:
...
@@ -87,6 +95,14 @@ testCases:
...
@@ -87,6 +95,14 @@ testCases:
kwargs
:
kwargs
:
expected_result_file
:
expected_metrics_dict.json
expected_result_file
:
expected_metrics_dict.json
-
name
:
export-dict
configFile
:
test/config/metrics_test/config_dict_metrics.yml
config
:
maxTrialNum
:
1
trialConcurrency
:
1
validator
:
class
:
ExportValidator
-
name
:
nnicli
-
name
:
nnicli
configFile
:
test/config/examples/sklearn-regression.yml
configFile
:
test/config/examples/sklearn-regression.yml
config
:
config
:
...
...
test/nni_test/nnitest/validators.py
View file @
62d74565
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
# Licensed under the MIT license.
# Licensed under the MIT license.
import
os.path
as
osp
import
os.path
as
osp
from
os
import
remove
import
subprocess
import
json
import
json
import
requests
import
requests
import
nnicli
as
nc
import
nnicli
as
nc
...
@@ -12,6 +14,24 @@ class ITValidator:
...
@@ -12,6 +14,24 @@ class ITValidator:
def
__call__
(
self
,
rest_endpoint
,
experiment_dir
,
nni_source_dir
,
**
kwargs
):
def
__call__
(
self
,
rest_endpoint
,
experiment_dir
,
nni_source_dir
,
**
kwargs
):
pass
pass
class
ExportValidator
(
ITValidator
):
def
__call__
(
self
,
rest_endpoint
,
experiment_dir
,
nni_source_dir
,
**
kwargs
):
exp_id
=
osp
.
split
(
experiment_dir
)[
-
1
]
proc1
=
subprocess
.
run
([
"nnictl"
,
"experiment"
,
"export"
,
exp_id
,
"-t"
,
"csv"
,
"-f"
,
"report.csv"
])
assert
proc1
.
returncode
==
0
,
'`nnictl experiment export -t csv` failed with code %d'
%
proc1
.
returncode
with
open
(
"report.csv"
,
'r'
)
as
f
:
print
(
'Exported CSV file:
\n
'
)
print
(
''
.
join
(
f
.
readlines
()))
print
(
'
\n\n
'
)
remove
(
'report.csv'
)
proc2
=
subprocess
.
run
([
"nnictl"
,
"experiment"
,
"export"
,
exp_id
,
"-t"
,
"json"
,
"-f"
,
"report.json"
])
assert
proc2
.
returncode
==
0
,
'`nnictl experiment export -t json` failed with code %d'
%
proc2
.
returncode
with
open
(
"report.json"
,
'r'
)
as
f
:
print
(
'Exported JSON file:
\n
'
)
print
(
'
\n
'
.
join
(
f
.
readlines
()))
print
(
'
\n\n
'
)
remove
(
'report.json'
)
class
MetricsValidator
(
ITValidator
):
class
MetricsValidator
(
ITValidator
):
def
__call__
(
self
,
rest_endpoint
,
experiment_dir
,
nni_source_dir
,
**
kwargs
):
def
__call__
(
self
,
rest_endpoint
,
experiment_dir
,
nni_source_dir
,
**
kwargs
):
...
...
tools/nni_cmd/nnictl_utils.py
View file @
62d74565
...
@@ -699,12 +699,13 @@ def export_trials_data(args):
...
@@ -699,12 +699,13 @@ def export_trials_data(args):
content
=
json
.
loads
(
response
.
text
)
content
=
json
.
loads
(
response
.
text
)
trial_records
=
[]
trial_records
=
[]
for
record
in
content
:
for
record
in
content
:
if
not
isinstance
(
record
[
'value'
],
(
float
,
int
)):
record_value
=
json
.
loads
(
record
[
'value'
])
formated_record
=
{
**
record
[
'parameter'
],
**
record
[
'value'
],
**
{
'id'
:
record
[
'id'
]}}
if
not
isinstance
(
record_value
,
(
float
,
int
)):
formated_record
=
{
**
record
[
'parameter'
],
**
record_value
,
**
{
'id'
:
record
[
'id'
]}}
else
:
else
:
formated_record
=
{
**
record
[
'parameter'
],
**
{
'reward'
:
record
[
'
value
'
]
,
'id'
:
record
[
'id'
]}}
formated_record
=
{
**
record
[
'parameter'
],
**
{
'reward'
:
record
_
value
,
'id'
:
record
[
'id'
]}}
trial_records
.
append
(
formated_record
)
trial_records
.
append
(
formated_record
)
with
open
(
args
.
path
,
'w'
)
as
file
:
with
open
(
args
.
path
,
'w'
,
newline
=
''
)
as
file
:
writer
=
csv
.
DictWriter
(
file
,
set
.
union
(
*
[
set
(
r
.
keys
())
for
r
in
trial_records
]))
writer
=
csv
.
DictWriter
(
file
,
set
.
union
(
*
[
set
(
r
.
keys
())
for
r
in
trial_records
]))
writer
.
writeheader
()
writer
.
writeheader
()
writer
.
writerows
(
trial_records
)
writer
.
writerows
(
trial_records
)
...
...
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