Unverified Commit b955ac99 authored by Yuge Zhang's avatar Yuge Zhang Committed by GitHub
Browse files

Use PyYAML instead of ruamel.yaml (#3702)

parent 7075a836
......@@ -3,7 +3,7 @@ hyperopt == 0.1.2
json_tricks
netifaces
psutil
ruamel.yaml
pyyaml
requests
responses
schema
......
......@@ -20,7 +20,7 @@ websockets
filelock
prettytable
psutil
ruamel.yaml
pyyaml
ipython
gym
tianshou
......
......@@ -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.SafeLoader)
config = yaml.safe_load(f)
else:
config = {}
ret = {}
......
......@@ -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)
......
......@@ -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 ##
......
......@@ -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)
......
......@@ -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.SafeLoader)
config = yaml.safe_load(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))
......@@ -13,7 +13,7 @@ tuner:
kappa: 5.0
xi: 0.0
nu: 2.5
alpha: 1e-6
alpha: 1.0e-6
cold_start_num: 10
selection_num_warm_up: 100000
selection_num_starting_points: 250
......
......@@ -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
......
......@@ -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'''
......
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