Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6c24e699fd95
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c0bdc92b18af
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 14, 2015

  1. Copy the full SHA
    4160d24 View commit details
  2. Copy the full SHA
    ebdd92c View commit details
  3. Copy the full SHA
    c0bdc92 View commit details
Showing with 77 additions and 48 deletions.
  1. +24 −0 artiq/management/rt_results.py
  2. +45 −35 artiq/management/sync_struct.py
  3. +2 −2 artiq/management/worker_impl.py
  4. +6 −11 frontend/artiq_master.py
24 changes: 24 additions & 0 deletions artiq/management/rt_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from artiq.management.sync_struct import Notifier, process_mod


class RTResults:
def __init__(self):
self.sets = Notifier(dict())
self.current_set = "default"

def init(self, description):
data = dict()
for rtr in description.keys():
if isinstance(rtr, tuple):
for e in rtr:
data[e] = []
else:
data[rtr] = []
self.sets[self.current_set] = {
"description": description,
"data": data
}

def update(self, mod):
target = self.sets[self.current_set]["data"]
process_mod(target, mod)
80 changes: 45 additions & 35 deletions artiq/management/sync_struct.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,24 @@
_init_string = b"ARTIQ sync_struct\n"


def process_mod(target, mod):
for key in mod["path"]:
target = getitem(target, key)
action = mod["action"]
if action == "append":
target.append(mod["x"])
elif action == "insert":
target.insert(mod["i"], mod["x"])
elif action == "pop":
target.pop(mod["i"])
elif action == "setitem":
target.__setitem__(mod["key"], mod["value"])
elif action == "delitem":
target.__delitem__(mod["key"])
else:
raise ValueError


class Subscriber:
def __init__(self, notifier_name, target_builder, notify_cb=None):
self.notifier_name = notifier_name
@@ -49,32 +67,24 @@ def _receive_cr(self):
if not line:
return
obj = pyon.decode(line.decode())
action = obj["action"]

if action == "init":
if obj["action"] == "init":
target = self.target_builder(obj["struct"])
else:
for key in obj["path"]:
target = getitem(target, key)
if action == "append":
target.append(obj["x"])
elif action == "insert":
target.insert(obj["i"], obj["x"])
elif action == "pop":
target.pop(obj["i"])
elif action == "setitem":
target.__setitem__(obj["key"], obj["value"])
elif action == "delitem":
target.__delitem__(obj["key"])
process_mod(target, obj)

if self.notify_cb is not None:
self.notify_cb()


class Notifier:
def __init__(self, backing_struct, publish=None, path=[]):
def __init__(self, backing_struct, root=None, path=[]):
self.read = backing_struct
self.publish = publish
if root is None:
self.root = self
self.publish = None
else:
self.root = root
self._backing_struct = backing_struct
self._path = path

@@ -83,44 +93,44 @@ def __init__(self, backing_struct, publish=None, path=[]):

def append(self, x):
self._backing_struct.append(x)
if self.publish is not None:
self.publish(self, {"action": "append",
"path": self._path,
"x": x})
if self.root.publish is not None:
self.root.publish(self.root, {"action": "append",
"path": self._path,
"x": x})

def insert(self, i, x):
self._backing_struct.insert(i, x)
if self.publish is not None:
self.publish(self, {"action": "insert",
"path": self._path,
"i": i, "x": x})
if self.root.publish is not None:
self.root.publish(self.root, {"action": "insert",
"path": self._path,
"i": i, "x": x})

def pop(self, i=-1):
r = self._backing_struct.pop(i)
if self.publish is not None:
self.publish(self, {"action": "pop",
"path": self._path,
"i": i})
if self.root.publish is not None:
self.root.publish(self.root, {"action": "pop",
"path": self._path,
"i": i})
return r

def __setitem__(self, key, value):
self._backing_struct.__setitem__(key, value)
if self.publish is not None:
self.publish(self, {"action": "setitem",
if self.root.publish is not None:
self.root.publish(self.root, {"action": "setitem",
"path": self._path,
"key": key,
"value": value})

def __delitem__(self, key):
self._backing_struct.__delitem__(key)
if self.publish is not None:
self.publish(self, {"action": "delitem",
"path": self._path,
"key": key})
if self.root.publish is not None:
self.root.publish(self.root, {"action": "delitem",
"path": self._path,
"key": key})

def __getitem__(self, key):
item = getitem(self._backing_struct, key)
return Notifier(item, self.publish, self._path + [key])
return Notifier(item, self.root, self._path + [key])


class Publisher(AsyncioServer):
4 changes: 2 additions & 2 deletions artiq/management/worker_impl.py
Original file line number Diff line number Diff line change
@@ -48,8 +48,8 @@ class ParentPDB:
set = make_parent_action("set_parameter", "name value")


init_rt_results = make_parent_action("init_rt_results", "data")
update_rt_results = make_parent_action("update_rt_results", "data")
init_rt_results = make_parent_action("init_rt_results", "description")
update_rt_results = make_parent_action("update_rt_results", "mod")


def publish_rt_results(notifier, data):
17 changes: 6 additions & 11 deletions frontend/artiq_master.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
from artiq.management.sync_struct import Publisher
from artiq.management.db import FlatFileDB, SimpleHistory
from artiq.management.scheduler import Scheduler
from artiq.management.rt_results import RTResults


def _get_args():
@@ -24,21 +25,14 @@ def _get_args():
return parser.parse_args()


def init_rt_results(data):
print("init realtime results: " + str(data))


def update_rt_results(data):
print("update realtime results: " + str(data))


def main():
args = _get_args()

ddb = FlatFileDB("ddb.pyon")
pdb = FlatFileDB("pdb.pyon")
simplephist = SimpleHistory(30)
pdb.hooks.append(simplephist)
rtr = RTResults()

loop = asyncio.get_event_loop()
atexit.register(lambda: loop.close())
@@ -47,8 +41,8 @@ def main():
"req_device": ddb.request,
"req_parameter": pdb.request,
"set_parameter": pdb.set,
"init_rt_results": init_rt_results,
"update_rt_results": update_rt_results
"init_rt_results": rtr.init,
"update_rt_results": rtr.update
})
loop.run_until_complete(scheduler.start())
atexit.register(lambda: loop.run_until_complete(scheduler.stop()))
@@ -67,7 +61,8 @@ def main():
"periodic": scheduler.periodic,
"devices": ddb.data,
"parameters": pdb.data,
"parameters_simplehist": simplephist.history
"parameters_simplehist": simplephist.history,
"rt_results": rtr.sets
})
loop.run_until_complete(server_notify.start(
args.bind, args.port_notify))