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: 5c08423b29d8
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: 1ceb06fb1642
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on May 9, 2015

  1. Copy the full SHA
    fdc406f View commit details
  2. Copy the full SHA
    1ceb06f View commit details
Showing with 83 additions and 11 deletions.
  1. +16 −0 artiq/coredevice/dds.py
  2. +60 −3 artiq/transforms/inline.py
  3. +4 −4 examples/master/repository/dds_test.py
  4. +3 −4 examples/master/repository/photon_histogram.py
16 changes: 16 additions & 0 deletions artiq/coredevice/dds.py
Original file line number Diff line number Diff line change
@@ -10,13 +10,29 @@
PHASE_MODE_TRACKING = 2


class _BatchContextManager:
def __init__(self, dds_bus):
self.dds_bus = dds_bus

@kernel
def __enter__(self):
self.dds_bus.batch_enter()

@kernel
def __exit__(self, type, value, traceback):
self.dds_bus.batch_exit()


class DDSBus(AutoDB):
"""Core device Direct Digital Synthesis (DDS) bus batching driver.
Manages batching of DDS commands on a DDS shared bus."""
class DBKeys:
core = Device()

def build(self):
self.batch = _BatchContextManager(self)

@kernel
def batch_enter(self):
"""Starts a DDS command batch. All DDS commands are buffered
63 changes: 60 additions & 3 deletions artiq/transforms/inline.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
import ast
import types
import builtins
from copy import copy
from fractions import Fraction
from collections import OrderedDict
from functools import partial
@@ -199,8 +198,10 @@ def code_visit(self, node):

# This is ast.NodeTransformer.generic_visit from CPython, modified
# to update self._insertion_point.
def code_generic_visit(self, node):
def code_generic_visit(self, node, exclude_fields=set()):
for field, old_value in ast.iter_fields(node):
if field in exclude_fields:
continue
old_value = getattr(node, field, None)
if isinstance(old_value, list):
prev_insertion_point = self._insertion_point
@@ -378,6 +379,60 @@ def code_visit_ExceptHandler(self, node):
self.code_generic_visit(node)
return node

def get_user_ctxm(self, context_expr):
try:
ctxm = self.static_visit(context_expr)
except:
# this also catches watchdog()
return None
else:
if (ctxm is core_language.sequential
or ctxm is core_language.parallel):
return None
return ctxm

def code_visit_With(self, node):
if len(node.items) != 1:
raise NotImplementedError
item = node.items[0]
if item.optional_vars is not None:
raise NotImplementedError
ctxm = self.get_user_ctxm(item.context_expr)
if ctxm is None:
self.code_generic_visit(node)
return node

# user context manager
self.code_generic_visit(node, {"items"})
if (not hasattr(ctxm, "__enter__")
or not hasattr(ctxm.__enter__, "k_function_info")):
raise NotImplementedError
enter = get_inline(self.core,
self.attribute_namespace, self.in_use_names,
None, self.mappers,
ctxm.__enter__.k_function_info.k_function,
[ctxm], dict())
if (not hasattr(ctxm, "__exit__")
or not hasattr(ctxm.__exit__, "k_function_info")):
raise NotImplementedError
exit = get_inline(self.core,
self.attribute_namespace, self.in_use_names,
None, self.mappers,
ctxm.__exit__.k_function_info.k_function,
[ctxm, None, None, None], dict())
try_stmt = ast.copy_location(
ast.Try(body=node.body,
handlers=[],
orelse=[],
finalbody=exit.body), node)
return ast.copy_location(
ast.With(
items=[ast.withitem(context_expr=ast.Name(id="sequential",
ctx=ast.Load()),
optional_vars=None)],
body=enter.body + [try_stmt]),
node)

def code_visit_FunctionDef(self, node):
node.args = ast.arguments(args=[], vararg=None, kwonlyargs=[],
kw_defaults=[], kwarg=None, defaults=[])
@@ -470,7 +525,9 @@ def get_attr_writeback(attribute_namespace, rpc_mapper, loc_node):
def inline(core, k_function, k_args, k_kwargs, with_attr_writeback):
# OrderedDict prevents non-determinism in attribute init
attribute_namespace = OrderedDict()
in_use_names = copy(embeddable_func_names)
# NOTE: in_use_names will be mutated. Do not mutate embeddable_func_names!
in_use_names = embeddable_func_names | {"sequential", "parallel",
"watchdog"}
mappers = types.SimpleNamespace(
rpc=HostObjectMapper(),
exception=HostObjectMapper(core_language.first_user_eid)
8 changes: 4 additions & 4 deletions examples/master/repository/dds_test.py
Original file line number Diff line number Diff line change
@@ -17,10 +17,10 @@ class DBKeys:

@kernel
def run(self):
self.dds_bus.batch_enter()
self.dds1.set(120*MHz)
self.dds2.set(200*MHz)
self.dds_bus.batch_exit()
with self.dds_bus.batch:
self.dds1.set(120*MHz)
self.dds2.set(200*MHz)
delay(1*us)

for i in range(10000):
if i & 0x200:
7 changes: 3 additions & 4 deletions examples/master/repository/photon_histogram.py
Original file line number Diff line number Diff line change
@@ -27,10 +27,9 @@ class DBKeys:

@kernel
def program_cooling(self):
self.dds_bus.batch_enter()
self.bd_dds.set(200*MHz)
self.bdd_dds.set(300*MHz)
self.dds_bus.batch_exit()
with self.dds_bus.batch:
self.bd_dds.set(200*MHz)
self.bdd_dds.set(300*MHz)

@kernel
def cool_detect(self):