RubiksCube
Bases: Environment[State, MultiDiscreteArray, Observation]
A JAX implementation of the Rubik's Cube with a configurable cube size (by default, 3) and number of scrambles at reset.
-
observation:
Observation
- cube: jax array (int8) of shape (6, cube_size, cube_size): each cell contains the index of the corresponding colour of the sticker in the scramble.
- step_count: jax array (int32) of shape (): specifies how many timesteps have elapsed since environment reset.
-
action: multi discrete array containing the move to perform (face, depth, and direction).
-
reward: jax array (float) of shape (): by default, 1.0 if cube is solved, otherwise 0.0.
-
episode termination: if either the cube is solved or a time limit is reached.
-
state:
State
- cube: jax array (int8) of shape (6, cube_size, cube_size): each cell contains the index of the corresponding colour of the sticker in the scramble.
- step_count: jax array (int32) of shape (): specifies how many timesteps have elapsed since environment reset.
- key: jax array (uint) of shape (2,) used for seeding the sampling for scrambling on reset.
1 2 3 4 5 6 7 8 |
|
Instantiate a RubiksCube
environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
generator
|
Optional[Generator]
|
|
None
|
time_limit
|
int
|
the number of steps allowed before an episode terminates. Defaults to 200. |
200
|
reward_fn
|
Optional[RewardFn]
|
|
None
|
viewer
|
Optional[Viewer[State]]
|
|
None
|
Source code in jumanji/environments/logic/rubiks_cube/env.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
action_spec: specs.MultiDiscreteArray
cached
property
#
Returns the action spec. An action is composed of 3 elements that range in: 6 faces, each with cube_size//2 possible depths, and 3 possible directions.
Returns:
Name | Type | Description |
---|---|---|
action_spec |
MultiDiscreteArray
|
|
observation_spec: specs.Spec[Observation]
cached
property
#
Specifications of the observation of the RubiksCube
environment.
Returns:
Type | Description |
---|---|
Spec[Observation]
|
Spec containing all the specifications for all the |
animate(states, interval=200, save_path=None)
#
Creates an animated gif of the cube based on the sequence of states.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
states
|
Sequence[State]
|
a list of |
required |
interval
|
int
|
the delay between frames in milliseconds, default to 200. |
200
|
save_path
|
Optional[str]
|
the path where the animation file should be saved. If it is None, the plot will not be saved. |
None
|
Returns:
Type | Description |
---|---|
FuncAnimation
|
animation.FuncAnimation: the animation object that was created. |
Source code in jumanji/environments/logic/rubiks_cube/env.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
close()
#
Perform any necessary cleanup.
Environments will automatically :meth:close()
themselves when
garbage collected or when the program exits.
Source code in jumanji/environments/logic/rubiks_cube/env.py
250 251 252 253 254 255 256 |
|
render(state)
#
Renders the current state of the cube.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State
|
the current state to be rendered. |
required |
Source code in jumanji/environments/logic/rubiks_cube/env.py
223 224 225 226 227 228 229 |
|
reset(key)
#
Resets the environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
PRNGKey
|
needed for scramble. |
required |
Returns:
Name | Type | Description |
---|---|---|
state |
State
|
|
timestep |
TimeStep[Observation]
|
|
Source code in jumanji/environments/logic/rubiks_cube/env.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
step(state, action)
#
Run one timestep of the environment's dynamics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State
|
|
required |
action
|
Array
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
next_state |
State
|
|
next_timestep |
TimeStep[Observation]
|
|
Source code in jumanji/environments/logic/rubiks_cube/env.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|