diff --git a/benchmarks/benchmark_utils.py b/benchmarks/benchmark_utils.py index 720590be315ca03abd07838c4475a5c586edf8dd..42792f98c427589e3b21d230b6451f85b984917e 100644 --- a/benchmarks/benchmark_utils.py +++ b/benchmarks/benchmark_utils.py @@ -12,7 +12,7 @@ def swap_attr(obj, attr, new_val): ... This will set obj.attr to 5 for the duration of the with: block, - restoring the old value at the end of the block. If `attr` doesn't + restoring the old value at the end of the block. If `attr` doesn`t exist on `obj`, it will be created and then deleted at the end of the block. diff --git a/flatland/core/env_observation_builder.py b/flatland/core/env_observation_builder.py index c7f18e2df6f2ca3f2c1942f6d1f0a859e07eb31b..65434ce932d313bf756405ee9c3b8aae58b67d8d 100644 --- a/flatland/core/env_observation_builder.py +++ b/flatland/core/env_observation_builder.py @@ -14,7 +14,7 @@ class ObservationBuilder: """ ObservationBuilder base class. - Derived objects must implement and `observation_space' attribute as a tuple with the dimensions of the returned + Derived objects must implement and `observation_space` attribute as a tuple with the dimensions of the returned observations. """ @@ -32,8 +32,8 @@ class ObservationBuilder: def get_many(self, handles=[]): """ - Called whenever an observation has to be computed for the `env' environment, for each agent with handle - in the `handles' list. + Called whenever an observation has to be computed for the `env` environment, for each agent with handle + in the `handles` list. Parameters ---------- @@ -44,7 +44,7 @@ class ObservationBuilder: ------- function A dictionary of observation structures, specific to the corresponding environment, with handles from - `handles' as keys. + `handles` as keys. """ observations = {} for h in handles: @@ -53,8 +53,8 @@ class ObservationBuilder: def get(self, handle=0): """ - Called whenever an observation has to be computed for the `env' environment, possibly - for each agent independently (agent id `handle'). + Called whenever an observation has to be computed for the `env` environment, possibly + for each agent independently (agent id `handle`). Parameters ---------- diff --git a/flatland/core/grid/grid4.py b/flatland/core/grid/grid4.py index b4b5b17c9b1e6f5c7abd3c82a1fbf1e5ee96fcfe..da721dd99fbc0ea46124dcd036425df3206aa339 100644 --- a/flatland/core/grid/grid4.py +++ b/flatland/core/grid/grid4.py @@ -24,9 +24,9 @@ class Grid4Transitions(Transitions): """ Grid4Transitions class derived from Transitions. - Special case of `Transitions' over a 2D-grid (FlatLand). + Special case of `Transitions` over a 2D-grid (FlatLand). Transitions are possible to neighboring cells on the grid if allowed. - GridTransitions keeps track of valid transitions supplied as `transitions' + GridTransitions keeps track of valid transitions supplied as `transitions` list, each represented as a bitmap of 16 bits. Whether a transition is allowed or not depends on which direction an agent @@ -67,8 +67,8 @@ class Grid4Transitions(Transitions): """ Get the 4 possible transitions ((N,E,S,W), 4 elements tuple if no diagonal transitions allowed) available for an agent oriented - in direction `orientation' and inside a cell with - transitions `cell_transition'. + in direction `orientation` and inside a cell with + transitions `cell_transition`. Parameters ---------- @@ -90,9 +90,9 @@ class Grid4Transitions(Transitions): """ Set the possible transitions (e.g., (N,E,S,W), 4 elements tuple if no diagonal transitions allowed) available for an agent - oriented in direction `orientation' and inside a cell with transitions - `cell_transition'. A new `cell_transition' is returned with - the specified bits replaced by `new_transitions'. + oriented in direction `orientation` and inside a cell with transitions + `cell_transition'. A new `cell_transition` is returned with + the specified bits replaced by `new_transitions`. Parameters ---------- @@ -107,8 +107,8 @@ class Grid4Transitions(Transitions): ------- int An updated bitmap that replaces the original transitions validity - of `cell_transition' with `new_transitions', for the appropriate - `orientation'. + of `cell_transition' with `new_transitions`, for the appropriate + `orientation`. """ mask = (1 << ((4 - orientation) * 4)) - (1 << ((3 - orientation) * 4)) @@ -127,8 +127,8 @@ class Grid4Transitions(Transitions): def get_transition(self, cell_transition, orientation, direction): """ Get the transition bit (1 value) that determines whether an agent - oriented in direction `orientation' and inside a cell with transitions - `cell_transition' can move to the cell in direction `direction' + oriented in direction `orientation` and inside a cell with transitions + `cell_transition' can move to the cell in direction `direction` relative to the current cell. Parameters @@ -151,8 +151,8 @@ class Grid4Transitions(Transitions): def set_transition(self, cell_transition, orientation, direction, new_transition, remove_deadends=False): """ Set the transition bit (1 value) that determines whether an agent - oriented in direction `orientation' and inside a cell with transitions - `cell_transition' can move to the cell in direction `direction' + oriented in direction `orientation` and inside a cell with transitions + `cell_transition' can move to the cell in direction `direction` relative to the current cell. Parameters @@ -171,8 +171,8 @@ class Grid4Transitions(Transitions): ------- int An updated bitmap that replaces the original transitions validity - of `cell_transition' with `new_transitions', for the appropriate - `orientation'. + of `cell_transition' with `new_transitions`, for the appropriate + `orientation`. """ if new_transition: @@ -196,7 +196,7 @@ class Grid4Transitions(Transitions): 16 bits used to encode the valid transitions for a cell. rotation : int Angle by which to clock-wise rotate the transition bits in - `cell_transition' by. I.e., rotation={0, 90, 180, 270} degrees. + `cell_transition` by. I.e., rotation={0, 90, 180, 270} degrees. Returns ------- diff --git a/flatland/core/grid/grid8.py b/flatland/core/grid/grid8.py index 2ba379a5ecb4099de999905d34daf91ccccac640..a4dcc3d215a3ff0fd699924e489d2fb17191a37c 100644 --- a/flatland/core/grid/grid8.py +++ b/flatland/core/grid/grid8.py @@ -20,9 +20,9 @@ class Grid8Transitions(Transitions): """ Grid8Transitions class derived from Transitions. - Special case of `Transitions' over a 2D-grid (FlatLand). + Special case of `Transitions` over a 2D-grid (FlatLand). Transitions are possible to neighboring cells on the grid if allowed. - GridTransitions keeps track of valid transitions supplied as `transitions' + GridTransitions keeps track of valid transitions supplied as `transitions` list, each represented as a bitmap of 64 bits. 0=North, 1=North-East, etc. @@ -82,8 +82,8 @@ class Grid8Transitions(Transitions): ------- int An updated bitmap that replaces the original transitions validity - of `cell_transition' with `new_transitions', for the appropriate - `orientation'. + of `cell_transition' with `new_transitions`, for the appropriate + `orientation`. """ mask = (1 << ((8 - orientation) * 8)) - (1 << ((7 - orientation) * 8)) @@ -106,8 +106,8 @@ class Grid8Transitions(Transitions): def get_transition(self, cell_transition, orientation, direction): """ Get the transition bit (1 value) that determines whether an agent - oriented in direction `orientation' and inside a cell with transitions - `cell_transition' can move to the cell in direction `direction' + oriented in direction `orientation` and inside a cell with transitions + `cell_transition' can move to the cell in direction `direction` relative to the current cell. Parameters @@ -131,8 +131,8 @@ class Grid8Transitions(Transitions): """ Set the transition bit (1 value) that determines whether an agent - oriented in direction `orientation' and inside a cell with transitions - `cell_transition' can move to the cell in direction `direction' + oriented in direction `orientation` and inside a cell with transitions + `cell_transition' can move to the cell in direction `direction` relative to the current cell. Parameters @@ -150,8 +150,8 @@ class Grid8Transitions(Transitions): ------- int An updated bitmap that replaces the original transitions validity - of `cell_transition' with `new_transitions', for the appropriate - `orientation'. + of `cell_transition' with `new_transitions`, for the appropriate + `orientation`. """ if new_transition: @@ -172,7 +172,7 @@ class Grid8Transitions(Transitions): 64 bits used to encode the valid transitions for a cell. rotation : int Angle by which to clock-wise rotate the transition bits in - `cell_transition' by. I.e., rotation={0, 45, 90, 135, 180, + `cell_transition` by. I.e., rotation={0, 45, 90, 135, 180, 225, 270, 315} degrees. Returns diff --git a/flatland/core/grid/rail_env_grid.py b/flatland/core/grid/rail_env_grid.py index 680e945316ab3a4876bd36fa8e6b001ea346cd26..fe85abd7dc1b3f108c5944c61f21512c7a8a171c 100644 --- a/flatland/core/grid/rail_env_grid.py +++ b/flatland/core/grid/rail_env_grid.py @@ -3,7 +3,7 @@ from flatland.core.grid.grid4 import Grid4Transitions class RailEnvTransitions(Grid4Transitions): """ - Special case of `GridTransitions' over a 2D-grid, with a pre-defined set + Special case of `GridTransitions` over a 2D-grid, with a pre-defined set of transitions mimicking the types of real Swiss rail connections. -------------------------------------------------------------------------- diff --git a/flatland/core/transition_map.py b/flatland/core/transition_map.py index 232d6fdab02c57da95bf04c631e4905986c71327..ce6ceda6825b3f8c663bb49a3bb9c05b67550d60 100644 --- a/flatland/core/transition_map.py +++ b/flatland/core/transition_map.py @@ -23,7 +23,7 @@ class TransitionMap: def get_transitions(self, cell_id): """ Return a tuple of transitions available in a cell specified by - `cell_id' (e.g., a tuple of size of the maximum number of transitions, + `cell_id` (e.g., a tuple of size of the maximum number of transitions, with values 0 or 1, or potentially in between, for stochastic transitions). @@ -43,8 +43,8 @@ class TransitionMap: def set_transitions(self, cell_id, new_transitions): """ - Replaces the available transitions in cell `cell_id' with the tuple - `new_transitions'. `new_transitions' must have + Replaces the available transitions in cell `cell_id` with the tuple + `new_transitions'. `new_transitions` must have one element for each possible transition. Parameters @@ -60,7 +60,7 @@ class TransitionMap: def get_transition(self, cell_id, transition_index): """ - Return the status of whether an agent in cell `cell_id' can perform a + Return the status of whether an agent in cell `cell_id` can perform a movement along transition `transition_index (e.g., the NESW direction of movement, for agents on a grid). @@ -85,8 +85,8 @@ class TransitionMap: def set_transition(self, cell_id, transition_index, new_transition): """ - Replaces the validity of transition to `transition_index' in cell - `cell_id' with the new `new_transition'. + Replaces the validity of transition to `transition_index` in cell + `cell_id' with the new `new_transition`. Parameters @@ -156,7 +156,7 @@ class GridTransitionMap(TransitionMap): def get_transitions(self, row, column, orientation): """ Return a tuple of transitions available in a cell specified by - `cell_id' (e.g., a tuple of size of the maximum number of transitions, + `cell_id` (e.g., a tuple of size of the maximum number of transitions, with values 0 or 1, or potentially in between, for stochastic transitions). @@ -178,8 +178,8 @@ class GridTransitionMap(TransitionMap): def set_transitions(self, cell_id, new_transitions): """ - Replaces the available transitions in cell `cell_id' with the tuple - `new_transitions'. `new_transitions' must have + Replaces the available transitions in cell `cell_id` with the tuple + `new_transitions'. `new_transitions` must have one element for each possible transition. Parameters @@ -204,7 +204,7 @@ class GridTransitionMap(TransitionMap): def get_transition(self, cell_id, transition_index): """ - Return the status of whether an agent in cell `cell_id' can perform a + Return the status of whether an agent in cell `cell_id` can perform a movement along transition `transition_index (e.g., the NESW direction of movement, for agents on a grid). @@ -232,8 +232,8 @@ class GridTransitionMap(TransitionMap): def set_transition(self, cell_id, transition_index, new_transition, remove_deadends=False): """ - Replaces the validity of transition to `transition_index' in cell - `cell_id' with the new `new_transition'. + Replaces the validity of transition to `transition_index` in cell + `cell_id' with the new `new_transition`. Parameters @@ -261,7 +261,7 @@ class GridTransitionMap(TransitionMap): def save_transition_map(self, filename): """ - Save the transitions grid as `filename', in npy format. + Save the transitions grid as `filename`, in npy format. Parameters ---------- @@ -273,9 +273,9 @@ class GridTransitionMap(TransitionMap): def load_transition_map(self, package, resource): """ - Load the transitions grid from `filename' (npy format). + Load the transitions grid from `filename` (npy format). The load function only updates the transitions grid, and possibly width and height, but the object has to be - initialized with the correct `transitions' object anyway. + initialized with the correct `transitions` object anyway. Parameters ---------- @@ -285,7 +285,7 @@ class GridTransitionMap(TransitionMap): Name of the file from which to load the transitions grid within the package. override_gridsize : bool If override_gridsize=True, the width and height of the GridTransitionMap object are replaced with the size - of the map loaded from `filename'. If override_gridsize=False, the transitions grid is either cropped (if + of the map loaded from `filename`. If override_gridsize=False, the transitions grid is either cropped (if the grid size is larger than (height,width) ) or padded with zeros (if the grid size is smaller than (height,width) ) diff --git a/flatland/core/transitions.py b/flatland/core/transitions.py index 5049c23bff3667a08375fee270a8867ca013c467..995c2d4e7a911c4e01b64b0673c2bdf1420d324c 100644 --- a/flatland/core/transitions.py +++ b/flatland/core/transitions.py @@ -12,7 +12,7 @@ class Transitions: Generic class that implements checks to control whether a certain transition is allowed (agent facing a direction - `orientation' and moving into direction `orientation') + `orientation' and moving into direction `orientation`) """ def get_type(self): @@ -21,7 +21,7 @@ class Transitions: def get_transitions(self, cell_transition, orientation): """ Return a tuple of transitions available in a cell specified by - `cell_transition' for an agent facing direction `orientation' + `cell_transition' for an agent facing direction `orientation` (e.g., a tuple of size of the maximum number of transitions, with values 0 or 1, or potentially in between, for stochastic transitions). @@ -45,9 +45,9 @@ class Transitions: def set_transitions(self, cell_transition, orientation, new_transitions): """ - Return a `cell_transition' specification where the transitions - available for an agent facing direction `orientation' are replaced - with the tuple `new_transitions'. `new_orientations' must have + Return a `cell_transition` specification where the transitions + available for an agent facing direction `orientation` are replaced + with the tuple `new_transitions'. `new_orientations` must have one element for each possible transition. Parameters @@ -65,8 +65,8 @@ class Transitions: ------- [cell-content] An updated class-specific object that replaces the original - transitions validity of `cell_transition' with `new_transitions', - for the appropriate `orientation'. + transitions validity of `cell_transition' with `new_transitions`, + for the appropriate `orientation`. """ raise NotImplementedError() @@ -74,8 +74,8 @@ class Transitions: def get_transition(self, cell_transition, orientation, direction): """ Return the status of whether an agent oriented in directions - `orientation' and inside a cell with transitions `cell_transition' - can move to the cell in direction `direction' relative + `orientation' and inside a cell with transitions `cell_transition` + can move to the cell in direction `direction` relative to the current cell. Parameters @@ -101,11 +101,11 @@ class Transitions: def set_transition(self, cell_transition, orientation, direction, new_transition): """ - Return a `cell_transition' specification where the status of - whether an agent oriented in direction `orientation' and inside - a cell with transitions `cell_transition' can move to the cell - in direction `direction' relative to the current cell is set - to `new_transition'. + Return a `cell_transition` specification where the status of + whether an agent oriented in direction `orientation` and inside + a cell with transitions `cell_transition` can move to the cell + in direction `direction` relative to the current cell is set + to `new_transition`. Parameters ---------- @@ -125,8 +125,8 @@ class Transitions: ------- [cell-content] An updated class-specific object that replaces the original - transitions validity of `cell_transition' with `new_transitions', - for the appropriate `orientation' to `direction'. + transitions validity of `cell_transition' with `new_transitions`, + for the appropriate `orientation' to `direction`. """ raise NotImplementedError() diff --git a/flatland/envs/observations.py b/flatland/envs/observations.py index 706e9bdeaf04d60fe076af6f50cd07077548a32f..ca9f4633a0b3d7a445ba54f753527d3a2bcc0cd3 100644 --- a/flatland/envs/observations.py +++ b/flatland/envs/observations.py @@ -85,10 +85,10 @@ class TreeObsForRailEnv(ObservationBuilder): # Fill in the (up to) 4 neighboring nodes # direction is the direction of movement, meaning that at least a possible orientation of an agent - # in cell (row,col) allows a movement in direction `direction' + # in cell (row,col) allows a movement in direction `direction` nodes_queue = deque(self._get_and_update_neighbors(position, target_nr, 0, enforce_target_direction=-1)) - # BFS from target `position' to all the reachable nodes in the grid + # BFS from target `position` to all the reachable nodes in the grid # Stop the search if the target position is re-visited, in any direction visited = {(position[0], position[1], 0), (position[0], position[1], 1), (position[0], position[1], 2), (position[0], position[1], 3)} @@ -124,7 +124,7 @@ class TreeObsForRailEnv(ObservationBuilder): possible_directions = [0, 1, 2, 3] if enforce_target_direction >= 0: - # The agent must land into the current cell with orientation `enforce_target_direction'. + # The agent must land into the current cell with orientation `enforce_target_direction`. # This is only possible if the agent has arrived from the cell in the opposite direction! possible_directions = [(enforce_target_direction + 2) % 4] @@ -137,7 +137,7 @@ class TreeObsForRailEnv(ObservationBuilder): # Check all possible transitions in new_cell for agent_orientation in range(4): - # Is a transition along movement `desired_movement_from_new_cell' to the current cell possible? + # Is a transition along movement `desired_movement_from_new_cell` to the current cell possible? is_valid = self.env.rail.get_transition((new_cell[0], new_cell[1], agent_orientation), desired_movement_from_new_cell) @@ -170,8 +170,8 @@ class TreeObsForRailEnv(ObservationBuilder): def get_many(self, handles=None): """ - Called whenever an observation has to be computed for the `env' environment, for each agent with handle - in the `handles' list. + Called whenever an observation has to be computed for the `env` environment, for each agent with handle + in the `handles` list. """ if handles is None: @@ -199,7 +199,7 @@ class TreeObsForRailEnv(ObservationBuilder): def get(self, handle): """ - Computes the current observation for agent `handle' in env + Computes the current observation for agent `handle` in env The observation vector is composed of 4 sequential parts, corresponding to data from the up to 4 possible movements in a RailEnv (up to because only a subset of possible transitions are allowed in RailEnv). @@ -460,7 +460,7 @@ class TreeObsForRailEnv(ObservationBuilder): last_is_dead_end = True if not last_is_dead_end: - # Keep walking through the tree along `direction' + # Keep walking through the tree along `direction` exploring = True # convert one-hot encoding to 0,1,2,3 direction = np.argmax(cell_transitions) @@ -479,7 +479,7 @@ class TreeObsForRailEnv(ObservationBuilder): last_is_terminal = True break - # `position' is either a terminal node or a switch + # `position` is either a terminal node or a switch # ############################# # ############################# @@ -749,8 +749,8 @@ class LocalObsForRailEnv(ObservationBuilder): def get_many(self, handles=None): """ - Called whenever an observation has to be computed for the `env' environment, for each agent with handle - in the `handles' list. + Called whenever an observation has to be computed for the `env` environment, for each agent with handle + in the `handles` list. """ observations = {} diff --git a/flatland/envs/rail_generators.py b/flatland/envs/rail_generators.py index 7e718eb3888b8fec916905c29dbacc1d5b225402..a6d1b9c70f1f924fb63d3636a00d756a2d22c501 100644 --- a/flatland/envs/rail_generators.py +++ b/flatland/envs/rail_generators.py @@ -250,7 +250,7 @@ def rail_from_grid_transition_map(rail_map) -> RailGenerator: Returns ------- function - Generator function that always returns the given `rail_map' object. + Generator function that always returns the given `rail_map` object. """ def generator(width: int, height: int, num_agents: int, num_resets: int = 0) -> RailGeneratorProduct: diff --git a/flatland/envs/schedule_generators.py b/flatland/envs/schedule_generators.py index ba65ffec819814f899c9d66143029524f4c35841..9ec89182cb3bef68959a04ced876832008d84fb3 100644 --- a/flatland/envs/schedule_generators.py +++ b/flatland/envs/schedule_generators.py @@ -117,7 +117,7 @@ def sparse_schedule_generator(speed_ratio_map: Mapping[float, float] = None) -> def random_schedule_generator(speed_ratio_map: Mapping[float, float] = None) -> ScheduleGenerator: """ - Given a `rail' GridTransitionMap, return a random placement of agents (initial position, direction and target). + Given a `rail` GridTransitionMap, return a random placement of agents (initial position, direction and target). Parameters ---------- diff --git a/flatland/utils/rendertools.py b/flatland/utils/rendertools.py index 802b361b623cdaea08271f5748ac86194056bdf2..99958bf38449ef8eb58c519990f1975106409c4e 100644 --- a/flatland/utils/rendertools.py +++ b/flatland/utils/rendertools.py @@ -560,7 +560,7 @@ class RenderTool(object): position = agent.position direction = agent.direction for possible_directions in range(4): - # Is a transition along movement `desired_movement_from_new_cell' to the current cell possible? + # Is a transition along movement `desired_movement_from_new_cell` to the current cell possible? isValid = env.rail.get_transition((*agent.position, agent.direction), possible_directions) if isValid: direction = possible_directions diff --git a/make_docs.py b/make_docs.py index 54fa84b3324f36769072b2b3f7da33ed8aa666bb..9a954d6ade893057d8610b4bd341b04f852f2d06 100644 --- a/make_docs.py +++ b/make_docs.py @@ -19,7 +19,9 @@ def remove_exists(filename): # clean docs config and html files, and rebuild everything -remove_exists('docs/flatland*.rst') +# wildcards do not work under Windows +for file in glob.glob(r'./docs/flatland*.rst'): + remove_exists(file) remove_exists('docs/modules.rst') # copy md files from root folder into docs folder diff --git a/tests/test_flatland_envs_observations.py b/tests/test_flatland_envs_observations.py index c96e8db00fe721f42667aed4833d034a47f19156..9bf7df53570aa672739d409d598447cd27d5759b 100644 --- a/tests/test_flatland_envs_observations.py +++ b/tests/test_flatland_envs_observations.py @@ -58,7 +58,7 @@ def _step_along_shortest_path(env, obs_builder, rail): # Check all possible transitions in new_cell for agent_orientation in range(4): - # Is a transition along movement `entry_direction' to the neighbour possible? + # Is a transition along movement `entry_direction` to the neighbour possible? is_valid = obs_builder.env.rail.get_transition((neighbour[0], neighbour[1], agent_orientation), desired_movement_from_new_cell) if is_valid: diff --git a/tox.ini b/tox.ini index 282d83888de34042ebad21278867b040b3663c79..b7a359b43c79cbb5d274755b35fd9f6a7873daff 100644 --- a/tox.ini +++ b/tox.ini @@ -21,8 +21,6 @@ commands = flake8 flatland tests examples benchmarks [testenv:docs] -; TODO https://gitlab.aicrowd.com/flatland/flatland/issues/33 docs requires make installed, therefore exclude Windows -platform = linux|linux2|darwin ; use python3.6 because of incompatibility under Windows of the pycairo installed through conda for py37 basepython = python3.6 whitelist_externals = make @@ -46,8 +44,6 @@ commands = make docs [testenv:coverage] -; TODO https://gitlab.aicrowd.com/flatland/flatland/issues/33 coverage requires make, therefore exclude Windows -platform = linux|linux2|darwin ; use python3.6 because of incompatibility under Windows of the pycairo installed through conda for py37 basepython = python3.6 whitelist_externals = make