def load(filename): """ Load an experiment from disk. Parameters ---------- filename : str Path to a file generated by |Experiment.save|. Returns ------- |Experiment| """ with open(filename, 'r') as f: self = yaml.load(f) self.filename = filename return self
def from_yaml_file(cls, filename): """ Construct an |Experiment| based on specification in a YAML file. Requires `PyYAML`_. Parameters ---------- filename : str YAML file location. The YAML should specify a dictionary matching the specification of |Experiment.from_dict|. Returns ------- |Experiment| """ if not yaml: raise ImportError('PyYAML is not installed') with open(filename, 'r') as f: spec = yaml.load(f) return cls.from_dict(spec)
def test_round_trip(data): cmp = yaml.load(yaml.dump(data)) == data if isinstance(cmp, np.ndarray): assert np.all(cmp) else: assert cmp