forked from M-Labs/artiq
1
0
Fork 0

language/environment: support non-stored results

This commit is contained in:
Sebastien Bourdeauducq 2015-08-06 18:43:27 +08:00
parent 59a29ae04b
commit 9261254653
2 changed files with 16 additions and 3 deletions

View File

@ -201,13 +201,15 @@ class HasEnvironment:
raise ValueError("Parameter database not present")
self.__pdb.set(key, value)
def set_result(self, key, value, realtime=False):
def set_result(self, key, value, realtime=False, store=True):
"""Writes the value of a result.
:param realtime: Marks the result as real-time, making it immediately
available to clients such as the user interface. Returns a
``Notifier`` instance that can be used to modify mutable results
(such as lists) and synchronize the modifications with the clients.
:param store: Defines if the result should be stored permanently,
e.g. in HDF5 output. Default is to store.
"""
if self.__rdb is None:
raise ValueError("Result database not present")
@ -217,11 +219,13 @@ class HasEnvironment:
self.__rdb.rt[key] = value
notifier = self.__rdb.rt[key]
notifier.kernel_attr_init = False
self.__rdb.set_store(key, store)
return notifier
else:
if key in self.__rdb.rt.read:
raise ValueError("Result is already realtime")
self.__rdb.nrt[key] = value
self.__rdb.set_store(key, store)
def get_result(self, key):
"""Retrieves the value of a result.

View File

@ -91,6 +91,7 @@ class ResultDB:
def __init__(self):
self.rt = Notifier(dict())
self.nrt = dict()
self.store = set()
def get(self, key):
try:
@ -98,9 +99,17 @@ class ResultDB:
except KeyError:
return self.rt[key].read
def set_store(self, key, store):
if store:
self.store.add(key)
else:
self.store.discard(key)
def write_hdf5(self, f):
result_dict_to_hdf5(f, self.rt.read)
result_dict_to_hdf5(f, self.nrt)
result_dict_to_hdf5(
f, {k: v for k, v in self.rt.read.items() if k in self.store})
result_dict_to_hdf5(
f, {k: v for k, v in self.nrt.items() if k in self.store})
def _create_device(desc, dmgr):