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
b4559f60
Unverified
Commit
b4559f60
authored
May 20, 2022
by
liuzhe-lz
Committed by
GitHub
May 20, 2022
Browse files
Fix issue 4810 (#4866)
parent
efd8c7c8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
2 deletions
+22
-2
nni/algorithms/hpo/tpe_tuner.py
nni/algorithms/hpo/tpe_tuner.py
+1
-1
nni/common/serializer.py
nni/common/serializer.py
+8
-1
test/ut/sdk/test_serializer.py
test/ut/sdk/test_serializer.py
+13
-0
No files found.
nni/algorithms/hpo/tpe_tuner.py
View file @
b4559f60
...
@@ -171,7 +171,7 @@ class TpeTuner(Tuner):
...
@@ -171,7 +171,7 @@ class TpeTuner(Tuner):
def
generate_parameters
(
self
,
parameter_id
,
**
kwargs
):
def
generate_parameters
(
self
,
parameter_id
,
**
kwargs
):
if
self
.
liar
and
self
.
_running_params
:
if
self
.
liar
and
self
.
_running_params
:
# give a fake loss for each concurrently running paramater set
# give a fake loss for each concurrently running paramater set
history
=
{
key
:
records
.
copy
()
for
key
,
records
in
self
.
_history
.
items
()}
# copy history
history
=
defaultdict
(
list
,
{
key
:
records
.
copy
()
for
key
,
records
in
self
.
_history
.
items
()}
)
# copy history
lie
=
self
.
liar
.
lie
()
lie
=
self
.
liar
.
lie
()
for
param
in
self
.
_running_params
.
values
():
for
param
in
self
.
_running_params
.
values
():
for
key
,
value
in
param
.
items
():
for
key
,
value
in
param
.
items
():
...
...
nni/common/serializer.py
View file @
b4559f60
...
@@ -392,7 +392,8 @@ def _dump(*, obj: Any, fp: Optional[Any], use_trace: bool, pickle_size_limit: in
...
@@ -392,7 +392,8 @@ def _dump(*, obj: Any, fp: Optional[Any], use_trace: bool, pickle_size_limit: in
return
json_tricks
.
dumps
(
obj
,
obj_encoders
=
encoders
,
**
json_tricks_kwargs
)
return
json_tricks
.
dumps
(
obj
,
obj_encoders
=
encoders
,
**
json_tricks_kwargs
)
def
load
(
string
:
Optional
[
str
]
=
None
,
*
,
fp
:
Optional
[
Any
]
=
None
,
ignore_comments
:
bool
=
True
,
**
json_tricks_kwargs
)
->
Any
:
def
load
(
string
:
Optional
[
str
]
=
None
,
*
,
fp
:
Optional
[
Any
]
=
None
,
preserve_order
:
bool
=
False
,
ignore_comments
:
bool
=
True
,
**
json_tricks_kwargs
)
->
Any
:
"""
"""
Load the string or from file, and convert it to a complex data structure.
Load the string or from file, and convert it to a complex data structure.
At least one of string or fp has to be not none.
At least one of string or fp has to be not none.
...
@@ -403,6 +404,10 @@ def load(string: Optional[str] = None, *, fp: Optional[Any] = None, ignore_comme
...
@@ -403,6 +404,10 @@ def load(string: Optional[str] = None, *, fp: Optional[Any] = None, ignore_comme
JSON string to parse. Can be set to none if fp is used.
JSON string to parse. Can be set to none if fp is used.
fp : str
fp : str
File path to load JSON from. Can be set to none if string is used.
File path to load JSON from. Can be set to none if string is used.
preserve_order : bool
`json_tricks parameter <https://json-tricks.readthedocs.io/en/latest/#order>`_
to use ``OrderedDict`` instead of ``dict``.
The order is in fact always preserved even when this is False.
ignore_comments : bool
ignore_comments : bool
Remove comments (starting with ``#`` or ``//``). Default is true.
Remove comments (starting with ``#`` or ``//``). Default is true.
...
@@ -427,6 +432,8 @@ def load(string: Optional[str] = None, *, fp: Optional[Any] = None, ignore_comme
...
@@ -427,6 +432,8 @@ def load(string: Optional[str] = None, *, fp: Optional[Any] = None, ignore_comme
_json_tricks_any_object_decode
_json_tricks_any_object_decode
]
]
# there was an issue that the user code does not accept ordered dict, and 3.7+ dict has guaranteed order
json_tricks_kwargs
[
'preserve_order'
]
=
preserve_order
# to bypass a deprecation warning in json-tricks
# to bypass a deprecation warning in json-tricks
json_tricks_kwargs
[
'ignore_comments'
]
=
ignore_comments
json_tricks_kwargs
[
'ignore_comments'
]
=
ignore_comments
...
...
test/ut/sdk/test_serializer.py
View file @
b4559f60
from
collections
import
OrderedDict
import
math
import
math
import
os
import
os
import
pickle
import
pickle
...
@@ -24,6 +25,18 @@ if True: # prevent auto formatting
...
@@ -24,6 +25,18 @@ if True: # prevent auto formatting
from
imported._test_serializer_py38
import
test_positional_only
from
imported._test_serializer_py38
import
test_positional_only
def
test_ordered_json
():
items
=
[
(
'a'
,
1
),
(
'c'
,
3
),
(
'b'
,
2
),
]
orig
=
OrderedDict
(
items
)
json
=
nni
.
dump
(
orig
)
loaded
=
nni
.
load
(
json
)
assert
list
(
loaded
.
items
())
==
items
@
nni
.
trace
@
nni
.
trace
class
SimpleClass
:
class
SimpleClass
:
def
__init__
(
self
,
a
,
b
=
1
):
def
__init__
(
self
,
a
,
b
=
1
):
...
...
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