Exemplo n.º 1
0
 public SamplerTests()
 {
     m_Channel = SideChannelsManager.GetSideChannel <EnvironmentParametersChannel>();
     // if running test on its own
     if (m_Channel == null)
     {
         m_Channel = new EnvironmentParametersChannel();
         SideChannelsManager.RegisterSideChannel(m_Channel);
     }
 }
    public void Awake()
    {
        // We create the Side Channel
        stringChannel = new StringLogSideChannel();

        // When a Debug.Log message is created, we send it to the stringChannel
        Application.logMessageReceived += stringChannel.SendDebugStatementToPython;

        // The channel must be registered with the SideChannelManager class
        SideChannelsManager.RegisterSideChannel(stringChannel);
    }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes the environment, configures it and initializes the Academy.
        /// </summary>
        void InitializeEnvironment()
        {
            TimerStack.Instance.AddMetadata("communication_protocol_version", k_ApiVersion);
            TimerStack.Instance.AddMetadata("com.unity.ml-agents_version", k_PackageVersion);

            EnableAutomaticStepping();

            SideChannelsManager.RegisterSideChannel(new EngineConfigurationChannel());
            m_EnvironmentParameters = new EnvironmentParameters();
            m_StatsRecorder         = new StatsRecorder();

            // Try to launch the communicator by using the arguments passed at launch
            var port = ReadPortFromArgs();

            if (port > 0)
            {
                Communicator = new RpcCommunicator(
                    new CommunicatorInitParameters
                {
                    port = port
                }
                    );
            }

            if (Communicator != null)
            {
                // We try to exchange the first message with Python. If this fails, it means
                // no Python Process is ready to train the environment. In this case, the
                //environment must use Inference.
                try
                {
                    var unityRlInitParameters = Communicator.Initialize(
                        new CommunicatorInitParameters
                    {
                        unityCommunicationVersion = k_ApiVersion,
                        unityPackageVersion       = k_PackageVersion,
                        name = "AcademySingleton",
                    });
                    UnityEngine.Random.InitState(unityRlInitParameters.seed);
                    // We might have inference-only Agents, so set the seed for them too.
                    m_InferenceSeed = unityRlInitParameters.seed;
                }
                catch
                {
                    Debug.Log($"" +
                              $"Couldn't connect to trainer on port {port} using API version {k_ApiVersion}. " +
                              "Will perform inference instead."
                              );
                    Communicator = null;
                }

                if (Communicator != null)
                {
                    Communicator.QuitCommandReceived  += OnQuitCommandReceived;
                    Communicator.ResetCommandReceived += OnResetCommand;
                }
            }

            // If a communicator is enabled/provided, then we assume we are in
            // training mode. In the absence of a communicator, we assume we are
            // in inference mode.

            ResetActions();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 internal StatsRecorder()
 {
     m_Channel = new StatsSideChannel();
     SideChannelsManager.RegisterSideChannel(m_Channel);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 internal EnvironmentParameters()
 {
     m_Channel = new EnvironmentParametersChannel();
     SideChannelsManager.RegisterSideChannel(m_Channel);
 }