src.plangym.vectorization.ray
=============================

.. py:module:: src.plangym.vectorization.ray

.. autoapi-nested-parse::

   Implement a :class:`plangym.VectorizedEnv` that uses ray when calling `step_batch`.



Classes
-------

.. autoapisummary::

   src.plangym.vectorization.ray.RemoteEnv
   src.plangym.vectorization.ray.RayEnv


Module Contents
---------------

.. py:class:: RemoteEnv(env_callable)

   Bases: :py:obj:`plangym.core.PlanEnv`


   Remote ray Actor interface for a plangym.PlanEnv.


   .. py:attribute:: _env_callable


   .. py:attribute:: env
      :value: None



   .. py:property:: unwrapped
      Completely unwrap this Environment.

      Returns
          plangym.Environment: The base non-wrapped plangym.Environment instance


   .. py:property:: name
      :type: str

      Return the name of the environment.


   .. py:method:: setup()

      Init the wrapped environment.



   .. py:method:: step(action, state=None, dt = 1, return_state = None)

      Take a simulation step and make the environment evolve.

      :param action: Chosen action applied to the environment.
      :param state: Set the environment to the given state before stepping it.
                    If state is None the behaviour of this function will be the
                    same as in OpenAI gym.
      :param dt: Consecutive number of times to apply an action.
      :param return_state: Whether to return the state in the returned tuple.                 If None, `step` will return the state if `state` was passed as a parameter.

      :returns: if states is None returns (observs, rewards, ends, infos)
                else returns(new_states, observs, rewards, ends, infos)



   .. py:method:: step_batch(actions, states=None, dt = 1, return_state = None)

      Take a step on a batch of states and actions.

      :param actions: Chosen actions applied to the environment.
      :param states: Set the environment to the given states before stepping it.
                     If state is None the behaviour of this function will be the same
                     as in OpenAI gym.
      :param dt: Consecutive number of times that the action will be
                 applied.
      :param return_state: Whether to return the state in the returned tuple.                 If None, `step` will return the state if `state` was passed as a parameter.

      :returns: if states is None returns (observs, rewards, ends, infos)
                else returns(new_states, observs, rewards, ends, infos)



   .. py:method:: reset(return_state = True)

      Restart the environment.



   .. py:method:: get_state()

      Recover the internal state of the simulation.

      A state must completely describe the Environment at a given moment.



   .. py:method:: set_state(state)

      Set the internal state of the simulation.

      :param state: Target state to be set in the environment.

      :returns: None



.. py:class:: RayEnv(env_class, name, frameskip = 1, autoreset = True, delay_setup = False, n_workers = 8, **kwargs)

   Bases: :py:obj:`plangym.vectorization.env.VectorizedEnv`


   Use ray for taking steps in parallel when calling `step_batch`.


   .. py:attribute:: _workers
      :value: None



   .. py:property:: workers
      :type: list[RemoteEnv]

      Remote actors exposing copies of the environment.


   .. py:method:: setup()

      Run environment initialization and create the subprocesses for stepping in parallel.



   .. py:method:: make_transitions(actions, states=None, dt = 1, return_state = None)

      Implement the logic for stepping the environment in parallel.



   .. py:method:: reset(return_state = True)

      Restart the environment.



   .. py:method:: sync_states(state)

      Synchronize all the copies of the wrapped environment.

      Set all the states of the different workers of the internal :class:`BatchEnv`
       to the same state as the internal :class:`Environment` used to apply the
       non-vectorized steps.



