-
Notifications
You must be signed in to change notification settings - Fork 3
/
experiment.py
77 lines (54 loc) · 2.27 KB
/
experiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
A dummy experiment specifications class.
"""
import json
import yaml
from aiida.orm import Dict
from aiida_aurora.schemas.cycling import ElectroChemSequence as ElectroChemSequenceSchema
class CyclingSpecsData(Dict): # pylint: disable=too-many-ancestors
"""
An experiment specification object.
This class represents the specifications used in an experiment.
"""
# "pydantic" schema to add automatic validation
schema = ElectroChemSequenceSchema
# pylint: disable=redefined-builtin
def __init__(self, dict=None, **kwargs):
"""
Constructor for the data class
Usage: ``DummyExperimentSpecs(dict{...})``
:param parameters_dict: dictionary with battery specifications
:param type parameters_dict: dict
"""
dict = self.validate(dict)
super().__init__(dict=dict, **kwargs)
# if not self.label:
# self.label = self.dict['metadata'].get('name')
def validate(self, parameters_dict): # pylint: disable=no-self-use
"""Validate command line options.
Uses the voluptuous package for validation. Find out about allowed keys using::
print(DummyExperimentSpecs.schema)
:param parameters_dict: dictionary with battery specifications
:param type parameters_dict: dict
:returns: validated dictionary
"""
return ElectroChemSequenceSchema(**parameters_dict).dict()
def get_json(self):
"""Get a JSON file containing the DummyExperimentSpecs specs."""
# this can be customized to fit the desired format
object_to_be_serialized = self.get_dict()
return json.dumps(object_to_be_serialized)
def get_yaml(self):
"""Get a YAML file containing the BatterySampleData specs."""
# this can be customized to fit the desired format
object_to_be_serialized = {"method": self.get_dict()}
return yaml.dump(object_to_be_serialized)
def __str__(self):
"""String representation of node.
Append values of dictionary to usual representation. E.g.::
uuid: b416cbee-24e8-47a8-8c11-6d668770158b (pk: 590)
{'ignore-case': True}
"""
string = super().__str__()
string += "\n" + str(self.get_dict())
return string