Exemplo n.º 1
0
        /// <summary>
        /// Initializes the environment, configures it and initialized the Academy.
        /// </summary>
        void InitializeEnvironment()
        {
            EnableAutomaticStepping();

            var floatProperties = new FloatPropertiesChannel();

            FloatProperties = floatProperties;

            // 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)
            {
                Communicator.RegisterSideChannel(new EngineConfigurationChannel());
                Communicator.RegisterSideChannel(floatProperties);
                // 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
                    {
                        version = k_ApiVersion,
                        name    = "AcademySingleton",
                    });
                    UnityEngine.Random.InitState(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.º 2
0
        /// <summary>
        /// Shut down the Academy.
        /// </summary>
        public void Dispose()
        {
            DisableAutomaticStepping();
            // Signal to listeners that the academy is being destroyed now
            DestroyAction?.Invoke();

            Communicator?.Dispose();
            Communicator = null;

            if (m_ModelRunners != null)
            {
                foreach (var mr in m_ModelRunners)
                {
                    mr.Dispose();
                }
                m_ModelRunners = null;
            }

            // Clear out the actions so we're not keeping references to any old objects
            ResetActions();

            // TODO - Pass worker ID or some other identifier,
            // so that multiple envs won't overwrite each others stats.
            TimerStack.Instance.SaveJsonTimers();

            FloatProperties = null;
            m_Initialized   = false;

            // Reset the Lazy instance
            s_Lazy = new Lazy <Academy>(() => new Academy());
        }
Exemplo n.º 3
0
    public override void InitializeAgent()
    {
        m_JdController = GetComponent <JointDriveController>();
        m_JdController.SetupBodyPart(hips);
        m_JdController.SetupBodyPart(chest);
        m_JdController.SetupBodyPart(spine);
        m_JdController.SetupBodyPart(head);
        m_JdController.SetupBodyPart(thighL);
        m_JdController.SetupBodyPart(shinL);
        m_JdController.SetupBodyPart(footL);
        m_JdController.SetupBodyPart(thighR);
        m_JdController.SetupBodyPart(shinR);
        m_JdController.SetupBodyPart(footR);
        m_JdController.SetupBodyPart(armL);
        m_JdController.SetupBodyPart(forearmL);
        m_JdController.SetupBodyPart(handL);
        m_JdController.SetupBodyPart(armR);
        m_JdController.SetupBodyPart(forearmR);
        m_JdController.SetupBodyPart(handR);

        m_HipsRb  = hips.GetComponent <Rigidbody>();
        m_ChestRb = chest.GetComponent <Rigidbody>();
        m_SpineRb = spine.GetComponent <Rigidbody>();

        m_ResetParams = Academy.Instance.FloatProperties;

        SetResetParameters();
    }
Exemplo n.º 4
0
    public override void InitializeAgent()
    {
        m_BallRb = ball.GetComponent <Rigidbody>();
        var academy = FindObjectOfType <Academy>();

        m_ResetParams = academy.FloatProperties;
        SetResetParameters();
    }
Exemplo n.º 5
0
    public override void InitializeAgent()
    {
        m_Rb      = gameObject.GetComponent <Rigidbody>();
        m_LookDir = Vector3.zero;

        m_ResetParams = Academy.Instance.FloatProperties;

        SetResetParameters();
    }
Exemplo n.º 6
0
    public override void InitializeAgent()
    {
        m_Rb      = gameObject.GetComponent <Rigidbody>();
        m_LookDir = Vector3.zero;

        var academy = FindObjectOfType <Academy>();

        m_ResetParams = academy.FloatProperties;

        SetResetParameters();
    }
Exemplo n.º 7
0
    public void Start()
    {
        m_ResetParameters = FindObjectOfType <Academy>().FloatProperties;

        m_Objects = new[] { goalPref, pitPref };

        m_AgentCam = transform.Find("agentCam").GetComponent <Camera>();

        actorObjs = new List <GameObject>();

        var sceneTransform = transform.Find("scene");

        m_Plane           = sceneTransform.Find("Plane").gameObject;
        m_Sn              = sceneTransform.Find("sN").gameObject;
        m_Ss              = sceneTransform.Find("sS").gameObject;
        m_Sw              = sceneTransform.Find("sW").gameObject;
        m_Se              = sceneTransform.Find("sE").gameObject;
        m_InitialPosition = transform.position;
    }
Exemplo n.º 8
0
    public override void InitializeAgent()
    {
        m_AgentRb = GetComponent <Rigidbody>();
        m_BallRb  = ball.GetComponent <Rigidbody>();
        var        canvas = GameObject.Find(k_CanvasName);
        GameObject scoreBoard;

        m_ResetParams = Academy.Instance.FloatProperties;
        if (invertX)
        {
            scoreBoard = canvas.transform.Find(k_ScoreBoardBName).gameObject;
        }
        else
        {
            scoreBoard = canvas.transform.Find(k_ScoreBoardAName).gameObject;
        }
        m_TextComponent = scoreBoard.GetComponent <Text>();
        SetResetParameters();
    }
Exemplo n.º 9
0
 public override void InitializeAgent()
 {
     m_BallRb      = ball.GetComponent <Rigidbody>();
     m_ResetParams = Academy.Instance.FloatProperties;
     SetResetParameters();
 }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes the environment, configures it and initialized the Academy.
        /// </summary>
        void InitializeEnvironment()
        {
            m_OriginalGravity          = Physics.gravity;
            m_OriginalFixedDeltaTime   = Time.fixedDeltaTime;
            m_OriginalMaximumDeltaTime = Time.maximumDeltaTime;

            var floatProperties = new FloatPropertiesChannel();

            FloatProperties = floatProperties;
            InitializeAcademy();


            // 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)
            {
                Communicator.RegisterSideChannel(new EngineConfigurationChannel());
                Communicator.RegisterSideChannel(floatProperties);
                // 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
                    {
                        version = k_ApiVersion,
                        name    = gameObject.name,
                    });
                    Random.InitState(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.

            DecideAction     += () => { };
            DestroyAction    += () => { };
            AgentSetStatus   += i => { };
            AgentResetIfDone += () => { };
            AgentSendState   += () => { };
            AgentAct         += () => { };
            AgentForceReset  += () => { };
        }