Skip to content

Commit

Permalink
Issue #164: Deprecate log_info in favor of logger.info
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark2000 committed Jul 29, 2024
1 parent ca0638a commit e4dcaec
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 28 deletions.
6 changes: 6 additions & 0 deletions docs/source/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Version 1.0.1
instead of :class:`~bsk_rl.scene.Scenario`.
* Added a new :ref:`examples` script that demonstrates how to include
a targets with cloud coverage and a rewarder that accounts for cloud cover.
* Reformat the info dictionary to be more consistent across environments. All satellites now
have a ``requires_retasking`` key, as opposed to a global list of satellites that require retasking.
Each satellite also gets ``d_ts`` in its info dictionary. Info and warning messages are no longer
saved in the info dict.
* ``log_info`` and ``log_warning`` are deprecated by :class:`~bsk_rl.sats.Satellite`, in favor of
``logger.info`` and ``logger.warning``.


Version 1.0.0
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ readme = "README.md"
requires-python = ">=3.9.0"
license = { text = "MIT" }
dependencies = [
"Deprecated",
"gymnasium",
"numpy",
"pandas",
Expand Down
4 changes: 2 additions & 2 deletions src/bsk_rl/act/discrete_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def set_action(self, action: int, prev_action_key=None) -> str:
The name of the activated action.
"""
assert action == 0
self.satellite.log_info(f"{self.name} tasked for {self.duration} seconds")
self.satellite.logger.info(f"{self.name} tasked for {self.duration} seconds")
self.satellite.update_timed_terminal_event(
self.simulator.sim_time + self.duration, info=f"for {self.fsw_action}"
)
Expand Down Expand Up @@ -285,7 +285,7 @@ def set_action(self, action: int, prev_action_key: Optional[str] = None) -> str:
:meta_private:
"""
self.satellite.log_info(f"target index {action} tasked")
self.satellite.logger.info(f"target index {action} tasked")
return self.image(action, prev_action_key)

def set_action_override(
Expand Down
4 changes: 3 additions & 1 deletion src/bsk_rl/gym.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ def _step(self, actions: MultiSatAct) -> None:
satellite.requires_retasking = False
else:
if satellite.requires_retasking:
satellite.log_warning(f"Requires retasking but received no task.")
satellite.logger.warning(
f"Requires retasking but received no task."
)

previous_time = self.simulator.sim_time # should these be recorded in simulator
self.simulator.run()
Expand Down
2 changes: 1 addition & 1 deletion src/bsk_rl/sats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MySatellite(Satellite):
* :class:`~Satellite.reset_pre_sim_init` - Called on reset before the simulation is constructed.
* :class:`~Satellite.reset_post_sim_init` - Called on reset after the simulation is constructed.
* :class:`~Satellite.log_info` - Logs a message to ``INFO``, associating it with the satellite.
* ``logger.info/warning/debug`` - Logs a message to ``INFO``, associating it with the satellite.
Satellite Varieties
-------------------
Expand Down
4 changes: 2 additions & 2 deletions src/bsk_rl/sats/access_satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def enable_target_window(self, target: "Target"):
types="target",
filter=self.default_access_filter,
)[target]
self.log_info(
self.logger.info(
f"{target} window enabled: {next_window[0]:.1f} to {next_window[1]:.1f}"
)
self.update_timed_terminal_event(
Expand All @@ -638,6 +638,6 @@ def task_target_for_imaging(self, target: "Target"):
target: Selected target
"""
msg = f"{target} tasked for imaging"
self.log_info(msg)
self.logger.info(msg)
self.fsw.action_image(target.r_LP_P, target.id)
self.enable_target_window(target)
11 changes: 9 additions & 2 deletions src/bsk_rl/sats/satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import numpy as np
from Basilisk.utilities import macros
from deprecated import deprecated
from gymnasium import spaces

from bsk_rl.act.actions import select_action_builder
Expand Down Expand Up @@ -273,19 +274,25 @@ def _info_command(self, info: str) -> str:
Returns:
actionList action for simBase.createNewEvent
"""
return self._satellite_command + f".log_info('{info}')"
return self._satellite_command + f".logger.info('{info}')"

@deprecated(reason="Use satellite.logger.info instead")
def log_info(self, info: Any) -> None:
"""Record information at the current simulation time.
:meta private:
Args:
info: Information to log
"""
self.logger.info(f"{info}")

@deprecated(reason="Use satellite.logger.warning instead")
def log_warning(self, warning: Any) -> None:
"""Record warning at the current simulation time.
:meta private:
Args:
warning: Warning to log
"""
Expand All @@ -302,7 +309,7 @@ def update_timed_terminal_event(
extra_actions: Additional actions to perform at terminal time
"""
self.disable_timed_terminal_event()
self.log_info(f"setting timed terminal event at {t_close:.1f}")
self.logger.info(f"setting timed terminal event at {t_close:.1f}")

# Create new timed terminal event
self._timed_terminal_event_name = valid_func_name(
Expand Down
2 changes: 1 addition & 1 deletion src/bsk_rl/utils/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def inner(*args, log_failure=False, **kwargs) -> bool:
self = args[0]
alive = func(*args, **kwargs)
if not alive and log_failure:
self.satellite.log_warning(f"failed {func.__name__} check")
self.satellite.logger.warning(f"failed {func.__name__} check")
return alive

inner.__doc__ = (
Expand Down
4 changes: 2 additions & 2 deletions tests/unittest/sats/test_access_satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,11 @@ def test_task_target_for_imaging(self):
sat.simulator = MagicMock(sim_time=35.0)
sat._update_image_event = MagicMock()
sat.update_timed_terminal_event = MagicMock()
sat.log_info = MagicMock()
sat.logger = MagicMock()
sat.task_target_for_imaging(self.tgt0)
sat.fsw.action_image.assert_called_once()
assert sat.fsw.action_image.call_args[0][1].startswith("tgt_0")
sat.log_info.assert_called()
sat.logger.info.assert_called()
sat._update_image_event.assert_called_once()
assert sat._update_image_event.call_args[0][0] == self.tgt0
sat.update_timed_terminal_event.assert_called_once()
Expand Down
16 changes: 0 additions & 16 deletions tests/unittest/sats/test_satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,6 @@ def test_satellite_command(self):
assert sat1 != eval(sat2._satellite_command)
assert sat2 == eval(sat2._satellite_command)

def test_info_command(self):
sat = sats.Satellite(name="TestSat", sat_args={})
sat.info = []
sat.simulator = MagicMock(sim_time=0.0)
self.satellites = [sat]
self.sim_time = 0.0
eval(sat._info_command("some info"))
assert sat.info[0] == (0.0, "some info")

def test_log_info(self):
sat = sats.Satellite(name="TestSat", sat_args={})
sat.info = []
sat.simulator = MagicMock(sim_time=0.0)
sat.log_info("some info")
assert sat.info[0] == (0.0, "some info")

def test_update_timed_terminal_event(self):
pass # Probably better with integration testing

Expand Down
2 changes: 1 addition & 1 deletion tests/unittest/utils/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_dead(self, type):
d.satellite.id = "SAT"
d.satellite._is_alive
assert functional.check_aliveness_checkers(d, log_failure=True) is False
d.satellite.log_warning.assert_called_with("failed is_living check")
d.satellite.logger.warning.assert_called_with("failed is_living check")


@pytest.mark.parametrize("prop_name,expected", [("prop", True), ("not_a_prop", False)])
Expand Down

0 comments on commit e4dcaec

Please sign in to comment.