2
0
mirror of https://github.com/m-labs/artiq.git synced 2025-01-31 04:40:20 +08:00

experiments: implement LRU-based management for state cleanup

Signed-off-by: Florian Agbuya <fa@m-labs.ph>
This commit is contained in:
Florian Agbuya 2024-10-22 15:48:46 +08:00 committed by Sébastien Bourdeauducq
parent 7619dff08d
commit c1f2ff3717

View File

@ -511,6 +511,24 @@ class _QuickOpenDialog(QtWidgets.QDialog):
self.close() self.close()
class _LRUDict(OrderedDict):
def __init__(self, size_limit=1000):
super().__init__()
self.size_limit = size_limit
def __setitem__(self, key, value):
if key in self:
self.pop(key)
super().__setitem__(key, value)
if len(self) > self.size_limit:
self.popitem(last=False)
def __getitem__(self, key):
value = super().__getitem__(key)
self.move_to_end(key)
return value
class ExperimentManager: class ExperimentManager:
#: Global registry for custom argument editor classes, indexed by the experiment #: Global registry for custom argument editor classes, indexed by the experiment
#: `argument_ui` string; can be populated by dashboard plugins such as ndscan. #: `argument_ui` string; can be populated by dashboard plugins such as ndscan.
@ -525,12 +543,12 @@ class ExperimentManager:
self.schedule_ctl = schedule_ctl self.schedule_ctl = schedule_ctl
self.experiment_db_ctl = experiment_db_ctl self.experiment_db_ctl = experiment_db_ctl
self.dock_states = dict() self.dock_states = _LRUDict()
self.submission_scheduling = dict() self.submission_scheduling = _LRUDict()
self.submission_options = dict() self.submission_options = _LRUDict()
self.submission_arguments = dict() self.submission_arguments = _LRUDict()
self.argument_ui_names = dict() self.argument_ui_names = _LRUDict()
self.colors = dict() self.colors = _LRUDict()
self.datasets = dict() self.datasets = dict()
dataset_sub.add_setmodel_callback(self.set_dataset_model) dataset_sub.add_setmodel_callback(self.set_dataset_model)
@ -790,24 +808,24 @@ class ExperimentManager:
for expurl, dock in self.open_experiments.items(): for expurl, dock in self.open_experiments.items():
self.dock_states[expurl] = dock.save_state() self.dock_states[expurl] = dock.save_state()
return { return {
"scheduling": self.submission_scheduling, "scheduling": dict(self.submission_scheduling),
"options": self.submission_options, "options": dict(self.submission_options),
"arguments": self.submission_arguments, "arguments": dict(self.submission_arguments),
"docks": self.dock_states, "docks": dict(self.dock_states),
"argument_uis": self.argument_ui_names, "argument_uis": dict(self.argument_ui_names),
"open_docks": set(self.open_experiments.keys()), "open_docks": set(self.open_experiments.keys()),
"colors": self.colors "colors": dict(self.colors)
} }
def restore_state(self, state): def restore_state(self, state):
if self.open_experiments: if self.open_experiments:
raise NotImplementedError raise NotImplementedError
self.dock_states = state["docks"] self.dock_states.update(state["docks"])
self.submission_scheduling = state["scheduling"] self.submission_scheduling.update(state["scheduling"])
self.submission_options = state["options"] self.submission_options.update(state["options"])
self.submission_arguments = state["arguments"] self.submission_arguments.update(state["arguments"])
self.argument_ui_names = state.get("argument_uis", {}) self.argument_ui_names.update(state.get("argument_uis", {}))
self.colors = state.get("colors", {}) self.colors.update(state.get("colors", {}))
for expurl in state["open_docks"]: for expurl in state["open_docks"]:
self.open_experiment(expurl) self.open_experiment(expurl)