Ejemplo n.º 1
0
def load(params: Any, base_dir: str) -> Any:
    """Load an object from a JSON file.

    Arguments:
        params: Parameters describing the object. This should have an `filename`
            attribute containing the filename of the saved object.
        base_dir: The directory from which to load the object.

    Returns: The loaded object.
    """
    filename = os.path.join(base_dir, params.filename)
    return protocols.read_json(filename)
Ejemplo n.º 2
0
def read_json(file_or_fn=None, *, json_text=None, resolvers=None):
    """Read a JSON file that optionally contains cirq objects.

    This differs from cirq.read_json by its default argument for
    `resolvers`. Use this function if your JSON document contains
    recirq objects.
    """
    if resolvers is None:
        resolvers = DEFAULT_RESOLVERS

    return protocols.read_json(file_or_fn=file_or_fn,
                               json_text=json_text,
                               resolvers=resolvers)