Skip to content

Commit

Permalink
Issue #113: Reset previous action on reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark2000 committed Feb 4, 2024
1 parent d1e0b91 commit e484e3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.action_list = []
self.action_map = {}

def reset_pre_sim(self) -> None:
"""Reset the previous action key."""
self.prev_action_key = None # Used to avoid retasking of BSK tasks
return super().reset_pre_sim()

def add_action(
self, act_fn, act_name: Optional[str] = None, n_actions: Optional[int] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

@patch.multiple(sa.DiscreteSatAction, __abstractmethods__=set())
@patch("bsk_rl.envs.general_satellite_tasking.scenario.satellites.Satellite.__init__")
@patch(
"bsk_rl.envs.general_satellite_tasking.scenario.satellites.Satellite.reset_pre_sim",
MagicMock,
)
class TestDiscreteSatAction:
def test_init(self, sat_init):
sa.DiscreteSatAction()
Expand Down Expand Up @@ -51,6 +55,7 @@ def test_add_multiple_actions(self, sat_init, n_actions):
)
def test_set_action(self, sat_init, disable_timed):
sat = sa.DiscreteSatAction()
sat.reset_pre_sim()
sat.action_list = [MagicMock(return_value="act_key")]
sat.set_action(0)
disable_timed.assert_called_once()
Expand All @@ -62,9 +67,19 @@ def test_action_space(self, sat_init):
sat.action_list = [0, 1, 2]
assert sat.action_space == spaces.Discrete(3)

def test_reset_pre_sim(self, sat_init):
sat = sa.DiscreteSatAction()
sat.prev_action_key = "some_action"
sat.reset_pre_sim()
assert sat.prev_action_key is None


@patch.multiple(sa.DiscreteSatAction, __abstractmethods__=set())
@patch("bsk_rl.envs.general_satellite_tasking.scenario.satellites.Satellite.__init__")
@patch(
"bsk_rl.envs.general_satellite_tasking.scenario.satellites.Satellite.reset_pre_sim",
MagicMock,
)
class TestFSWAction:
def test_init(self, sat_init):
FSWAct = sa.fsw_action_gen("cool_action")
Expand All @@ -75,6 +90,7 @@ def test_init(self, sat_init):
def make_action_sat(self):
FSWAct = sa.fsw_action_gen("cool_action", 60.0)
sat = FSWAct()
sat.reset_pre_sim()
sat.fsw = MagicMock(cool_action=MagicMock())
sat.log_info = MagicMock()
sat._disable_timed_terminal_event = MagicMock()
Expand All @@ -93,6 +109,7 @@ def test_act(self, sat_init):
def make_action_sat_configured(self):
FSWAct = sa.fsw_action_gen("cool_action", 59.0).configure(action_duration=60.0)
sat = FSWAct()
sat.reset_pre_sim()
sat.fsw = MagicMock(cool_action=MagicMock())
sat.log_info = MagicMock()
sat._disable_timed_terminal_event = MagicMock()
Expand Down Expand Up @@ -158,6 +175,7 @@ def test_image_retask(self, sat_init, target):
@pytest.mark.parametrize("target", [1, "target_1", MockTarget()])
def test_set_action(self, sat_init, discrete_set, target):
sat = sa.ImagingActions()
sat.prev_action_key = None
sat._disable_image_event = MagicMock()
sat.image = MagicMock()
sat.set_action(target)
Expand Down

0 comments on commit e484e3f

Please sign in to comment.