Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions Paramood/bridge/formatting.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from ..core.expressions import SCALAR, UNITS, TextValue
from ..core.expressions import TextValue, unit_definition


def display_quantity(quantity, unit):
if isinstance(quantity, TextValue):
return quantity.value
if not unit and quantity.dimension == SCALAR:
return quantity.value
if unit not in UNITS or UNITS[unit][1] != quantity.dimension:
raise ValueError('Unsupported output unit')
return quantity.value / UNITS[unit][0]
factor, dimension, offset = unit_definition(unit)
if dimension != quantity.dimension:
raise ValueError('Incompatible output unit')
return (quantity.value - offset) / factor
5 changes: 1 addition & 4 deletions Paramood/bridge/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from ..core.expressions import (
ExpressionError,
LocalEvaluationUnsupported,
NondeterministicExpression,
)


Expand Down Expand Up @@ -66,9 +65,7 @@ def dispatch(adapter, message):
}
except ExpressionError as exc:
code = (
'NONDETERMINISTIC_EXPRESSION'
if isinstance(exc, NondeterministicExpression)
else 'LOCAL_EVALUATION_UNSUPPORTED'
'LOCAL_EVALUATION_UNSUPPORTED'
if isinstance(exc, LocalEvaluationUnsupported)
else 'INVALID_EXPRESSION'
)
Expand Down
4 changes: 3 additions & 1 deletion Paramood/core/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
)
FUNCTIONS = {item['name']: item for item in CATALOG['functions']}
CONSTANT_NAMES = {item['name'] for item in CATALOG['constants']}
UNIT_NAMES = set(CATALOG['units'])
UNIT_NAMES = set(CATALOG['units']) | {
alias for unit in CATALOG['unitDefinitions'] for alias in unit['aliases']
}
Loading
Loading