Add sampled multiband template fitting (CUDA and Rust) - #8
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add sampled multiband template fitting (CUDA and Rust)
Adds
TemplateFitSampledon both backends, reachable through the device APIlike the other algorithms.
What it does
Fits a bank of physical templates to a multiband light curve at each of its own
trial periods and returns the single best
(period, template, phase, amplitude). Not a periodogram: the candidate periods come from one, and thischooses among them using a model of the class.
The model at trial period P, for band b:
The offset is free per band and
ais one amplitude shared across all bands,so the band amplitude ratios are a constraint the fit has to respect and not a
free parameter each. Score is the fraction of variance unexplained, pooled over
bands.
Templates are samples on a phase grid; folding the light curve onto that same
grid makes every sum the score needs a circular correlation, so one transform
gives the score at all phase shifts at once.
Timing
Measured on one A100, each object fitted at ~200 trial periods over 512 phase
shifts. Cost is linear in bank size, about 0.11 ms per template per object:
The Rust backend on 8 cores takes 3.53 s per object for the 820 template bank,
so the GPU is 38x faster on the same fit.
Accuracy
Rubin DP2, 613 objects with published periods from VSX and other catalogues,
each fitted against the bank of its own class only. The banks come from three
generators, none of them part of this library:
Cepheid type-II, Delta Scuti.
Exact means within 2 per cent of the published period:
The harmonic column counts a factor of two or three as recovered. It matters
only for eclipsing binaries, where the light curve genuinely repeats at half
the orbital period, and EA goes from 68 to 86 per cent on that basis.
The same objects and the same banks, fitted with templates truncated to eleven
Fourier coefficients instead of sampled, give EA 55 per cent against 68 and
Delta Scu 69 against 75, with the smooth classes unchanged. That is the case
for holding templates as samples: it buys accuracy exactly where a truncated
series cannot represent the shape.
Double precision
f64 end to end. The score is an argmin over
n_template * n_phasenearly tiedcolumns and folds a long baseline at short periods; in single precision a
different column wins.
That is also why
dblatomic.cuhis new.atomicAddon double is native onlyfrom compute capability 6.0 and
setup.pycompiles fromcompute_50, so theolder targets need the documented compare-and-swap fallback. Accumulating in
float, as the existing kernels do, is not an option here.
Validation
The CPU and GPU backends were run on the same 22 light curves against an 820
template bank: identical period, template and phase shift on all 22, with fvu
agreeing to 7e-11. The Rust was separately checked against an independent numpy
implementation, also identical.
Tests: 8 Rust unit tests in
tfs.rs, 7 pytest intests/test_template_fit_sampled.py. Both build templates analytically, so nodata files are added.
No bank ships
The kernel takes
samplesfrom the caller, so the library carries no templatedata.
docs/user-guide/template-banks.mddocuments the array contract, how tobuild a bank, and how to choose the phase grid.