Module for conveniently managing a Hyperopt cluster.
Abstract implementation of the MasterLauncher
interface used to implement a concrete launch strategy for mongodb instance used in hyperopt.
This class implements the logic for starting a MongoDB instance on localhost. Hence, we simply treat the MongoDB instance as master node.
__init__(runtime_group: RuntimeGroup)
Initialization method.
Args:
runtime_group
: The group where the workers will be started.
The port where the master instance is started on. Will be None if not yet started.
Returns:
Optional[int]
: The master port.
The process object where the master instance was started in.
Returns:
Optional[Popen]
: The process object or None if not yet started.
Concrete implementation of the MasterLauncher
interface. See its documentation to get a list of the inherited methods and attributes.
This class implements the logic for starting a MongoDB instance on localhost. Hence, we simply treat the MongoDB instance as master node.
__init__(runtime_group: RuntimeGroup)
Initialization method.
Args:
runtime_group
: The group where the workers will be started.
The port where the master instance is started on. Will be None if not yet started.
Returns:
Optional[int]
: The master port.
The process object where the master instance was started in.
Returns:
Optional[Popen]
: The process object or None if not yet started.
cleanup() β None
Release all resources.
get_mongod_start_cmd() β str
Get the shell command for starting mongod as a deamon process.
Returns:
str
: The shell command.
get_mongod_stop_cmd() β str
Get the shell command for stopping the currently running mongod process.
Returns:
str
: The shell command.
start(
ports: Union[List[int], int],
timeout: int = 0,
debug: bool = False
) β List[int]
Launch a master instance.
Note:
If you create a custom subclass of MasterLauncher which will not start the master instance on localhost then you should pass the debug flag on to
execute_task()
of theRuntimeGroup
orRuntime
so that you can benefit from the debug feature ofRuntimeTask.execute()
.
Args:
ports
: Port where the DB should be started. If a list is given then the first port that is free in theRuntimeGroup
will be used. The actual chosen port can be requested via the propertyport
.timeout
: Timeout (s) after which an MasterStartError is raised if DB instance not started yet. Defaults to 3 seconds.debug
: IfTrue
, stdout/stderr from the runtime will be printed to stdout of localhost. If,False
then the stdout/stderr will be added to python logger with level debug after eachRuntimeTask
step. Defaults toFalse
.
Returns:
List[int]
: In case a port list was given the updated port list will be returned. Otherwise an empty list.
Raises:
PortInUseError
: If a single port is given and it is not free in theRuntimeGroup
.NoPortsLeftError
: If a port list was given and none of the ports is actually free in theRuntimeGroup
.MasterStartError
: If master was not started after the specifiedtimeout
.
Concrete WorkerLauncher implementation for launching hyperopt workers in a round robin manner.
See the WorkerLauncher
documentation to get a list of the inherited methods and attributes.
__init__(runtime_group: RuntimeGroup, dbname: str, poll_interval: float)
Initialization method.
Args:
runtime_group
: The group where the workers will be started.dbname
: The name of the mongodb instance.poll_interval
: The poll interval of the hyperopt worker.
Raises.
ValueError
: In case dbname is empty.
Dictionary with the host as key and a port list as value. The list contains all ports where a worker instance is reachable on the respective host.
Returns:
Dict[str, List[int]]
: The ports per host as a dictionary.
cleanup() β None
Release all resources.
start(
worker_count: int,
master_port: int,
ports: List[int] = None,
debug: bool = True
) β List[int]
Launches the worker instances in the RuntimeGroup
.
Args:
worker_count
: The number of worker instances to be started in the group.master_port
: The port of the master instance.ports
: Without use here. Only here because we need to adhere to the interface defined by the WorkerLauncher class.debug
: IfTrue
, stdout/stderr from the runtime will be printed to stdout of localhost. If,False
then the stdout/stderr will be added to python logger with level debug after eachRuntimeTask
step. Defaults toFalse
.
Returns:
List[int]
: The updated port list after starting the workers, i.e. the used ones were removed.
Convenient class for launching a Hyperopt cluster in a RuntimeGroup
.
HyperoptCluster inherits from MasterWorkerCluster. See its documentation to get a list of the inherited methods and attributes.
The number of hyperopt workers defaults to the number of Runtimes
in the used RuntimeGroup
. This number can be adjusted so that more or less workers than available Runtimes
can be used. Per default the desired number of workers is started in a round robin way as implemented in RoundRobinLauncher
. Consequently, this leads to an equal distribution of hyperopt workers in the RuntimeGroup
. You can provide a custom implementation inheriting from the WorkerLauncher
class in order to execute a different strategy how workers should be started. The master instance (i.e. the mongoDB) will always be started on localhost as implemented in LocalMasterLauncher
. This behavior can also be changed by providing a custom implementation inheriting from the MasterLauncher
.
__init__(
runtime_group: RuntimeGroup,
mongo_launcher: Optional[MongoLauncher] = None,
worker_launcher: Optional[WorkerLauncher] = None,
dbpath: Optional[str] = None,
dbname: str = 'hyperopt',
worker_poll_intervall: float = 1
)
Initialization method.
Args:
runtime_group
: TheRuntimeGroup
contains allRuntimes
which can be used for starting the entities.mongo_launcher
: Optionally, an instance implementing theMasterLauncher
interface can be given, which implements the strategy for launching the master instances in the cluster. If None, thenLocalMasterLauncher
is used.worker_launcher
: Optionally, an instance implementing theWorkerLauncher
interface can be given, which implements the strategy for launching the worker instances. If None, thenRoundRobinLauncher
is used.dbpath
: The directory where the db files will be kept. Defaults to amongodb
directory inside theutils.Environment.main_directory
.dbname
: The name of the database to be used for experiments. See MongoTrials url scheme in hyperopt documentation for more details. Defaults to Β΄hyperoptΒ΄.worker_poll_intervall
: The poll interval of the hyperopt worker. Defaults to0.1
.
Raises:
PermissionError
: If thedbpath
does not exsist and could not be created due to lack of permissions.
The name of the MongoDB database to be used for experiments.
The port where the master instance was started. None, if not yet started.
Returns:
Optional[int]
: The master port.
The MongoDB url indicating what mongod process and which database to use.
Note:
The format is the format required by the hyperopt MongoTrials object.
Returns:
str
: URL string.
The MongoDB url indicating what mongod process and which database to use.
Note:
The format is
mongo://host:port/dbname
.
Returns:
str
: URL string.
The RuntimeGroup.
Returns:
RuntimeGroup
: The used group.
cleanup() β None
Release all resources.
start_master(
master_port: Optional[int] = None,
timeout: int = 3,
debug: bool = False
) β None
Start the master instance.
Note:
How the master is actually started is determined by the the actual
MasterLauncher
implementation. Another implementation adhering to theMasterLauncher
interface can be provided in the constructor of the cluster class.
Args:
master_port
: Port of the master instance. Defaults to self.DEFAULT_MASTER_PORT, but another one is chosen if the port is not free within the group. The actual chosen port can be requested via self.master_port.timeout
: Timeout (s) after which an MasterStartError is raised if master instance not started yet.debug
: IfTrue
, stdout/stderr from the runtime will be printed to stdout of localhost. Has no effect for if the master instance is started locally, what default MasterLauncher implementations usually do.
Raises:
PortInUseError
: If a single port is given and it is not free in theRuntimeGroup
.NoPortsLeftError
: If there are no free ports left in the port list for instantiating the master.MasterStartError
: If master was not started after the specifiedtimeout
.
This file was automatically generated via lazydocs.