Skip to content

Commit

Permalink
Support multiple results in NeptuneObserver completed_event() (#68)
Browse files Browse the repository at this point in the history
* Support multiple results in NeptuneObservercompleted_event

* added logging of results objects
  • Loading branch information
david1309 authored and jakubczakon committed Nov 18, 2019
1 parent f37d1e0 commit f5f78b8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion neptunecontrib/monitoring/sacred.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#

import collections
import warnings

import neptune
from neptunecontrib.monitoring.utils import pickle_and_send_artifact
from sacred.dependencies import get_digest
from sacred.observers import RunObserver

Expand Down Expand Up @@ -100,7 +102,19 @@ def started_event(self, ex_info, command, host_info, start_time, config, meta_in

def completed_event(self, stop_time, result):
if result:
neptune.log_metric('result', result)
if not isinstance(result, tuple):
result = (
result,) # transform single result to tuple so that both single & multiple results use same code

for i, r in enumerate(result):
if isinstance(r, float) or isinstance(r, int):
neptune.log_metric("result_{}".format(i), float(r))
elif isinstance(r, object):
pickle_and_send_artifact(r, "result_{}.pkl".format(i))
else:
warnings.warn(
"logging results does not support type '{}' results. Ignoring this result".format(type(r)))

neptune.stop()

def interrupted_event(self, interrupt_time, status):
Expand Down

0 comments on commit f5f78b8

Please sign in to comment.