diff --git a/freqtrade/optimize/hyperopt_tools.py b/freqtrade/optimize/hyperopt_tools.py index 8d6098257..665c393b3 100644 --- a/freqtrade/optimize/hyperopt_tools.py +++ b/freqtrade/optimize/hyperopt_tools.py @@ -31,15 +31,27 @@ class HyperoptTools(): else: return any(s in config['spaces'] for s in [space, 'all', 'default']) + @staticmethod + def _read_results_pickle(results_file: Path) -> List: + """ + Read hyperopt results from pickle file + LEGACY method - new files are written as json and cannot be read with this method. + """ + from joblib import load + + logger.info(f"Reading pickled epochs from '{results_file}'") + data = load(results_file) + return data + @staticmethod def _read_results(results_file: Path) -> List: """ Read hyperopt results from file """ - from joblib import load - - logger.info("Reading epochs from '%s'", results_file) - data = load(results_file) + import rapidjson + logger.info(f"Reading epochs from '{results_file}'") + with results_file.open('r') as f: + data = [rapidjson.loads(line) for line in f] return data @staticmethod @@ -49,7 +61,10 @@ class HyperoptTools(): """ epochs: List = [] if results_file.is_file() and results_file.stat().st_size > 0: - epochs = HyperoptTools._read_results(results_file) + if results_file.suffix == '.pickle': + epochs = HyperoptTools._read_results_pickle(results_file) + else: + epochs = HyperoptTools._read_results(results_file) # Detection of some old format, without 'is_best' field saved if epochs[0].get('is_best') is None: raise OperationalException(