-
Notifications
You must be signed in to change notification settings - Fork 5
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
Converting nanoseconds to picoseconds? #19
Comments
The primary intended workflow with QuantiPhy is:
So a fundamental assumption is that the except when reading and writing numbers, the value is always represented in its base units, in this case, seconds. I don't really understand your motivation for wanting the value in picoseconds, so let me give two possible answers. First I will assume that internally you need picoseconds in order to perform a calculation. In that case you can simply do the following:
Or, if you want the code to be more explicit, you can use the following:
Notice that mytime_in_ps is represented as a float. You generally only want to use a QuantiPhy's quantity when representing numbers in their base units, otherwise you can end up with weird results like:
That explains why I did not use the scale feature of QuantiPhy, as it would have ended up with a quantity with base units of 'ps'. You can do this if you want, but then you should avoid outputting numbers with scale factors. So for example, you can use:
The scale factor is a scale by value rather than a scale to value, so it is simply multiplied by the specified number to get the final result. So in this case '1 ns' is converted to 1e-9 's', which is then multiplied by 1e12 to get the final result in 'ps'. The other possibility that I can think of is that the internal computations are performed in seconds and you simply want to convert the results into picoseconds upon output. This is the more common scenario but it does not appear to be what you want. Anyway, just in case, here it is:
In this case scale converts the result to picoseconds, but you should also suppress the use of SI scale factors:
|
Hi @KenKundert , Many thanks for the excellent feedback!
Ah yes, sorry about that. Basically, I started experting with some libraries for VCD files; one of the key parts of these files is the timescale statement:
So, the timescale is specified as a string. Now, some libraries default to "ps" timescale, some to "ns" timescale - so if I want to convert from one to the other, and avoid resampling, I want to find out how many picoseconds is, say, "100 ns". So I throught - instead of me trying to write my own converter, I might as well try to see is there is some units library - and I found Quantiphy. And it works great for me in this case - I was just unclear on how things are supposed to work.
Excellent - thanks for this, this is the critical piece of information that I was missing. And thanks also for the great examples. I guess I can close this issue now ... |
I tried reading a bit through the docs, but cannot figure how to do this...
Let's say I have a '1 ns', and I would like to convert this to picoseconds; a-priori I know that 1 ns = 1000 ps. So:
How can I correctly convert from one to another prefix (e.g. n to p), without changing the (physical) unit?
Edit: Read through https://quantiphy.readthedocs.io/en/stable/user.html#scaling-when-creating-a-quantity - so I tried using a tuple for scale:
.... and this passes code-wise, but gives me the wrong result.
Edit2: found https://stackoverflow.com/questions/10969759/python-library-to-convert-between-si-unit-prefixes/45122861#45122861 - and thought this would help:
Thankfully, it was easy to find in the repo that: "... change show_si to form ..."; so I tried this:
Wrong result again ... however, the opposite seems to work:
... yes, indeed 1ns is 1e3 = 1000 ps, great! Except, now I'm not sure, what is the meaning of the first number in scale ...
However, the
.render
function apparently just prints - what I'd like is to convert to a new Quantity, so that when I specify '1 ns' as input time, and specify 'ps' as the "output" unit, then I'd like to be able to read the1e3
==1000
as a plain number somehow (without the units) ... - Ah, that probably works like this:So, this kind of conversion is possible - but how are these kinds of conversions supposed to work?
The text was updated successfully, but these errors were encountered: