src.plangym.vectorization.ray#

Implement a plangym.VectorizedEnv that uses ray when calling step_batch.

Classes#

RemoteEnv

Remote ray Actor interface for a plangym.PlanEnv.

RayEnv

Use ray for taking steps in parallel when calling step_batch.

Module Contents#

class src.plangym.vectorization.ray.RemoteEnv(env_callable)[source]#

Bases: plangym.core.PlanEnv

Remote ray Actor interface for a plangym.PlanEnv.

_env_callable#
env = None#
property unwrapped#
Completely unwrap this Environment.
Returns

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

property name: str#

Return the name of the environment.

Return type:

str

setup()[source]#

Init the wrapped environment.

step(action, state=None, dt=1, return_state=None)[source]#

Take a simulation step and make the environment evolve.

Parameters:
  • action – Chosen action applied to the environment.

  • 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.

  • dt (int) – Consecutive number of times to apply an action.

  • return_state (bool | None) – 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)

Return type:

tuple

step_batch(actions, states=None, dt=1, return_state=None)[source]#

Take a step on a batch of states and actions.

Parameters:
  • actions ([numpy.ndarray, list]) – Chosen actions applied to the environment.

  • 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.

  • dt (int) – Consecutive number of times that the action will be applied.

  • return_state (bool | None) – 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)

Return type:

tuple

reset(return_state=True)[source]#

Restart the environment.

Parameters:

return_state (bool)

Return type:

[numpy.ndarray, tuple]

get_state()[source]#

Recover the internal state of the simulation.

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

set_state(state)[source]#

Set the internal state of the simulation.

Parameters:

state – Target state to be set in the environment.

Returns:

None

class src.plangym.vectorization.ray.RayEnv(env_class, name, frameskip=1, autoreset=True, delay_setup=False, n_workers=8, **kwargs)[source]#

Bases: plangym.vectorization.env.VectorizedEnv

Use ray for taking steps in parallel when calling step_batch.

Parameters:
  • name (str)

  • frameskip (int)

  • autoreset (bool)

  • delay_setup (bool)

  • n_workers (int)

_workers = None#
property workers: list[RemoteEnv]#

Remote actors exposing copies of the environment.

Return type:

list[RemoteEnv]

setup()[source]#

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

make_transitions(actions, states=None, dt=1, return_state=None)[source]#

Implement the logic for stepping the environment in parallel.

Parameters:
  • dt ([numpy.ndarray, int])

  • return_state (bool | None)

reset(return_state=True)[source]#

Restart the environment.

Parameters:

return_state (bool)

Return type:

[numpy.ndarray, tuple]

sync_states(state)[source]#

Synchronize all the copies of the wrapped environment.

Set all the states of the different workers of the internal BatchEnv

to the same state as the internal Environment used to apply the non-vectorized steps.

Parameters:

state (None)

Return type:

None