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
98c1a77f
Unverified
Commit
98c1a77f
authored
May 14, 2022
by
liuzhe-lz
Committed by
GitHub
May 14, 2022
Browse files
Support multiple HPO experiments in one process (#4855)
parent
5dc80762
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
53 deletions
+7
-53
test/ut/sdk/test_msg_dispatcher.py
test/ut/sdk/test_msg_dispatcher.py
+7
-8
test/ut/sdk/test_protocol.py
test/ut/sdk/test_protocol.py
+0
-45
No files found.
test/ut/sdk/test_msg_dispatcher.py
View file @
98c1a77f
...
@@ -5,14 +5,12 @@ import json
...
@@ -5,14 +5,12 @@ import json
from
io
import
BytesIO
from
io
import
BytesIO
from
unittest
import
TestCase
,
main
from
unittest
import
TestCase
,
main
from
nni.runtime
import
protocol
from
nni.runtime
import
msg_dispatcher_base
from
nni.runtime
import
msg_dispatcher_base
from
nni.runtime.msg_dispatcher
import
MsgDispatcher
from
nni.runtime.msg_dispatcher
import
MsgDispatcher
from
nni.runtime.
protocol
import
CommandType
,
send
,
receive
from
nni.runtime.
tuner_command_channel.legacy
import
*
from
nni.tuner
import
Tuner
from
nni.tuner
import
Tuner
from
nni.utils
import
extract_scalar_reward
from
nni.utils
import
extract_scalar_reward
class
NaiveTuner
(
Tuner
):
class
NaiveTuner
(
Tuner
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
param
=
0
self
.
param
=
0
...
@@ -45,15 +43,15 @@ _out_buf = BytesIO()
...
@@ -45,15 +43,15 @@ _out_buf = BytesIO()
def
_reverse_io
():
def
_reverse_io
():
_in_buf
.
seek
(
0
)
_in_buf
.
seek
(
0
)
_out_buf
.
seek
(
0
)
_out_buf
.
seek
(
0
)
protocol
.
_set_out_file
(
_in_buf
)
_set_out_file
(
_in_buf
)
protocol
.
_set_in_file
(
_out_buf
)
_set_in_file
(
_out_buf
)
def
_restore_io
():
def
_restore_io
():
_in_buf
.
seek
(
0
)
_in_buf
.
seek
(
0
)
_out_buf
.
seek
(
0
)
_out_buf
.
seek
(
0
)
protocol
.
_set_in_file
(
_in_buf
)
_set_in_file
(
_in_buf
)
protocol
.
_set_out_file
(
_out_buf
)
_set_out_file
(
_out_buf
)
class
MsgDispatcherTestCase
(
TestCase
):
class
MsgDispatcherTestCase
(
TestCase
):
...
@@ -68,7 +66,8 @@ class MsgDispatcherTestCase(TestCase):
...
@@ -68,7 +66,8 @@ class MsgDispatcherTestCase(TestCase):
_restore_io
()
_restore_io
()
tuner
=
NaiveTuner
()
tuner
=
NaiveTuner
()
dispatcher
=
MsgDispatcher
(
tuner
)
dispatcher
=
MsgDispatcher
(
'ws://_placeholder_'
,
tuner
)
dispatcher
.
_channel
=
LegacyCommandChannel
()
msg_dispatcher_base
.
_worker_fast_exit_on_terminate
=
False
msg_dispatcher_base
.
_worker_fast_exit_on_terminate
=
False
dispatcher
.
run
()
dispatcher
.
run
()
...
...
test/ut/sdk/test_protocol.py
deleted
100644 → 0
View file @
5dc80762
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from
nni.runtime
import
protocol
from
nni.runtime.protocol
import
CommandType
,
send
,
receive
from
io
import
BytesIO
from
unittest
import
TestCase
,
main
def
_prepare_send
():
out_file
=
BytesIO
()
protocol
.
_set_out_file
(
out_file
)
return
out_file
def
_prepare_receive
(
data
):
protocol
.
_set_in_file
(
BytesIO
(
data
))
class
ProtocolTestCase
(
TestCase
):
def
test_send_en
(
self
):
out_file
=
_prepare_send
()
send
(
CommandType
.
NewTrialJob
,
'CONTENT'
)
self
.
assertEqual
(
out_file
.
getvalue
(),
b
'TR00000000000007CONTENT'
)
def
test_send_zh
(
self
):
out_file
=
_prepare_send
()
send
(
CommandType
.
NewTrialJob
,
'你好'
)
self
.
assertEqual
(
out_file
.
getvalue
(),
'TR00000000000006你好'
.
encode
(
'utf8'
))
def
test_receive_en
(
self
):
_prepare_receive
(
b
'IN00000000000005hello'
)
command
,
data
=
receive
()
self
.
assertIs
(
command
,
CommandType
.
Initialize
)
self
.
assertEqual
(
data
,
'hello'
)
def
test_receive_zh
(
self
):
_prepare_receive
(
'IN00000000000006世界'
.
encode
(
'utf8'
))
command
,
data
=
receive
()
self
.
assertIs
(
command
,
CommandType
.
Initialize
)
self
.
assertEqual
(
data
,
'世界'
)
if
__name__
==
'__main__'
:
main
()
Prev
1
2
Next
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