# -*- coding: utf-8 -*-
:mod:`orion.client` -- Helper function for returning results from script
.. module:: client
:synopsis: Provides functions for communicating with `orion.core`.
IS_ORION_ON = False
_HAS_REPORTED_RESULTS = False
RESULTS_FILENAME = os.getenv('ORION_RESULTS_PATH', None)
if RESULTS_FILENAME and os.path.isfile(RESULTS_FILENAME):
IS_ORION_ON = True
if RESULTS_FILENAME and not IS_ORION_ON:
raise RuntimeWarning("Results file path provided in environmental variable "
"does not correspond to an existing file.")
"""Facilitate the reporting of results for a user's script acting as a
:param data: A dictionary containing experimental results
.. note:: To be called only once in order to report a final evaluation
of a particular trial.
.. note:: In case that user's script is not running in a orion's context,
this function will act as a Python `print` function.
.. note:: For your own good, this can be called **only once**.
global _HAS_REPORTED_RESULTS # pylint:disable=global-statement
raise RuntimeWarning("Has already reported evaluation results once.")
with open(RESULTS_FILENAME, 'w') as results_file:
_HAS_REPORTED_RESULTS = True