Skip to content

Commit

Permalink
Merge pull request #76 from trustimaging/reduce-iteration
Browse files Browse the repository at this point in the history
Reduce size of serialised iteration object
  • Loading branch information
ccuetom authored Dec 20, 2023
2 parents fc6fb11 + 53aabae commit eee6c7b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 0 additions & 1 deletion mosaic/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def sizeof(obj, seen=None):
size += sum([sizeof(k, seen) for k in obj.keys()])
elif hasattr(obj, '__dict__'):
size += sizeof(obj.__dict__, seen)

elif hasattr(obj, '__iter__') and not isinstance(obj, (str, bytes, bytearray)):
try:
size += sum([sizeof(i, seen) for i in obj])
Expand Down
23 changes: 23 additions & 0 deletions stride/optimisation/optimisation_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,29 @@ def __set_desc__(self, description):
fun = FunctionalValue(fun_desc.fun_value, fun_desc.shot_id)
self._fun[fun.shot_id] = fun

_serialisation_attrs = ['id', 'abs_id', '_submitted_shots', '_completed_shots', '_fun']

def _serialisation_helper(self):
state = {}

for attr in self._serialisation_attrs:
state[attr] = getattr(self, attr)

return state

@classmethod
def _deserialisation_helper(cls, state):
instance = cls.__new__(cls)

for attr, value in state.items():
setattr(instance, attr, value)

return instance

def __reduce__(self):
state = self._serialisation_helper()
return self._deserialisation_helper, (state,)


class Block:
"""
Expand Down

0 comments on commit eee6c7b

Please sign in to comment.