本文整理汇总了Python中hpbandster.core.nameserver.NameServer方法的典型用法代码示例。如果您正苦于以下问题:Python nameserver.NameServer方法的具体用法?Python nameserver.NameServer怎么用?Python nameserver.NameServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hpbandster.core.nameserver
的用法示例。
在下文中一共展示了nameserver.NameServer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_nameserver
# 需要导入模块: from hpbandster.core import nameserver [as 别名]
# 或者: from hpbandster.core.nameserver import NameServer [as 别名]
def get_nameserver(self, run_id, task_id, ns_credentials_dir, network_interface_name):
"""Get the namesever object
Arguments:
run_id {str} -- The id of the run
task_id {int} -- An id for the worker
ns_credentials_dir {str} -- Path to ns credentials
network_interface_name {str} -- The network interface name
Returns:
NameServer -- The NameServer object
"""
if not os.path.isdir(ns_credentials_dir):
try:
os.mkdir(ns_credentials_dir)
except:
pass
return NameServer(run_id=run_id, nic_name=network_interface_name, working_directory=ns_credentials_dir)
示例2: test_Timeout
# 需要导入模块: from hpbandster.core import nameserver [as 别名]
# 或者: from hpbandster.core.nameserver import NameServer [as 别名]
def test_Timeout(self):
class dummy_callback(object):
def register_result(self, *args, **kwargs):
pass
host = hpn.nic_name_to_host('lo')
w = TestWorker(run_id=self.run_id, sleep_duration=0, timeout=1, host=host)
dc = dummy_callback()
with tempfile.TemporaryDirectory() as working_directory:
# start up nameserver
ns = hpn.NameServer(self.run_id, working_directory=working_directory, host=host)
ns_host, ns_port = ns.start()
# connect worker to it
w.load_nameserver_credentials(working_directory)
w.run(background=True)
# start a computation with a dummy callback and dummy id
w.start_computation(dc, '0')
# at this point the worker must still be alive
self.assertTrue(w.thread.is_alive())
# as the timeout is only 1, after 2 seconds, the worker thread should be dead
time.sleep(2)
self.assertFalse(w.thread.is_alive())
# shutdown the nameserver before the temporary directory is gone
ns.shutdown()
示例3: test_optimizers
# 需要导入模块: from hpbandster.core import nameserver [as 别名]
# 或者: from hpbandster.core.nameserver import NameServer [as 别名]
def test_optimizers(self):
optimizers = [BOHB, H2BO, RandomSearch]
for optimizer in optimizers:
host = hpn.nic_name_to_host('lo')
with tempfile.TemporaryDirectory() as working_directory:
# start up nameserver
ns = hpn.NameServer(self.run_id, working_directory=working_directory, host=host)
ns_host, ns_port = ns.start()
# create workers and connect them to the nameserver
w = TestWorker(run_id=self.run_id, sleep_duration=2, timeout=1, host=host, id=1)
w.load_nameserver_credentials(working_directory)
w.run(background=True)
opt = optimizer(run_id=self.run_id,
configspace=self.configspace,
nameserver=ns_host,
nameserver_port=ns_port,
min_budget=1, max_budget=3, eta=3, ping_interval=1)
opt.run(1, min_n_workers=1)
opt.shutdown()
time.sleep(2)
# shutdown the nameserver before the temporary directory is gone
ns.shutdown()
示例4: test_local_nameserver_1
# 需要导入模块: from hpbandster.core import nameserver [as 别名]
# 或者: from hpbandster.core.nameserver import NameServer [as 别名]
def test_local_nameserver_1(self):
host, port = utils.start_local_nameserver(host=None, nic_name=None)
self.assertEqual(host, 'localhost')
ns = hpn.NameServer('0', host=host)
ns_host, ns_port = ns.start()
self.assertEqual(ns.host, 'localhost')
ns.shutdown()
示例5: test_local_nameserver_2
# 需要导入模块: from hpbandster.core import nameserver [as 别名]
# 或者: from hpbandster.core.nameserver import NameServer [as 别名]
def test_local_nameserver_2(self):
host, port = utils.start_local_nameserver(host=None, nic_name='lo')
self.assertEqual(host, '127.0.0.1')
ns = hpn.NameServer('0', host=host)
ns_host, ns_port = ns.start()
self.assertEqual(ns.host, '127.0.0.1')
ns.shutdown()
示例6: generate_bohb_data
# 需要导入模块: from hpbandster.core import nameserver [as 别名]
# 或者: from hpbandster.core.nameserver import NameServer [as 别名]
def generate_bohb_data():
import warnings
import hpbandster.core.nameserver as hpns
import hpbandster.core.result as hpres
from hpbandster.optimizers import BOHB as BOHB
run_id = '0' # Every run has to have a unique (at runtime) id.
NS = hpns.NameServer(run_id=run_id, host='localhost', port=0)
ns_host, ns_port = NS.start()
from neural_opt import MyWorker, get_configspace
w = MyWorker(nameserver=ns_host,
nameserver_port=ns_port,
run_id=run_id, # same as nameserver's
)
w.run(background=True)
# Log the optimization results for later analysis
result_logger = hpres.json_result_logger(directory='test/general_example/results/bohb_full_configspace',
overwrite=True)
bohb = BOHB(configspace=get_configspace(),
run_id=run_id, # same as nameserver's
eta=2, min_budget=5, max_budget=100, # Hyperband parameters
nameserver=ns_host, nameserver_port=ns_port,
result_logger=result_logger,
)
# Then start the optimizer. The n_iterations parameter specifies
# the number of iterations to be performed in this run
with warnings.catch_warnings():
warnings.simplefilter("ignore")
res = bohb.run(n_iterations=2)
# After the run is finished, the services started above need to be shutdown.
# This ensures that the worker, the nameserver and the master all properly exit
# and no (daemon) threads keep running afterwards.
# In particular we shutdown the optimizer (which shuts down all workers) and the nameserver.
bohb.shutdown(shutdown_workers=True)
NS.shutdown()
示例7: get_nameserver
# 需要导入模块: from hpbandster.core import nameserver [as 别名]
# 或者: from hpbandster.core.nameserver import NameServer [as 别名]
def get_nameserver(self, run_id, task_id, ns_credentials_dir, network_interface_name):
if not os.path.isdir(ns_credentials_dir):
try:
os.mkdir(ns_credentials_dir)
except:
pass
return NameServer(run_id=run_id, nic_name=network_interface_name, working_directory=ns_credentials_dir)
示例8: start
# 需要导入模块: from hpbandster.core import nameserver [as 别名]
# 或者: from hpbandster.core.nameserver import NameServer [as 别名]
def start(self):
# type: () -> ()
"""
Start the Optimizer controller function loop()
If the calling process is stopped, the controller will stop as well.
.. important::
This function returns only after optimization is completed or :meth:`stop` was called.
"""
# Step 1: Start a NameServer
fake_run_id = 'OptimizerBOHB_{}'.format(time())
# default port is 9090, we must have one, this is how BOHB workers communicate (even locally)
self._namespace = hpns.NameServer(run_id=fake_run_id, host='127.0.0.1', port=self._nameserver_port)
self._namespace.start()
# we have to scale the budget to the iterations per job, otherwise numbers might be too high
budget_iteration_scale = self._max_iteration_per_job
# Step 2: Start the workers
workers = []
for i in range(self._num_concurrent_workers):
w = _TrainsBandsterWorker(
optimizer=self,
sleep_interval=int(self.pool_period_minutes * 60),
budget_iteration_scale=budget_iteration_scale,
base_task_id=self._base_task_id,
objective=self._objective_metric,
queue_name=self._execution_queue,
nameserver='127.0.0.1', nameserver_port=self._nameserver_port, run_id=fake_run_id, id=i)
w.run(background=True)
workers.append(w)
# Step 3: Run an optimizer
self._bohb = BOHB(configspace=self._convert_hyper_parameters_to_cs(),
run_id=fake_run_id,
# num_samples=self.total_max_jobs, # will be set by self._bohb_kwargs
min_budget=float(self._min_iteration_per_job) / float(self._max_iteration_per_job),
**self._bohb_kwargs)
# scale the budget according to the successive halving iterations
if self.budget.jobs.limit:
self.budget.jobs.limit *= len(self._bohb.budgets)
if self.budget.iterations.limit:
self.budget.iterations.limit *= len(self._bohb.budgets)
# start optimization
self._res = self._bohb.run(n_iterations=self.total_max_jobs, min_n_workers=self._num_concurrent_workers)
# Step 4: if we get here, Shutdown
self.stop()