in compiler_gym/envs/loop_tool/service/loop_tool_compilation_session.py [0:0]
def apply_action(self, action: Action) -> Tuple[bool, Optional[ActionSpace], bool]:
if len(action.choice) != 1:
raise ValueError("Invalid choice count")
choice_index = action.choice[0].named_discrete_value_index
if choice_index < 0 or choice_index >= len(
self.action_space.choice[0].named_discrete_space.value
):
raise ValueError("Out-of-range")
logger.info("Applied action %d", choice_index)
act = self.action_space.choice[0].named_discrete_space.value[choice_index]
if self.mode not in ["size", "select"]:
raise RuntimeError("Invalid mode set: {}".format(self.mode))
if act == "toggle_mode":
if self.mode == "size":
self.mode = "select"
elif self.mode == "select":
self.mode = "size"
if act == "toggle_thread":
self.thread[self.cursor] = not self.thread[self.cursor]
if act == "down":
# always loop around
if self.mode == "size":
self.resize(-1)
elif self.mode == "select":
next_cursor = (self.cursor - 1) % len(self.order)
self.cursor = next_cursor
if act == "up":
# always loop around
if self.mode == "size":
self.resize(1)
elif self.mode == "select":
next_cursor = (self.cursor + 1) % len(self.order)
self.cursor = next_cursor
return False, None, False