Keep parameters as float128 values in tm_delay#228
Keep parameters as float128 values in tm_delay#228mattpitkin wants to merge 2 commits intonanograv:masterfrom
Conversation
|
Note that for some platforms (most notably Apple Silicon a.k.a. arm64) float128 it's either unavailable or defaults to a regular double. So on some platforms the change may break the code, or not fix the problem. On those platforms, tempo2 will also operate with double precision internally. So I'm not sure what the way forward is. Is it a problem if this code breaks on arm64? It would signal that simulation is not doing what one thinks it is, but should we ship broken code? Will it even CI? |
|
I've made a slight change to workaround |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #228 +/- ##
==========================================
+ Coverage 37.29% 37.30% +0.01%
==========================================
Files 20 20
Lines 3974 3978 +4
==========================================
+ Hits 1482 1484 +2
- Misses 2492 2494 +2
Continue to review full report in Codecov by Sentry.
|
In the
tm_delayfunction, the parameters to be varied are set asnp.doubleprecision values. The original values in thet2pulsarobject (in particular the frequency parameters) are stored asnp.float128, so the recasting asdouble's loses some precision. This isn't generally problematic, but it can be problematic if you are doing simulations with very low noise and truncation of, e.g., the frequency, caused by converting todouble's throws off other parameters.I will show a concrete example. I generate some fake TOAs for J2145-0750 using the Tempo2
fakeplugin, with the very low noise of 0.1ns:where the
.parfile contained:Now, if I assume that
F2is actually unknown and I want to estimate its value from the TOAs, I could set up a.par, called, say,J2145-0750_no_f2.parfile containing:and run (the below assumes #226 has been applied to allow it to run with
white_vary=False):it gives:
where the
F2value is completely wrong (note that a fit with Tempo2 itself gets the correct value).From digging into why this is happening, I find that when the
F0value gets converted fromfloat128todoublein timing.py, it gets truncated from:to
With the very low noise, this difference in frequency is enough to throw off the estimation of
F2. If I apply the patch in this PR and run the above code again, I get:which has the correct
F2value.