jerbaroo / bridge-sim

Python library for concrete slab bridge simulation.
MIT License
1 stars 0 forks source link

Types for units #160

Open jerbaroo opened 4 years ago

jerbaroo commented 4 years ago

Metre = NewType(float, "Metre") KiloNewton = NewType(float, "KiloNewton")

Or have a look at a Python library, though it might not really be necessary for the few types being used. When looking at a third party library would be interested how it handles "strain" and "microstrain".

I would start by adding simple NewTypes, and then look at a library. Unless the library seems pretty fantastic.

jerbaroo commented 4 years ago

https://www.researchgate.net/publication/326550053_Physical-type_correctness_in_scientific_Python

Not looking for this kind of correctness, but I find it interesting.

rozsasarpi commented 4 years ago

Yes, interesting. I think what they are aiming for is likely unattainable. For example, as it is meaningless to add together stress and Young's modulus, it is often meaningless to add together two stresses, e.g. if they are from different points or if they are from the same point but one is shear and the other is normal stress. I think for their correctness you would need to add a lot of additional metadata and checks.

I vote for performance and I'm ready to debug my code to find issues with units. :)

jerbaroo commented 4 years ago

You might find it interesting that a language like Haskell has a mechanism that could support checks for Kinds of Quantities, though I have no desire to support this, no point at all, just an aside. In Haskell these are called Kinds of Types.

jerbaroo commented 4 years ago

However I really would like to add support for some kind of unit checking in the future, but I don't want to rush it. I prefer not to do so with variable naming, but with some (ideally optional) system that will check the units are correct, either via static analysis or at run-time. I noticed the pint units package supports different unit systems.

vote for performance

Perhaps support for unit-checking via static analysis then. I think this needs a lot more thought, and I need more free-time for this, to create a few examples.

rozsasarpi commented 4 years ago

Agreed, I think this is something interesting and would be cool to have but currently has a low priority. (Haskell is getting more and more interesting :))