-
Notifications
You must be signed in to change notification settings - Fork 315
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
Units, 1e9 vs 1G vs 1000000000 #56
Comments
Intense indeed, I'm sure everyone is going to have different ideas about this. Here are mine, but I'd love to hear from more people: @damazter @guenp @MerlinSmiles @akhmerov @spauka @MarkusJacobsen and anyone else who has an opinion!
|
This was the exact argument in our discussion, the thing I am worried about is mistakes due to being inconsistent in how it is entered.
I think we want to support this for sure in the GUI like things but unless we find a proper way of doing it it will indeed cause more confusion than anything else.
👍
I am worried that using custom datatypes (e.g. Giga floats?) will break compatibility with things like numpy arrays and other built in python functionality. I would say always use SI in the code but allow the set, get, and display functionalities to return it in G, M, m, u etc. I think it would be good to also be able to get and set the units (only possible to change the prefix) of every parameter. Such a unit conversion to SI would then work in a similar way as the get and set-parser.
Agree, this also relates to another point which I think is starting to get important, standard analysis classes (find-data, provide basic plot and do basic fitting routine). I think all should be using the same way to do the unit conversions.
Why would there be separate functions? Would not one that always rounds to the nearest power of 3 and give a G,M, etc as a suffix be the way to go? (maybe pretty is not the right name though) @alexcjohnson , I asked @cdickel to send you an email. He previously had an invite to QCodes but it seems to have gotten lost. |
I like SI units with exponents too. Re: pretty printing: In Jupyter, the
outputs |
I like the precision magic, however I would prefer if it did rounding in powers of 3 (e.g. 2.53e7 -> 25.3e6 or 25.3 M) I guess we can do that with a default formatter. |
Why not enable usage of e.g.
Agree
Same as above. If the units say 'GHz', the data should be saved in GHz. |
that works for most units... but it's fragile - the example I gave above is miles ( |
Oh, are miles SI units? :) |
OK, how about 'mol', we need some lookup table that tells us 'ol' isn't a unit? Anyway I don't think anyone is going to be happy if we only support preexisting SI units... what about e^2/h? And it gets worse if we want qcodes to get use in the wider scientific world. We could take the opposite tack and support some whitelisted set of prefixed units... but then that seems liable to confuse people even more if they ever stray outside that, like if we define THz, GHz, MHz, kHz, then someone has a really fine sweep and wants mHz and it all breaks. I'd much prefer to do something totally robust, even if it isn't the prettiest. |
I would do it the other way around. Try to parse 'mol' as an SI unit, if it fails, then try and see if the first character is an exponent symbol. The code doesn't have to be that idiot proof. 2e^2/h is just G0. :) Also, for those cases where it's dubious you can have users add a space (e.g.'mol' is mol, 'm ol' is mili ol (whatever that may be)). This looks pretty robust to me. |
I prefer to have units and exponents separated too, it seems more robust to me. |
It would make sense if the units/exponents are separated on the lowest level. The parsing can then happen on a higher level and is optional. This way we can all be happy 😀 |
I tend to agree with @adriaan, use of SI units is clear, and the added cost of having to type e9, e-9 after entering ranges is not huge.... If we have pieces of equipment where it is more natural to think in terms of mV or GHz, specifying an exponent manually also does not seem like a huge burden, but I am not sure that automatic parsing of prefixes makes sense, particularly for a wider release. Apart from the examples given above, an additional difficulty may arise for people in CS, trying to specify prefixes in powers of 2, for example the difference between units such as MB (megabyte, 10^6) and MiB (mibibytes, 2^20) etc. Depending on how the higher level is handled, it also may make comparison of traces more difficult. For two different pieces of equipment, one specified in units of Hz, the other in GHz, would |
I would like to add that some numerical simulations are not done in SI units at all, for example it can be useful in simulations to use eV, m_e, nm as a unit system. This would break if qcodes would parse nm as nanometer instead of a baseunit 'nm'. The problem is similar to kg which is not 1000 g but should be stored as 10^-3 kg in this system. Hence I would think that hardcoding any units in qcodes is not a good idea. I would always enter the value of a parameter as a float number in python without any other stuff attached.
Which would also allow for
or maybe:
if that is appropriate for the problem at hand. I know that this hybrid approach can lead to problems. But users should be free to define their own unit systems. |
Cosing as per #494 . |
@alexcjohnson
Yesterday we had a quite intense discussion in the lab on units.
I am personally a big fan of using SI units for everything and then adding e9 (or e-9 or e6 etc) to it to convert it to whatever quantity we need.
There are several pros and cons for this way of doing it
Pros:
Cons:
displaying problem
I looked a bit in the print problem but it looks like there is no easy solution to this. I found the following things which are related but don't cover it completely: numpy set printoptions, converting to a custom float class.
I guess other alternatives (which I haven't found) would be , add a very short conversion function to "pretty float" for easy printing i.e.
print(pretty(x))
.Modify the base python float class repr (not possible as it is immutable and would require recompiling python)
Note if we are going down the pretty float road we can also incorporate the G,M,k, , m, u, n prefixes.
Specifying input problem
I do not know the best way to address this one, from what I understood typing e9 every time is considered a pain. A valid alternative would be to use scientifix prefixes after typing the number i.e.
x=1.24G
would set x to 1.24e9.The text was updated successfully, but these errors were encountered: