Skip to content

Commit

Permalink
Fix: key collisions for input/outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
gpauloski committed Apr 2, 2021
1 parent 414a303 commit 39fbabd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions colmena/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import colmena
import json
import logging
import random
import pickle as pkl
import sys
from datetime import datetime
Expand Down Expand Up @@ -167,9 +168,12 @@ def serialize(self) -> float:
_value = self.value
_inputs = self.inputs

def _serialize_and_proxy(value):
def _serialize_and_proxy(value, key=None):
"""Helper function for serializing and proxying"""
key = str(id(value))
if key is None:
# TODO(gpauloski): We assume all input/outputs are unique.
# We should rethink if we want to keep this.
key = str(random.getrandbits(128))
# Serialized object before proxying to compare size of serialized
# object to value server threshold
value = SerializationMethod.serialize(self.serialization_method, value)
Expand All @@ -195,7 +199,10 @@ def _serialize_and_proxy(value):
kwargs = {k: _serialize_and_proxy(v) for k, v in _inputs[1].items()}
self.inputs = (args, kwargs)

# The entire result is serialized as one object
# The entire result is serialized as one object.
# We generate a random key for the result to avoid key collisions
# in Redis. I.e. the result of a function is always considered
# unique
if _value is not None:
self.value = _serialize_and_proxy(_value)

Expand Down

0 comments on commit 39fbabd

Please sign in to comment.