Skip to content

Commit 192b01a

Browse files
Store sets as lists in YAML file
1 parent 53f6fb5 commit 192b01a

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

surface_sim/detectors/detectors.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,19 @@ def store_state(self, filename: str | pathlib.Path) -> None:
122122
"""Stores the current state to the given YAML file.
123123
This is useful in a conditioned circuit to not encode the first part
124124
of the circuit for every realization."""
125+
# convert sets to lists for easier storage in YAML file
125126
state = {
126-
"anc_qubit_labels": deepcopy(self.anc_qubit_labels),
127+
"anc_qubit_labels": deepcopy(list(self.anc_qubit_labels)),
127128
"frame": deepcopy(self.frame),
128-
"anc_coords": deepcopy(self.anc_coords),
129+
"anc_coords": deepcopy({k: list(v) for k, v in self.anc_coords.items()}),
129130
"include_gauge_dets": deepcopy(self.include_gauge_dets),
130-
"detectors": deepcopy(self.detectors),
131+
"detectors": deepcopy({k: list(v) for k, v in self.detectors.items()}),
131132
"num_rounds": deepcopy(self.num_rounds),
132133
"total_num_rounds": deepcopy(self.total_num_rounds),
133-
"update_dict_list": deepcopy(self.update_dict_list),
134-
"gauge_detectors": deepcopy(self.gauge_detectors),
134+
"update_dict_list": deepcopy(
135+
[{k: list(v) for k, v in d.items()} for d in self.update_dict_list]
136+
),
137+
"gauge_detectors": deepcopy(list(self.gauge_detectors)),
135138
}
136139
with open(filename, "w") as file:
137140
yaml.dump(state, file)
@@ -149,11 +152,13 @@ def load_state(cls, filename: str | pathlib.Path) -> "Detectors":
149152
anc_coords=state["anc_coords"],
150153
include_gauge_dets=state["include_gauge_dets"],
151154
)
152-
detectors.detectors = state["detectors"]
155+
detectors.detectors = {k: set(v) for k, v in state["detectors"].items()}
153156
detectors.num_rounds = state["num_rounds"]
154157
detectors.total_num_rounds = state["total_num_rounds"]
155-
detectors.update_dict_list = state["update_dict_list"]
156-
detectors.gauge_detectors = state["gauge_detectors"]
158+
detectors.update_dict_list = [
159+
{k: set(v) for k, v in d.items()} for d in state["update_dict_list"]
160+
]
161+
detectors.gauge_detectors = set(state["gauge_detectors"])
157162
return detectors
158163

159164
def activate_detectors(

0 commit comments

Comments
 (0)