public SamplerTests() { m_Channel = SideChannelManager.GetSideChannel <EnvironmentParametersChannel>(); // if running test on its own if (m_Channel == null) { m_Channel = new EnvironmentParametersChannel(); SideChannelManager.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 SideChannelManager.RegisterSideChannel(stringChannel); }
/// <summary> /// Constructor. /// </summary> internal StatsRecorder() { m_Channel = new StatsSideChannel(); SideChannelManager.RegisterSideChannel(m_Channel); }
/// <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(); SideChannelManager.RegisterSideChannel(new EngineConfigurationChannel()); SideChannelManager.RegisterSideChannel(new TrainingAnalyticsSideChannel()); 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 = CommunicatorFactory.Create(); } 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. bool initSuccessful = false; var communicatorInitParams = new CommunicatorInitParameters { port = port, unityCommunicationVersion = k_ApiVersion, unityPackageVersion = k_PackageVersion, name = "AcademySingleton", CSharpCapabilities = new UnityRLCapabilities() }; try { initSuccessful = Communicator.Initialize( communicatorInitParams, out var unityRlInitParameters ); if (initSuccessful) { UnityEngine.Random.InitState(unityRlInitParameters.seed); // We might have inference-only Agents, so set the seed for them too. m_InferenceSeed = unityRlInitParameters.seed; TrainerCapabilities = unityRlInitParameters.TrainerCapabilities; TrainerCapabilities.WarnOnPythonMissingBaseRLCapabilities(); } else { Debug.Log($"Couldn't connect to trainer on port {port} using API version {k_ApiVersion}. Will perform inference instead."); Communicator = null; } } catch (Exception ex) { Debug.Log($"Unexpected exception when trying to initialize communication: {ex}\nWill 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(); }
/// <summary> /// Constructor. /// </summary> internal EnvironmentParameters() { m_Channel = new EnvironmentParametersChannel(); SideChannelManager.RegisterSideChannel(m_Channel); }