Shortcuts

openrl.envs.mpe package

Subpackages

Submodules

openrl.envs.mpe.core module

class openrl.envs.mpe.core.Action[源代码]

基类:object

class openrl.envs.mpe.core.Agent[源代码]

基类:openrl.envs.mpe.core.Entity

class openrl.envs.mpe.core.AgentState[源代码]

基类:openrl.envs.mpe.core.EntityState

class openrl.envs.mpe.core.Entity[源代码]

基类:object

property mass
class openrl.envs.mpe.core.EntityState[源代码]

基类:object

class openrl.envs.mpe.core.Landmark[源代码]

基类:openrl.envs.mpe.core.Entity

class openrl.envs.mpe.core.Wall(orient='H', axis_pos=0.0, endpoints=(- 1, 1), width=0.1, hard=True)[源代码]

基类:object

class openrl.envs.mpe.core.World[源代码]

基类:object

apply_action_force(p_force)[源代码]
apply_environment_force(p_force)[源代码]
assign_agent_colors()[源代码]
assign_landmark_colors()[源代码]
calculate_distances()[源代码]
property entities
get_entity_collision_force(ia, ib)[源代码]
get_wall_collision_force(entity, wall)[源代码]
integrate_state(p_force)[源代码]
name: str
property policy_agents
property scripted_agents
step()[源代码]
update_agent_state(agent)[源代码]

openrl.envs.mpe.mpe_env module

openrl.envs.mpe.mpe_env.make(id: str, render_mode: Optional[str] = None, **kwargs: Any) gymnasium.core.Env[源代码]

openrl.envs.mpe.multi_discrete module

class openrl.envs.mpe.multi_discrete.MultiDiscrete(array_of_param_array)[源代码]

基类:Generic[gym.spaces.space.T_cov]

  • The multi-discrete action space consists of a series of discrete action spaces with different parameters

  • It can be adapted to both a Discrete action space or a continuous (Box) action space

  • It is useful to represent game controllers or keyboards where each key can be represented as a discrete action space

  • It is parametrized by passing an array of arrays containing [min, max] for each discrete action space

    where the discrete action space can take any integers from min to max (both inclusive)

Note: A value of 0 always need to represent the NOOP action. e.g. Nintendo Game Controller - Can be conceptualized as 3 discrete action spaces:

  1. Arrow Keys: Discrete 5 - NOOP[0], UP[1], RIGHT[2], DOWN[3], LEFT[4] - params: min: 0, max: 4

  2. Button A: Discrete 2 - NOOP[0], Pressed[1] - params: min: 0, max: 1

  3. Button B: Discrete 2 - NOOP[0], Pressed[1] - params: min: 0, max: 1

  • Can be initialized as

    MultiDiscrete([ [0,4], [0,1], [0,1] ])

contains(x)[源代码]

Return boolean specifying if x is a valid member of this space.

sample()[源代码]

Returns a array with one sample from each discrete action space

property shape

Return the shape of the space as an immutable property.

openrl.envs.mpe.multiagent_env module

class openrl.envs.mpe.multiagent_env.EnvSpec(id: str)[源代码]

基类:object

id: str
class openrl.envs.mpe.multiagent_env.MultiAgentEnv(world, reset_callback=None, reward_callback=None, observation_callback=None, info_callback=None, done_callback=None, post_step_callback=None, shared_viewer=True, discrete_action=True, render_mode=None)[源代码]

基类:Generic[gymnasium.core.ObsType, gymnasium.core.ActType]

property agent_num
static construct_obs(obs_n)[源代码]
deal_render()[源代码]
metadata: dict[str, Any] = {'render.modes': ['human', 'rgb_array']}
render(mode='rgb_array', close=False)[源代码]

Compute the render frames as specified by render_mode during the initialization of the environment.

The environment's metadata render modes (env.metadata["render_modes"]) should contain the possible ways to implement the render modes. In addition, list versions for most render modes is achieved through gymnasium.make which automatically applies a wrapper to collect rendered frames.

Note:

As the render_mode is known during __init__, the objects used to render the environment state should be initialised in __init__.

By convention, if the render_mode is:

  • None (default): no render is computed.

  • "human": The environment is continuously rendered in the current display or terminal, usually for human consumption. This rendering should occur during step() and render() doesn't need to be called. Returns None.

  • "rgb_array": Return a single frame representing the current state of the environment. A frame is a np.ndarray with shape (x, y, 3) representing RGB values for an x-by-y pixel image.

  • "ansi": Return a strings (str) or StringIO.StringIO containing a terminal-style text representation for each time step. The text can include newlines and ANSI escape sequences (e.g. for colors).

  • "rgb_array_list" and "ansi_list": List based version of render modes are possible (except Human) through the wrapper, gymnasium.wrappers.RenderCollection that is automatically applied during gymnasium.make(..., render_mode="rgb_array_list"). The frames collected are popped after render() is called or reset().

Note:

Make sure that your class's metadata "render_modes" key includes the list of supported modes.

在 0.25.0 版更改: The render function was changed to no longer accept parameters, rather these parameters should be specified in the environment initialised, i.e., gymnasium.make("CartPole-v1", render_mode="human")

reset(*, seed: Optional[Union[int, List[int]]] = None, options: Optional[Dict[str, Any]] = None) Tuple[gymnasium.core.ObsType, Dict[str, Any]][源代码]

Resets the environment to an initial internal state, returning an initial observation and info.

This method generates a new starting state often with some randomness to ensure that the agent explores the state space and learns a generalised policy about the environment. This randomness can be controlled with the seed parameter otherwise if the environment already has a random number generator and reset() is called with seed=None, the RNG is not reset.

Therefore, reset() should (in the typical use case) be called with a seed right after initialization and then never again.

For Custom environments, the first line of reset() should be super().reset(seed=seed) which implements the seeding correctly.

在 v0.25 版更改: The return_info parameter was removed and now info is expected to be returned.

Args:
seed (optional int): The seed that is used to initialize the environment's PRNG (np_random).

If the environment does not already have a PRNG and seed=None (the default option) is passed, a seed will be chosen from some source of entropy (e.g. timestamp or /dev/urandom). However, if the environment already has a PRNG and seed=None is passed, the PRNG will not be reset. If you pass an integer, the PRNG will be reset even if it already exists. Usually, you want to pass an integer right after the environment has been initialized and then never again. Please refer to the minimal example above to see this paradigm in action.

options (optional dict): Additional information to specify how the environment is reset (optional,

depending on the specific environment)

Returns:
observation (ObsType): Observation of the initial state. This will be an element of observation_space

(typically a numpy array) and is analogous to the observation returned by step().

info (dictionary): This dictionary contains auxiliary information complementing observation. It should be analogous to

the info returned by step().

seed(seed=None)[源代码]
spec: EnvSpec | None = EnvSpec(id='')
step(action_n)[源代码]

Run one timestep of the environment's dynamics using the agent actions.

When the end of an episode is reached (terminated or truncated), it is necessary to call reset() to reset this environment's state for the next episode.

在 0.26 版更改: The Step API was changed removing done in favor of terminated and truncated to make it clearer to users when the environment had terminated or truncated which is critical for reinforcement learning bootstrapping algorithms.

Args:

action (ActType): an action provided by the agent to update the environment state.

Returns:
observation (ObsType): An element of the environment's observation_space as the next observation due to the agent actions.

An example is a numpy array containing the positions and velocities of the pole in CartPole.

reward (SupportsFloat): The reward as a result of taking the action. terminated (bool): Whether the agent reaches the terminal state (as defined under the MDP of the task)

which can be positive or negative. An example is reaching the goal state or moving into the lava from the Sutton and Barton, Gridworld. If true, the user needs to call reset().

truncated (bool): Whether the truncation condition outside the scope of the MDP is satisfied.

Typically, this is a timelimit, but could also be used to indicate an agent physically going out of bounds. Can be used to end the episode prematurely before a terminal state is reached. If true, the user needs to call reset().

info (dict): Contains auxiliary diagnostic information (helpful for debugging, learning, and logging).

This might, for instance, contain: metrics that describe the agent's performance state, variables that are hidden from observations, or individual reward terms that are combined to produce the total reward. In OpenAI Gym <v26, it contains "TimeLimit.truncated" to distinguish truncation and termination, however this is deprecated in favour of returning terminated and truncated variables.

done (bool): (Deprecated) A boolean value for if the episode has ended, in which case further step() calls will

return undefined results. This was removed in OpenAI Gym v26 in favor of terminated and truncated attributes. A done signal may be emitted for different reasons: Maybe the task underlying the environment was solved successfully, a certain timelimit was exceeded, or the physics simulation has entered an invalid state.

openrl.envs.mpe.rendering module

2D rendering framework

class openrl.envs.mpe.rendering.Attr[源代码]

基类:object

disable()[源代码]
enable()[源代码]
class openrl.envs.mpe.rendering.Color(vec4)[源代码]

基类:openrl.envs.mpe.rendering.Attr

enable()[源代码]
class openrl.envs.mpe.rendering.FilledPolygon(v)[源代码]

基类:openrl.envs.mpe.rendering.Geom

render1()[源代码]
class openrl.envs.mpe.rendering.Geom[源代码]

基类:object

add_attr(attr)[源代码]
render()[源代码]
render1()[源代码]
set_color(r, g, b, alpha=1)[源代码]
class openrl.envs.mpe.rendering.Line(start=(0.0, 0.0), end=(0.0, 0.0))[源代码]

基类:openrl.envs.mpe.rendering.Geom

render1()[源代码]
class openrl.envs.mpe.rendering.LineStyle(style)[源代码]

基类:openrl.envs.mpe.rendering.Attr

disable()[源代码]
enable()[源代码]
class openrl.envs.mpe.rendering.LineWidth(stroke)[源代码]

基类:openrl.envs.mpe.rendering.Attr

enable()[源代码]
class openrl.envs.mpe.rendering.Point[源代码]

基类:openrl.envs.mpe.rendering.Geom

render1()[源代码]
class openrl.envs.mpe.rendering.PolyLine(v, close)[源代码]

基类:openrl.envs.mpe.rendering.Geom

render1()[源代码]
set_linewidth(x)[源代码]
class openrl.envs.mpe.rendering.Transform(translation=(0.0, 0.0), rotation=0.0, scale=(1, 1))[源代码]

基类:openrl.envs.mpe.rendering.Attr

disable()[源代码]
enable()[源代码]
set_rotation(new)[源代码]
set_scale(newx, newy)[源代码]
set_translation(newx, newy)[源代码]
class openrl.envs.mpe.rendering.Viewer(width, height, display=None)[源代码]

基类:object

add_geom(geom)[源代码]
add_onetime(geom)[源代码]
close()[源代码]
draw_circle(radius=10, res=30, filled=True, **attrs)[源代码]
draw_line(start, end, **attrs)[源代码]
draw_polygon(v, filled=True, **attrs)[源代码]
draw_polyline(v, **attrs)[源代码]
get_array()[源代码]
render(return_rgb_array=False)[源代码]
set_bounds(left, right, bottom, top)[源代码]
window_closed_by_user()[源代码]
openrl.envs.mpe.rendering.get_display(spec)[源代码]

Convert a display specification (such as :0) into an actual Display object.

Pyglet only supports multiple Displays on Linux.

openrl.envs.mpe.rendering.make_circle(radius=10, res=30, filled=True)[源代码]
openrl.envs.mpe.rendering.make_polygon(v, filled=True)[源代码]
openrl.envs.mpe.rendering.make_polyline(v)[源代码]

openrl.envs.mpe.scenario module

class openrl.envs.mpe.scenario.BaseScenario[源代码]

基类:object

info(agent, world)[源代码]
make_world()[源代码]
reset_world(world)[源代码]

Module contents

openrl.envs.mpe.make_mpe_envs(id: str, env_num: int = 1, render_mode: Optional[Union[str, List[str]]] = None, **kwargs) List[Callable[[], gymnasium.core.Env]][源代码]