diff --git a/artiq/language/units.py b/artiq/language/units.py index 0584706f1..588631f5e 100644 --- a/artiq/language/units.py +++ b/artiq/language/units.py @@ -5,17 +5,6 @@ _prefixes_str = "pnum_kMG" _smallest_prefix = _Fraction(1, 10**12) -class Unit: - """Represents a fundamental unit (second, hertz, ...). - - """ - def __init__(self, name): - self.name = name - - def __eq__(self, other): - return isinstance(other, Unit) and self.name == other.name - - class DimensionError(Exception): """Exception raised when attempting operations on incompatible units (e.g. adding seconds and hertz). @@ -25,7 +14,8 @@ class DimensionError(Exception): class Quantity: - """Represents an amount in a given fundamental unit (:class:`Unit`). + """Represents an amount in a given fundamental unit (identified by a + string). The amount can be of any Python numerical type (integer, float, Fraction, ...). @@ -144,14 +134,12 @@ class Quantity: return self.amount >= other.amount -def _register_unit(name, prefixes): - unit = Unit(name) - globals()[name+"_unit"] = unit +def _register_unit(unit, prefixes): amount = _smallest_prefix for prefix in _prefixes_str: if prefix in prefixes: quantity = Quantity(amount, unit) - full_name = prefix + name if prefix != "_" else name + full_name = prefix + unit if prefix != "_" else unit globals()[full_name] = quantity amount *= 1000 diff --git a/artiq/transforms/inline.py b/artiq/transforms/inline.py index 9bb9388fb..6a846cfaa 100644 --- a/artiq/transforms/inline.py +++ b/artiq/transforms/inline.py @@ -48,8 +48,7 @@ class _ReferenceManager: for kg in core_language.kernel_globals: self.use_count[kg] = 1 for name in ("int", "round", "int64", "round64", "float", "array", - "range", "Fraction", "Quantity", "EncodedException", - "s_unit", "Hz_unit"): + "range", "Fraction", "Quantity", "EncodedException"): self.use_count[name] = 1 def new_name(self, base_name): diff --git a/artiq/transforms/tools.py b/artiq/transforms/tools.py index b5fb5d547..02eecab45 100644 --- a/artiq/transforms/tools.py +++ b/artiq/transforms/tools.py @@ -35,8 +35,7 @@ def value_to_ast(value): if isinstance(value, units.Quantity): return ast.Call( func=ast.Name("Quantity", ast.Load()), - args=[value_to_ast(value.amount), - ast.Name(value.unit.name+"_unit", ast.Load())], + args=[value_to_ast(value.amount), ast.Str(value.unit)], keywords=[], starargs=None, kwargs=None) return None