def __init__(self,
                 file_name: Optional[str] = None,
                 worker_id: int = 0,
                 base_port: int = 5005,
                 seed: int = 0,
                 docker_training: bool = False,
                 no_graphics: bool = False,
                 timeout_wait: int = 30):
        """
        Starts a new unity environment and establishes a connection with the environment.
        Notice: Currently communication between Unity and Python takes place over an open socket without authentication.
        Ensure that the network where training takes place is secure.

        :string file_name: Name of Unity environment binary.
        :int base_port: Baseline port number to connect to Unity environment over. worker_id increments over this.
        :int worker_id: Number to add to communication port (5005) [0]. Used for asynchronous agent scenarios.
        :bool docker_training: Informs this class whether the process is being run within a container.
        :bool no_graphics: Whether to run the Unity simulator in no-graphics mode
        :int timeout_wait: Time (in seconds) to wait for connection from environment.
        :bool train_mode: Whether to run in training mode, speeding up the simulation, by default.
        """

        atexit.register(self._close)
        self.port = base_port + worker_id
        self._buffer_size = 12000
        self._version_ = "API-8"
        self._loaded = False  # If true, this means the environment was successfully loaded
        self.proc1 = None  # The process that is started. If None, no process was started
        self.communicator = self.get_communicator(worker_id, base_port, timeout_wait)

        # If the environment name is None, a new environment will not be launched
        # and the communicator will directly try to connect to an existing unity environment.
        # If the worker-id is not 0 and the environment name is None, an error is thrown
        if file_name is None and worker_id != 0:
            raise UnityEnvironmentException(
                "If the environment name is None, "
                "the worker-id must be 0 in order to connect with the Editor.")
        if file_name is not None:
            self.executable_launcher(file_name, docker_training, no_graphics)
        else:
            logger.info("Start training by pressing the Play button in the Unity Editor.")
        self._loaded = True

        rl_init_parameters_in = UnityRLInitializationInput(
            seed=seed
        )
        try:
            aca_params = self.send_academy_parameters(rl_init_parameters_in)
        except UnityTimeOutException:
            self._close()
            raise
        # TODO : think of a better way to expose the academyParameters
        self._unity_version = aca_params.version
        if self._unity_version != self._version_:
            self._close()
            raise UnityEnvironmentException(
                "The API number is not compatible between Unity and python. Python API : {0}, Unity API : "
                "{1}.\nPlease go to https://github.com/Unity-Technologies/ml-agents to download the latest version "
                "of ML-Agents.".format(self._version_, self._unity_version))
        self._n_agents = {}
        self._global_done = None
        self._academy_name = aca_params.name
        self._log_path = aca_params.log_path
        self._brains = {}
        self._brain_names = []
        self._external_brain_names = []
        for brain_param in aca_params.brain_parameters:
            self._brain_names += [brain_param.brain_name]
            self._brains[brain_param.brain_name] = BrainParameters.from_proto(brain_param)
            if brain_param.is_training:
                self._external_brain_names += [brain_param.brain_name]
        self._num_brains = len(self._brain_names)
        self._num_external_brains = len(self._external_brain_names)
        self._resetParameters = dict(aca_params.environment_parameters.float_parameters)
        logger.info("\n'{0}' started successfully!\n{1}".format(self._academy_name, str(self)))
        if self._num_external_brains == 0:
            logger.warning(" No Learning Brains set to train found in the Unity Environment. "
                           "You will not be able to pass actions to your agent(s).")
def __init__ ( self , file_name : Optional [ str ] = None , worker_id : int = 0 , base_port : int = 5005 , seed : int = 0 , docker_training : bool = False , no_graphics : bool = False , timeout_wait : int = 30 ) : atexit . register ( self . _close ) self . port = base_port + worker_id self . _buffer_size = 12000 self . _version_ = "API-8" self . _loaded = False self . proc1 = None self . communicator = self . get_communicator ( worker_id , base_port , timeout_wait ) if file_name is None and worker_id != 0 : raise UnityEnvironmentException ( "If the environment name is None, " "the worker-id must be 0 in order to connect with the Editor." ) if file_name is not None : self . executable_launcher ( file_name , docker_training , no_graphics ) else : logger . info ( "Start training by pressing the Play button in the Unity Editor." ) self . _loaded = True rl_init_parameters_in = UnityRLInitializationInput ( seed = seed ) try : aca_params = self . send_academy_parameters ( rl_init_parameters_in ) except UnityTimeOutException : self . _close ( ) raise self . _unity_version = aca_params . version if self . _unity_version != self . _version_ : self . _close ( ) raise UnityEnvironmentException ( "The API number is not compatible between Unity and python. Python API : {0}, Unity API : " "{1}.\nPlease go to https://github.com/Unity-Technologies/ml-agents to download the latest version " "of ML-Agents." . format ( self . _version_ , self . _unity_version ) ) self . _n_agents = { } self . _global_done = None self . _academy_name = aca_params . name self . _log_path = aca_params . log_path self . _brains = { } self . _brain_names = [ ] self . _external_brain_names = [ ] for brain_param in aca_params . brain_parameters : self . _brain_names += [ brain_param . brain_name ] self . _brains [ brain_param . brain_name ] = BrainParameters . from_proto ( brain_param ) if brain_param . is_training : self . _external_brain_names += [ brain_param . brain_name ] self . _num_brains = len ( self . _brain_names ) self . _num_external_brains = len ( self . _external_brain_names ) self . _resetParameters = dict ( aca_params . environment_parameters . float_parameters ) logger . info ( "\n'{0}' started successfully!\n{1}" . format ( self . _academy_name , str ( self ) ) ) if self . _num_external_brains == 0 : logger . warning ( " No Learning Brains set to train found in the Unity Environment. " "You will not be able to pass actions to your agent(s)." )
Starts a new unity environment and establishes a connection with the environment.
        Notice: Currently communication between Unity and Python takes place over an open socket without authentication.
        Ensure that the network where training takes place is secure.

        :string file_name: Name of Unity environment binary.
        :int base_port: Baseline port number to connect to Unity environment over. worker_id increments over this.
        :int worker_id: Number to add to communication port (5005) [0]. Used for asynchronous agent scenarios.
        :bool docker_training: Informs this class whether the process is being run within a container.
        :bool no_graphics: Whether to run the Unity simulator in no-graphics mode
        :int timeout_wait: Time (in seconds) to wait for connection from environment.
        :bool train_mode: Whether to run in training mode, speeding up the simulation, by default.