remote_smac.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:ac_pysmac 作者: belkhir-nacim 项目源码 文件源码
def __init__(self, scenario_fn, additional_options_fn, seed, class_path, memory_limit, parser_dict,
                 java_executable):
        """
        Starts SMAC in IPC mode. SMAC will wait for udp messages to be sent.
        """
        self.__parser = parser_dict
        self.__subprocess = None
        self.__logger = multiprocessing.get_logger()

        # establish a socket
        self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.__sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.__sock.settimeout(3)
        self.__sock.bind(('', 0))
        self.__sock.listen(1)

        self.__port = self.__sock.getsockname()[1]
        self.__logger.debug('picked port %i' % self.__port)

        # build the java command
        cmds = java_executable.split()
        if memory_limit is not None:
            cmds += ["-Xmx%im" % memory_limit]
        cmds += ["-XX:ParallelGCThreads=4",
                 "-cp",
                 class_path,
                 "ca.ubc.cs.beta.smac.executors.SMACExecutor",
                 "--scenario-file", scenario_fn,
                 "--tae", "IPC",
                 "--ipc-mechanism", "TCP",
                 "--ipc-remote-port", str(self.__port),
                 "--seed", str(seed)
                 ]

        with open(additional_options_fn, 'r') as fh:
            for line in fh:
                name, value = line.strip().split(' ')
                cmds += ['--%s' % name, '%s' % value]

        self.__logger.debug("SMAC command: %s" % (' '.join(cmds)))

        self.__logger.debug("Starting SMAC in ICP mode")

        # connect the output to the logger if the appropriate level has been set
        if self.__logger.level < logging.WARNING:
            self.__subprocess = subprocess.Popen(cmds, stdout=sys.stdout, stderr=sys.stderr)
        else:
            with open(os.devnull, "w") as fnull:
                self.__subprocess = subprocess.Popen(cmds, stdout=fnull, stderr=fnull)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号