From 597fe57fb34bb77ed3590ebb803a22aedbf17417 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 9 Dec 2014 10:48:47 +0800 Subject: [PATCH] pyon: unit support --- artiq/management/pyon.py | 8 ++++++++ test/serialization.py | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/artiq/management/pyon.py b/artiq/management/pyon.py index e3a207beb..c231b63be 100644 --- a/artiq/management/pyon.py +++ b/artiq/management/pyon.py @@ -23,6 +23,8 @@ from fractions import Fraction import numpy +from artiq.language.units import Quantity + _encode_map = { type(None): "none", @@ -34,6 +36,7 @@ _encode_map = { list: "list", dict: "dict", Fraction: "fraction", + Quantity: "quantity", numpy.ndarray: "nparray" } @@ -100,6 +103,10 @@ class _Encoder: return "Fraction({}, {})".format(encode(x.numerator), encode(x.denominator)) + def encode_quantity(self, x): + return "Quantity({}, {})".format(encode(x.amount), + encode(x.unit)) + def encode_nparray(self, x): r = "nparray(" r += encode(x.shape) + ", " @@ -133,6 +140,7 @@ _eval_dict = { "true": True, "Fraction": Fraction, + "Quantity": Quantity, "nparray": _nparray } diff --git a/test/serialization.py b/test/serialization.py index 542c20ded..4a73ac9bd 100644 --- a/test/serialization.py +++ b/test/serialization.py @@ -4,12 +4,14 @@ from fractions import Fraction import numpy as np +from artiq.language.units import * from artiq.management import pyon _pyon_test_object = { (1, 2): [(3, 4.2), (2, )], - Fraction(3, 4): np.linspace(5, 10, 1) + Fraction(3, 4): np.linspace(5, 10, 1), + "frequency": 10*GHz }