Skip to content

Commit

Permalink
Merge pull request #295 from NextCenturyCorporation/revert-285-serial…
Browse files Browse the repository at this point in the history
…ization_fix

Revert "Serialization Fix"
  • Loading branch information
deanwetherby authored Apr 6, 2021
2 parents 3d4a12e + 3f399be commit f3ba67e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
13 changes: 5 additions & 8 deletions machine_common_sense/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _ext_pack(x):
msgpack.packb([
x.uuid, x.color, x.dimensions, x.direction, x.distance,
x.distance_in_steps, x.distance_in_world, x.held, x.mass,
x.material_list, x.position, x.rotation, x.shape, x.state_list, x.texture_color_list, x.visible
x.material_list, x.position, x.rotation, x.visible
],
default=SerializerMsgPack._ext_pack,
strict_types=True))
Expand Down Expand Up @@ -158,11 +158,11 @@ def _ext_unpack(code, data):
elif code == 5:
uuid, color, dimensions, direction, distance, distance_in_steps, \
distance_in_world, held, mass, material_list, position, \
rotation, shape, state_list, texture_color_list, visible = msgpack.unpackb(
rotation, visible = msgpack.unpackb(
data, ext_hook=SerializerMsgPack._ext_unpack)
return ObjectMetadata(uuid, color, dimensions, direction, distance,
distance_in_steps, distance_in_world, held,
mass, material_list, position, rotation, shape, state_list, texture_color_list,
mass, material_list, position, rotation,
visible)
elif code == 6:
x = msgpack.unpackb(data, ext_hook=SerializerMsgPack._ext_unpack)
Expand Down Expand Up @@ -260,9 +260,6 @@ def default(self, x):
'material_list': x.material_list,
'position': x.position,
'rotation': x.rotation,
'shape': x.shape,
'state_list': x.state_list,
'texture_color_list': x.texture_color_list,
'visible': x.visible
}
elif isinstance(x, np.ndarray):
Expand All @@ -282,8 +279,8 @@ def convert_object_list(raw_list):
object_raw['distance'], object_raw['distance_in_steps'],
object_raw['distance_in_world'], object_raw['held'],
object_raw['mass'], object_raw['material_list'],
object_raw['position'], object_raw['rotation'], object_raw['shape'], object_raw['state_list'],
object_raw['texture_color_list'], object_raw['visible'])
object_raw['position'], object_raw['rotation'],
object_raw['visible'])
object_list.append(obj)
return object_list

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Jinja2==2.11.3
MarkupSafe==1.1.1
matplotlib==3.3.2
msgpack==1.0.0
numpy==1.19.4
opencv-python==4.4.0.44
packaging==20.4
pre-commit==2.7.1
Expand Down
Binary file modified tests/test.msgpack
Binary file not shown.
12 changes: 4 additions & 8 deletions tests/test_serializer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import unittest

import numpy as np
Expand All @@ -18,24 +17,21 @@ def _helper_get_step_metadata():

def test_serialization_msgpack(self):
unpacked_metadata = TestSerializer._helper_get_step_metadata()
assert abs(unpacked_metadata.reward - (-0.036000000000000004)) < 1e-04, 'Reward unexpected.'
assert abs(unpacked_metadata.rotation - 0.0) < 1e-04, 'Rotation unexpected.'
assert type(unpacked_metadata.object_list[-1].shape) == str, 'Shape type unexpected.'
assert unpacked_metadata.reward == 0.0, 'Reward unexpected.'
assert unpacked_metadata.rotation == 0.0, 'Rotation unexpected.'

def test_serialization_json(self):
unpacked_metadata = TestSerializer._helper_get_step_metadata()

serializer = mcs.SerializerJson()
json_dump = serializer.serialize(unpacked_metadata)
unpacked_metadata = serializer.deserialize(json_dump)

self.assertEqual(len(unpacked_metadata.depth_map_list), 1)
self.assertIsInstance(unpacked_metadata.depth_map_list[0], np.ndarray)
self.assertEqual(unpacked_metadata.depth_map_list[0].shape, (400, 600))
self.assertIsInstance(unpacked_metadata, mcs.StepMetadata)
self.assertAlmostEqual(unpacked_metadata.reward, -0.036000000000000004)
self.assertAlmostEqual(unpacked_metadata.rotation, 0.0, delta=1e-04)
self.assertIsInstance(unpacked_metadata.object_list[-1].shape, str)
self.assertEqual(unpacked_metadata.reward, 0.0)
self.assertEqual(unpacked_metadata.rotation, 0.0)


if __name__ == '__main__':
Expand Down

0 comments on commit f3ba67e

Please sign in to comment.