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
b955ac99
Unverified
Commit
b955ac99
authored
Jun 01, 2021
by
Yuge Zhang
Committed by
GitHub
Jun 01, 2021
Browse files
Use PyYAML instead of ruamel.yaml (#3702)
parent
7075a836
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
18 additions
and
18 deletions
+18
-18
dependencies/required.txt
dependencies/required.txt
+1
-1
docs/requirements.txt
docs/requirements.txt
+1
-1
examples/trials/benchmarking/automlbenchmark/nni/extensions/NNI/tuners.py
...benchmarking/automlbenchmark/nni/extensions/NNI/tuners.py
+1
-1
nni/experiment/config/base.py
nni/experiment/config/base.py
+2
-2
nni/experiment/config/common.py
nni/experiment/config/common.py
+2
-2
nni/tools/nnictl/common_utils.py
nni/tools/nnictl/common_utils.py
+2
-2
nni/tools/package_utils/__init__.py
nni/tools/package_utils/__init__.py
+3
-3
test/config/tuners/gp.yml
test/config/tuners/gp.yml
+1
-1
test/nni_test/nnitest/run_tests.py
test/nni_test/nnitest/run_tests.py
+2
-2
test/nni_test/nnitest/utils.py
test/nni_test/nnitest/utils.py
+3
-3
No files found.
dependencies/required.txt
View file @
b955ac99
...
...
@@ -3,7 +3,7 @@ hyperopt == 0.1.2
json_tricks
netifaces
psutil
ruamel.
yaml
py
yaml
requests
responses
schema
...
...
docs/requirements.txt
View file @
b955ac99
...
...
@@ -20,7 +20,7 @@ websockets
filelock
prettytable
psutil
ruamel.
yaml
py
yaml
ipython
gym
tianshou
...
...
examples/trials/benchmarking/automlbenchmark/nni/extensions/NNI/tuners.py
View file @
b955ac99
...
...
@@ -18,7 +18,7 @@ def get_tuner_class_dict():
config_file
=
str
(
get_config_file
(
'registered_algorithms.yml'
))
if
os
.
path
.
exists
(
config_file
):
with
open
(
config_file
,
'r'
)
as
f
:
config
=
yaml
.
load
(
f
,
Loader
=
yaml
.
SafeL
oad
er
)
config
=
yaml
.
safe_l
oad
(
f
)
else
:
config
=
{}
ret
=
{}
...
...
nni/experiment/config/base.py
View file @
b955ac99
...
...
@@ -6,7 +6,7 @@ import dataclasses
from
pathlib
import
Path
from
typing
import
Any
,
Dict
,
Optional
,
Type
,
TypeVar
import
ruamel.yaml
as
yaml
import
yaml
from
.
import
util
...
...
@@ -72,7 +72,7 @@ class ConfigBase:
Load config from YAML (or JSON) file.
Keys in YAML file can either be camelCase or snake_case.
"""
data
=
yaml
.
load
(
open
(
path
)
,
Loader
=
yaml
.
SafeLoader
)
data
=
yaml
.
safe_
load
(
open
(
path
))
if
not
isinstance
(
data
,
dict
):
raise
ValueError
(
f
'Content of config file
{
path
}
is not a dict/object'
)
return
cls
(
**
data
,
_base_path
=
Path
(
path
).
parent
)
...
...
nni/experiment/config/common.py
View file @
b955ac99
...
...
@@ -5,7 +5,7 @@ from dataclasses import dataclass
from
pathlib
import
Path
from
typing
import
Any
,
Dict
,
List
,
Optional
,
Union
from
ruamel.yaml
import
YAML
import
yaml
from
.base
import
ConfigBase
,
PathLike
from
.
import
util
...
...
@@ -118,7 +118,7 @@ class ExperimentConfig(ConfigBase):
def
json
(
self
)
->
Dict
[
str
,
Any
]:
obj
=
super
().
json
()
if
obj
.
get
(
'searchSpaceFile'
):
obj
[
'searchSpace'
]
=
YAML
().
load
(
open
(
obj
.
pop
(
'searchSpaceFile'
)))
obj
[
'searchSpace'
]
=
yaml
.
safe_
load
(
open
(
obj
.
pop
(
'searchSpaceFile'
)))
return
obj
## End of public API ##
...
...
nni/tools/nnictl/common_utils.py
View file @
b955ac99
...
...
@@ -9,7 +9,7 @@ import time
import
socket
import
string
import
random
import
ruamel.yaml
as
yaml
import
yaml
import
psutil
import
filelock
import
glob
...
...
@@ -21,7 +21,7 @@ def get_yml_content(file_path):
'''Load yaml file content'''
try
:
with
open
(
file_path
,
'r'
)
as
file
:
return
yaml
.
load
(
file
,
Loader
=
yaml
.
SafeLoader
)
return
yaml
.
safe_
load
(
file
)
except
yaml
.
scanner
.
ScannerError
as
err
:
print_error
(
'yaml file format error!'
)
print_error
(
err
)
...
...
nni/tools/package_utils/__init__.py
View file @
b955ac99
...
...
@@ -6,7 +6,7 @@ import importlib
import
os
from
pathlib
import
Path
import
sys
import
ruamel.yaml
as
yaml
import
yaml
from
nni.runtime.config
import
get_config_file
ALGO_TYPES
=
[
'tuners'
,
'assessors'
,
'advisors'
]
...
...
@@ -215,7 +215,7 @@ def read_registerd_algo_meta():
config_file
=
get_registered_algo_config_path
()
if
os
.
path
.
exists
(
config_file
):
with
open
(
config_file
,
'r'
)
as
f
:
config
=
yaml
.
load
(
f
,
Loader
=
yaml
.
SafeL
oad
er
)
config
=
yaml
.
safe_l
oad
(
f
)
else
:
config
=
defaultdict
(
list
)
for
t
in
ALGO_TYPES
:
...
...
@@ -226,4 +226,4 @@ def read_registerd_algo_meta():
def
write_registered_algo_meta
(
config
):
config_file
=
get_registered_algo_config_path
()
with
open
(
config_file
,
'w'
)
as
f
:
f
.
write
(
yaml
.
dump
(
dict
(
config
),
default_flow_style
=
False
))
f
.
write
(
yaml
.
safe_
dump
(
dict
(
config
),
default_flow_style
=
False
))
test/config/tuners/gp.yml
View file @
b955ac99
...
...
@@ -13,7 +13,7 @@ tuner:
kappa
:
5.0
xi
:
0.0
nu
:
2.5
alpha
:
1e-6
alpha
:
1
.0
e-6
cold_start_num
:
10
selection_num_warm_up
:
100000
selection_num_starting_points
:
250
...
...
test/nni_test/nnitest/run_tests.py
View file @
b955ac99
...
...
@@ -9,7 +9,7 @@ import subprocess
import
sys
import
time
import
ruamel.yaml
as
yaml
import
yaml
import
validators
from
utils
import
(
CLEAR
,
EXPERIMENT_URL
,
GREEN
,
RED
,
REST_ENDPOINT
,
...
...
@@ -80,7 +80,7 @@ def prepare_config_file(test_case_config, it_config, args):
# generate temporary config yml file to launch experiment
new_config_file
=
config_path
+
'.tmp'
dump_yml_content
(
new_config_file
,
test_yml_config
)
print
(
yaml
.
dump
(
test_yml_config
,
default_flow_style
=
False
),
flush
=
True
)
print
(
yaml
.
safe_
dump
(
test_yml_config
,
default_flow_style
=
False
),
flush
=
True
)
return
new_config_file
...
...
test/nni_test/nnitest/utils.py
View file @
b955ac99
...
...
@@ -9,7 +9,7 @@ import sys
import
subprocess
import
requests
import
time
import
ruamel.yaml
as
yaml
import
yaml
import
shlex
EXPERIMENT_DONE_SIGNAL
=
'Experiment done'
...
...
@@ -43,12 +43,12 @@ def remove_files(file_list):
def
get_yml_content
(
file_path
):
'''Load yaml file content'''
with
open
(
file_path
,
'r'
)
as
file
:
return
yaml
.
load
(
file
,
Loader
=
yaml
.
Loader
)
return
yaml
.
safe_
load
(
file
)
def
dump_yml_content
(
file_path
,
content
):
'''Dump yaml file content'''
with
open
(
file_path
,
'w'
)
as
file
:
file
.
write
(
yaml
.
dump
(
content
,
default_flow_style
=
False
))
file
.
write
(
yaml
.
safe_
dump
(
content
,
default_flow_style
=
False
))
def
setup_experiment
(
installed
=
True
):
'''setup the experiment if nni is not installed'''
...
...
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