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: 8d59f843fba2
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: d59d110f784b
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Nov 22, 2014

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ab88c6d View commit details
  2. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    chris-huxtable Chris Huxtable
    Copy the full SHA
    d59d110 View commit details
Showing with 17 additions and 3 deletions.
  1. +10 −3 artiq/transforms/lower_units.py
  2. +1 −0 doc/manual/index.rst
  3. +6 −0 test/full_stack.py
13 changes: 10 additions & 3 deletions artiq/transforms/lower_units.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import ast
from collections import defaultdict
from copy import copy

from artiq.language import units

@@ -14,6 +16,7 @@ def wrapper(*args):
class _UnitsLowerer(ast.NodeTransformer):
def __init__(self, rpc_map):
self.rpc_map = rpc_map
self.rpc_remap = defaultdict(lambda: len(self.rpc_remap))
self.variable_units = dict()

def visit_Name(self, node):
@@ -66,9 +69,9 @@ def visit_Call(self, node):
elif node.func.id == "now":
node.unit = "s"
elif node.func.id == "syscall" and node.args[0].s == "rpc":
unit_list = [getattr(arg, "unit", None) for arg in node.args]
unit_list = tuple(getattr(arg, "unit", None) for arg in node.args[2:])
rpc_n = node.args[1].n
self.rpc_map[rpc_n] = _add_units(self.rpc_map[rpc_n], unit_list)
node.args[1].n = self.rpc_remap[(rpc_n, (unit_list))]
return node

def _update_target(self, target, unit):
@@ -105,4 +108,8 @@ def visit_For(self, node):


def lower_units(func_def, rpc_map):
_UnitsLowerer(rpc_map).visit(func_def)
ul = _UnitsLowerer(rpc_map)
ul.visit(func_def)
original_map = copy(rpc_map)
for (original_rpcn, unit_list), new_rpcn in ul.rpc_remap.items():
rpc_map[new_rpcn] = _add_units(original_map[original_rpcn], unit_list)
1 change: 1 addition & 0 deletions doc/manual/index.rst
Original file line number Diff line number Diff line change
@@ -13,3 +13,4 @@ Contents:
core_drivers_reference
management_reference
drivers_reference
fpga_board_ports
6 changes: 6 additions & 0 deletions test/full_stack.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
from fractions import Fraction

from artiq import *
from artiq.language.units import Quantity
from artiq.coredevice import comm_serial, core, runtime_exceptions, rtio
from artiq.sim import devices as sim_devices

@@ -44,13 +45,16 @@ def run(self):
class _Misc(AutoContext):
def build(self):
self.input = 84
self.inhomogeneous_units = []

@kernel
def run(self):
self.half_input = self.input//2
decimal_fraction = Fraction("1.2")
self.decimal_fraction_n = int(decimal_fraction.numerator)
self.decimal_fraction_d = int(decimal_fraction.denominator)
self.inhomogeneous_units.append(Quantity(1000, "Hz"))
self.inhomogeneous_units.append(Quantity(10, "s"))


class _PulseLogger(AutoContext):
@@ -157,6 +161,8 @@ def test_misc(self):
self.assertEqual(Fraction(uut.decimal_fraction_n,
uut.decimal_fraction_d),
Fraction("1.2"))
self.assertEqual(uut.inhomogeneous_units, [
Quantity(1000, "Hz"), Quantity(10, "s")])

def test_pulses(self):
l_device, l_host = [], []