fix: hash symbolic quantities structurally#213
Conversation
Fix inconsistent hashing for symbolic dimensions and quantities so equal symbolic units deduplicate correctly. Fixes JuliaPhysics#212 Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Benchmark Results (Julia v1.10)Time benchmarks
Memory benchmarks
|
Benchmark Results (Julia v1)Time benchmarks
Memory benchmarks
|
MilesCranmer
left a comment
There was a problem hiding this comment.
@MilesCranmerBot please integrate these suggestions
Refine symbolic-dimension hashing to follow the local while-loop style and normalize exponent values structurally, so equal symbolic units hash consistently across representations. Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
|
@MilesCranmerBot CI is failing, pls fix |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #213 +/- ##
=======================================
Coverage 99.15% 99.16%
=======================================
Files 23 23
Lines 1305 1320 +15
=======================================
+ Hits 1294 1309 +15
Misses 11 11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
please ensure that 100% of the diff is covered by testing, it looks like only 83% at the moment. |
MilesCranmer
left a comment
There was a problem hiding this comment.
@MilesCranmerBot see changes. Also please ensure that test coverage of the diff is 100%.
|
|
||
| macro register_constant(name, value) | ||
| return esc(_register_constant(name, value)) | ||
| return esc(_register_constant(__module__, name, value)) |
There was a problem hiding this comment.
Should not be done as part of this PR. If it is needed, it should be done in a separate PR.
| function _register_constant(mod::Module, name::Symbol, value) | ||
| s = string(name) | ||
| name_symbol = Meta.quot(name) | ||
| return quote | ||
| const $name = $value | ||
| Core.eval($mod, Expr(:const, Expr(:(=), $name_symbol, $value))) | ||
| push!(_CONSTANT_SYMBOLS, Symbol($s)) | ||
| push!(_CONSTANT_VALUES, $name) | ||
| push!(_CONSTANT_VALUES, Base.invokelatest(getproperty, $mod, $name_symbol)) | ||
| end | ||
| end | ||
|
|
||
| function _register_constant(name::Symbol, value) | ||
| return _register_constant(@__MODULE__, name, value) | ||
| end | ||
|
|
| end | ||
|
|
||
| function _register_unit(name::Symbol, value) | ||
| return _register_unit(@__MODULE__, name, value) |
efcd578 to
257c843
Compare
|
@MilesCranmerBot CI is failing. Maybe you should use |
Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Summary
Fix inconsistent hashing for symbolic dimensions and symbolic quantities so equal symbolic units deduplicate correctly.
Changes
hashforAbstractSymbolicDimensionshashfor quantities based on value plus dimensionsTesting
/usr/local/bin/julia --project -e 'using DynamicQuantities, Test; @register_unit gacc 9.81u"m/s^2"; @test hash(SymbolicDimensions(; m=1, s=-1)) == hash(SymbolicDimensions(; m=1, g=0, s=-1)); @test hash(us"m/s") == hash(us"m/s"); @test length(unique(fill(us"m/s", 10))) == 1; @test length(unique(sym_uparse.(fill("gacc",10)))) == 1; println("targeted regression checks passed")'Related to #212