Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tune] Add custom field for serializations #4237

Merged
merged 6 commits into from
Mar 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions python/ray/tune/trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,24 @@ def __init__(self,
self.error_file = None
self.num_failures = 0

# AutoML fields
self.results = None
self.best_result = None
self.param_config = None
self.extra_arg = None

self._nonjson_fields = [
"_checkpoint",
"config",
"loggers",
"sync_function",
"last_result",
"results",
"best_result",
"param_config",
"extra_arg",
]

self.trial_name = None
if trial_name_creator:
self.trial_name = trial_name_creator(self)
Expand Down Expand Up @@ -509,17 +527,8 @@ def __getstate__(self):
state = self.__dict__.copy()
state["resources"] = resources_to_json(self.resources)

# These are non-pickleable entries.
pickle_data = {
"_checkpoint": self._checkpoint,
"config": self.config,
"loggers": self.loggers,
"sync_function": self.sync_function,
"last_result": self.last_result
}

for key, value in pickle_data.items():
state[key] = binary_to_hex(cloudpickle.dumps(value))
for key in self._nonjson_fields:
state[key] = binary_to_hex(cloudpickle.dumps(state.get(key)))

state["runner"] = None
state["result_logger"] = None
Expand All @@ -535,10 +544,7 @@ def __getstate__(self):
def __setstate__(self, state):
logger_started = state.pop("__logger_started__")
state["resources"] = json_to_resources(state["resources"])
for key in [
"_checkpoint", "config", "loggers", "sync_function",
"last_result"
]:
for key in self._nonjson_fields:
state[key] = cloudpickle.loads(hex_to_binary(state[key]))

self.__dict__.update(state)
Expand Down