Skip to content

Bug: errors in handing physical quantities #285

Open

Description

@peterbjohnson

Description of the bug

Discovered by Claude while auditing the physical quantities features:

Physical quantity mode: errors found in code review

Unit table (app/utility/unit_system_conversions.py)

  • Roentgen expands to kelvin/kilogram; should be coulomb/kilogram. Docs table has the same error.
  • Angle conventions are mixed. Degree = 1/360 and radian = 1/(2*pi) (one turn = 1), but angleminute = pi/10800 and anglesecond = pi/648000 assume radian = 1. Result: 60 angleminute != 1 degree.
  • rad maps to the absorbed-dose unit (0.01 Gy); radian uses r. Input 3.14 rad parses as a dose with dimension m^2/s^2.
  • Litre plurals are one string, ('litres,liters',); neither plural is recognised. Should be ('litres', 'liters').
  • Comment says short forms of set_of_common_units_in_SI are unused, but SLR_generate_unit_dictionaries loads x[1] for all units. Consequences: da also maps to deci-are; with units_string without imperial, ft parses as femto-metricton.
  • Truncated constants: pint 0.00056826 (exact 0.00056826125), electronvolt 1.60218e-19 (exact 1.602176634e-19), atomic mass unit 1.66054e-27 (1.66053906660e-27).
  • Bel comment says "log(10) in base 2"; the value is the natural log of 10.
  • Docs only: gallon listed as 4546.09 litre (should be 4.54609), barn in metre (should be metre^2), kelvin symbol shown as k, litre symbol shown as l (code uses L).

Transforms (app/utility/physical_quantity_utilities.py)

  • transform_prefixes_to_standard: the (?<!\w) lookbehind fails after a digit. 5 μm converts, 5μm does not, and μ is not in the unit dictionaries.

Comparison (app/context/physical_quantity.py)

  • is_proportional: the elif repeats the test on expr0; the expr1 branch never runs.
  • <, >, <=, >= criteria: with mismatched dimensions, bool() on an undecided SymPy relational raises TypeError. No tolerance is applied to these comparisons.
  • feedback_string_generator is a stub returning None.
  • Docs say criteria are ignored when physical_quantity is true; the code supports matches, dimension and comparison criteria.

Parser (app/utility/slr_parsing_utilities.py)

  • ExprNode uses a mutable default tags=set(), shared by all nodes created without a tag_handler. copy() also passes the same set object to the copy.
  • SLR_Parser.parse: output += ExprNode(self.parse(tokens), []) passes a list where a Token is expected; this path would raise.
  • parse_quantity rebuilds the SLR parser table on every evaluation. Cache by (units_string, strictness).

Expression(s)/input that trigger it

.

Expected vs. actual result

.

Steps to reproduce / where it was used

.

Activity

  1. peterbjohnson commented on Oct 28, 2026

    @peterbjohnson
    MemberAuthor

    Also, (additional items from #303, which was otherwise a duplicate):

    • Lumen and lux ignore the file's steradian. Lumen is cd·sr, and steradian is (1/(4*pi)) in this file. lumen is set to (candela), and lux to (metre**(-2)*candela). Both are missing the steradian factor.
    • A plural form does not follow its unit name. nauticalmiles should be nautical_miles to match nautical_mile.
    • Comments contain typos. "an neper" should be "and neper", and "to many" should be "too many".
    • Atomic mass unit uses an older value. The value above, 1.66053906660e-27, is CODATA 2018. CODATA 2022 gives 1.66053906892e-27.
  2. m-messer commented on Oct 30, 2026

    @m-messer
    Member

    Status of each item (including those from #303) against packages 0.4.0-rc1-preview and the fix stack (top: #302).

    Resolved

    Item Where
    Roentgen in K/kg packages data.py: second*ampere/kilogram
    Mixed angle conventions radian = steradian = 1, degree = pi/180; 60 angleminute = 1 degree
    rad vs radian deliberate and documented in data.py (r is the radian)
    Litre plurals ("litres", "liters")
    Short forms for every set / ft as femto-metricton every set's symbols are recognised; 1 ft = 0.3048 m
    Bel comment, comment typos corrected
    Lumen/lux without sr consistent now that sr = 1
    nauticalmiles nautical_miles is the plural; the old spelling is kept as an alias
    is_proportional elif #286
    </> TypeError with mismatched dimensions #284 (comparison_function returns None)
    ExprNode mutable tags / shared copy, SLR_Parser.parse list argument, parser rebuilt per evaluation packages slr_parsing rewrite; build_quantity_parser is cached

    Still open, tracked separately

    Open until #284 and #286 reach main.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions