Skip to content

Commit

Permalink
#115 - Complete final testing details of multi-worker log loading
Browse files Browse the repository at this point in the history
  • Loading branch information
dmh23 committed Feb 25, 2023
1 parent d163a1d commit ce6b3c0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/log/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def load_all(self, meta_file_names: Union[str, list], please_wait: PleaseWait, t
self._episodes += episodes_by_iteration[i]
for new_id, e in enumerate(self._episodes):
e.id = new_id
for v in e.events:
v.episode = new_id
for e in multi_evaluation_phases:
if len(e) > 0:
assert(len(self._evaluation_phases)) == 0
Expand Down
4 changes: 0 additions & 4 deletions src/log/log_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ def set_from_json(self, received_json: dict) -> None:

def merge_from_multi_logs(self, multi_log_meta: list[Self]):
assert len(multi_log_meta) >= 2
# self._fields = multi_log_meta[0]._fields # Fudge to test the testing framework!!
# self.action_space = multi_log_meta[0].action_space
# self.fixed_object_locations = multi_log_meta[0].fixed_object_locations
# TODO - Finish this for ALL the meta data

# Some fields are different per log, so need to be arbitrarily set to the value in the FIRST merged log
self.worker_id.set(multi_log_meta[0].worker_id.get())
Expand Down
44 changes: 35 additions & 9 deletions tests/system_tests/tests/test_file_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ def test_load_single_short_log_file(self):
expected_step_counts = [139, 141, 142, 87, 156, 132, 138, 144, 143, 137, 133, 144, 147, 141, 133, 141, 140,
142, 131, 138]
expected_quarters = [1] * 5 + [2] * 5 + [3] * 5 + [4] * 5
log = self._test_load_episodes("training-20220721141556-OUjJCTWHR7SeYQs_-7xc4A-robomaker.log",
Reinvent2018Track,
expected_step_counts, expected_quarters)

first_episode: Episode = log.get_episodes()[0]
# print(first_episode.quarter)
self._test_load_episodes("training-20220721141556-OUjJCTWHR7SeYQs_-7xc4A-robomaker.log",
Reinvent2018Track,
expected_step_counts, expected_quarters)

def test_load_two_worker_log_files(self):
expected_step_counts = [25, 24, 25, 27, 15, 35, 22, 20, 22, 25,
Expand All @@ -59,8 +56,6 @@ def test_load_two_worker_log_files(self):

self._verify_log_meta_json(log, "test_load_two_worker_log_files.json")

# TODO - lots more checks on "log" and its contents

def test_load_four_worker_log_files(self):
expected_step_counts = [165, 183, 391, 73, 366, 26, 50, 364, 195, 240,
95, 76, 386, 78, 362, 277, 51, 332, 272, 361,
Expand All @@ -81,7 +76,38 @@ def test_load_four_worker_log_files(self):

self._verify_log_meta_json(log, "test_load_four_worker_log_files.json")

# TODO - lots more checks on "log" and its contents
# Should be the 11th step of the 3rd episode in 2nd worker
# SIM_TRACE_LOG:2,11,-7.9529,-0.2597,27.0350,-30.00,1.00,4,25.0000,False,True,1.1486,75,52.87,39.632,in_progress,0.00
# 75 : 62 45
# B - Bonus fast section
sample_episode = log.get_episodes()[12]
sample_event = sample_episode.events[10]
self.assertEqual(12, sample_episode.id)
self.assertEqual(12, sample_event.episode)
self.assertEqual(11, sample_event.step)
self.assertEqual("\n75 : 62 45\nB - Bonus fast section\n", sample_event.debug_log)
self.assertEqual(39.632, sample_event.time)
self.assertEqual(3, sample_event.sequence_count)
self.assertEqual("R", sample_event.track_side)
self.assertEqual(3.7, round(sample_event.projected_travel_distance, 1))
self.assertTrue(sample_event.all_wheels_on_track)
self.assertEqual(1.0, round(sample_event.track_speed, 1))

# Last step in the last episode of the last worker
# SIM_TRACE_LOG:19,158,-0.3655,2.3368,-40.3193,-5.00,4.00,2,0.1000,True,False,49.6239,140,52.87,557.678,off_track,0.00
# ERROR - Going directly off track
sample_episode = log.get_episodes()[-1]
sample_event = sample_episode.events[-1]
self.assertEqual(73, sample_episode.id)
self.assertEqual(73, sample_event.episode)
self.assertEqual(158, sample_event.step)
self.assertEqual("\nERROR - Going directly off track\n", sample_event.debug_log)
self.assertEqual(557.678, sample_event.time)
self.assertEqual(5, sample_event.sequence_count)
self.assertEqual("L", sample_event.track_side)
self.assertEqual(0.0, round(sample_event.projected_travel_distance, 1))
self.assertFalse(sample_event.all_wheels_on_track)
self.assertEqual(2.4, round(sample_event.track_speed, 1))

def _test_load_episodes(self, filenames: Union[str, list], track_type: type, expected_step_counts: list,
expected_quarters: list) -> Log:
Expand Down

0 comments on commit ce6b3c0

Please sign in to comment.