Skip to content

Commit

Permalink
simplified step_backwards
Browse files Browse the repository at this point in the history
  • Loading branch information
michalkoziarski committed Aug 29, 2023
1 parent d813a88 commit ece416a
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions gflownet/envs/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,30 +624,18 @@ def step_backwards(
Returns
-------
self.state : list
The sequence after executing the action
The state after executing the action.
action : int
Action index
Given action.
valid : bool
False, if the action is not allowed for the current state.
"""
if self.continuous:
# Replace the continuous value of threshold by -1 to allow checking it.
action = self.action2representative(action)
do_step, self.state, action_to_check = self._pre_step(
action,
backward=True,
skip_mask_check=(skip_mask_check or self.skip_mask_check),
)
if not do_step:
return self.state, action, False
parents, parents_a = self.get_parents()
state_next = parents[parents_a.index(action)]
self.state = state_next
self.done = False
self.n_actions += 1
return self.state, action, True
# Replace the continuous value of threshold by -1 to allow checking it.
action_to_check = self.action2representative(action)
_, _, valid = super().step_backwards(action_to_check, skip_mask_check=skip_mask_check)
return self.state, action, valid

def set_state(self, state: List, done: Optional[bool] = False):
"""
Expand Down

2 comments on commit ece416a

@alexhernandezgarcia
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit strange. I think we should just add action_to_check = self.action2representative(action) before calling the method _pre_step() in the base env, and then we could remove step_backwards() altogether from the tree env.

@alexhernandezgarcia
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do this later too...

Please sign in to comment.