Source code for ax.storage.json_store.save
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import json
from ax.core.experiment import Experiment
from ax.storage.json_store.encoder import object_to_json
[docs]def save_experiment(experiment: Experiment, filepath: str) -> None:
"""Save experiment to file.
1) Convert Ax experiment to JSON-serializable dictionary.
2) Write to file.
"""
if not isinstance(experiment, Experiment):
raise ValueError("Can only save instances of Experiment")
if not filepath.endswith(".json"):
raise ValueError("Filepath must end in .json")
json_experiment = object_to_json(experiment)
with open(filepath, "w+") as file:
file.write(json.dumps(json_experiment))