Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a new class for physical constants and variable, separate from Quantity. #16757

Open
schymans opened this issue Apr 30, 2019 · 2 comments
Open
Labels
Enhancement physics.units Units and dimensions

Comments

@schymans
Copy link
Contributor

The current class Quantity is well suited to represent units, but due to its limitations, it is not so good for physical constants and especially variables, which can be positive or negative.

@jirikuncar and I created a sympy-based system to deal with physical variables and equations here: https://github.com/environmentalscience/essm

We originally used Quantity to represent physical constants and variables, but we ran into all sorts of problems. Now we base our Variable class on Symbol and consider quantities just as units. Works like a charm. Perhaps this could be merged into sympy at some point. I think everything would be a lot clearer if we used the current Quantity for units and a separate Variable for physical constants. Then there would be no point in defining different quantities with the same dimension and scale factor, leading to problems such as described e.g. in #14595, #14374, #14596, #13267, #14374, ...

@sylee957 sylee957 added Enhancement physics.units Units and dimensions labels May 1, 2019
@meganly
Copy link
Contributor

meganly commented Jul 16, 2021

I think everything would be a lot clearer if we used the current Quantity for units

I totally agree! My idea is to then have a class called PhysicalQuantity to represent numerical quantities with units as PhysicalQuantity(magnitude, units). Is this similar to your Variable class? I found it a little confusing have a class for physical constants named "Variable" since constants are fixed, but variables change. Overall essm looks pretty neat though.

@schymans
Copy link
Contributor Author

schymans commented Sep 2, 2021

Good point, PhysicalQuantity would be a more accurate name, but a bit tedious to type. Perhaps PQ as you suggested in another issue. The way Variable works in ESSM, is that it behaves just like any other symbol, but has additional information stored with it, such as a docstring, latex representation, default units and an optional default value, e.g. for constants. For doing calculations, one needs to substitute values for the variables, just like substitution for symbols in normal sympy expressions. There is a special Equation class, which uses the unit information stored in Variable to check for dimensional consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement physics.units Units and dimensions
Projects
None yet
Development

No branches or pull requests

3 participants