plangym.vectorization.ray

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

Module Contents

Classes

RemoteEnv

Remote ray Actor interface for a plangym.PlanEnv.

RayEnv

Use ray for taking steps in parallel when calling step_batch.

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

Bases: plangym.core.PlanEnv

Remote ray Actor interface for a plangym.PlanEnv.

property unwrapped(self)

Completely unwrap this Environment.

Returns

The base non-wrapped plangym.Environment instance

Return type

plangym.Environment

property name(self)

Return the name of the environment.

Return type

str

setup(self)[source]

Init the wrapped environment.

step(self, 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) – 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(self, 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) – 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(self, return_state=True)[source]

Restart the environment.

Parameters

return_state (bool) –

Return type

[numpy.ndarray, tuple]

get_state(self)[source]

Recover the internal state of the simulation.

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

set_state(self, state)[source]

Set the internal state of the simulation.

Parameters

state – Target state to be set in the environment.

Returns

None

class 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) –

property workers(self)

Remote actors exposing copies of the environment.

Return type

List[RemoteEnv]

setup(self)[source]

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

make_transitions(self, 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) –

reset(self, return_state=True)[source]

Restart the environment.

Parameters

return_state (bool) –

Return type

[numpy.ndarray, tuple]

sync_states(self, 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