-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add local search sampler #208
Changes from 14 commits
1ccf16c
a3af467
d7d95ca
b075d9e
8481673
0cc32f7
4e11c27
e7fa8b6
21ce0c2
5ce1fdc
6f13cff
958139f
2672d9b
8529e4a
a2837bd
354ee04
9c60997
26126df
731e081
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,8 @@ def __init__( | |
self.dummy_action = dummy_action | ||
self.exit_action = exit_action | ||
|
||
# Warning: don't use self.States or self.Actions to initialize an instance of the class. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who is this warning intended for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe us?? Regarding this, what about making them into private variables (e.g., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like we should not initialize a States object using |
||
# Use self.states_from_tensor or self.actions_from_tensor instead. | ||
self.States = self.make_states_class() | ||
self.Actions = self.make_actions_class() | ||
|
||
|
@@ -85,16 +87,20 @@ def states_from_tensor(self, tensor: torch.Tensor): | |
""" | ||
return self.States(tensor) | ||
|
||
def states_from_batch_shape(self, batch_shape: Tuple): | ||
def states_from_batch_shape( | ||
self, batch_shape: Tuple, random: bool = False, sink: bool = False | ||
): | ||
hyeok9855 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Returns a batch of s0 states with a given batch_shape. | ||
|
||
Args: | ||
batch_shape: Tuple representing the shape of the batch of states. | ||
random (optional): Initalize states randomly. | ||
sink (optional): States initialized with s_f (the sink state). | ||
|
||
Returns: | ||
States: A batch of initial states. | ||
""" | ||
return self.States.from_batch_shape(batch_shape) | ||
return self.States.from_batch_shape(batch_shape, random=random, sink=sink) | ||
|
||
def actions_from_tensor(self, tensor: torch.Tensor): | ||
"""Wraps the supplied Tensor an an Actions instance. | ||
|
@@ -218,7 +224,7 @@ def reset( | |
batch_shape = (1,) | ||
if isinstance(batch_shape, int): | ||
batch_shape = (batch_shape,) | ||
return self.States.from_batch_shape( | ||
return self.states_from_batch_shape( | ||
batch_shape=batch_shape, random=random, sink=sink | ||
) | ||
|
||
|
@@ -441,21 +447,21 @@ def reset( | |
batch_shape = (1,) | ||
if isinstance(batch_shape, int): | ||
batch_shape = (batch_shape,) | ||
states = self.States.from_batch_shape( | ||
states = self.states_from_batch_shape( | ||
batch_shape=batch_shape, random=random, sink=sink | ||
) | ||
self.update_masks(states) | ||
|
||
return states | ||
|
||
@abstractmethod | ||
def update_masks(self, states: type[States]) -> None: | ||
def update_masks(self, states: States) -> None: | ||
"""Updates the masks in States. | ||
|
||
Called automatically after each step for discrete environments. | ||
""" | ||
|
||
def make_states_class(self) -> type[States]: | ||
def make_states_class(self) -> type[DiscreteStates]: | ||
env = self | ||
|
||
class DiscreteEnvStates(DiscreteStates): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the major blocker here? Anyone know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure either... This was from here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One guess is this:
In line 436-443:
Also, in line 461-463:
These assume that the action is an integer, which is not true for continuous case, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The blocker: see my response to line 462 of this file in the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function will not work on non-discrete environments!