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 }