GTLS: GPU Transit Least Squares
GTLS (gputls on PyPI) is a CUDA-accelerated implementation of the Transit Least Squares (TLS) algorithm for detecting periodic exoplanet transits in photometric light curves.
It preserves the TLS transit-shape templates and search grids while parallelising phase folding, depth estimation, and weighted residual evaluation on NVIDIA GPUs—achieving 27.9× median paired speedup over 28-worker CPU TLS 2.0.4 (fused-pl) on a 1470-day Kepler-like light curve on an RTX 5090, while reproducing the CPU search's best period, epoch, and S/N.
Why GTLS?
- Familiar API: Near drop-in replacement for
transitleastsquares(from gputls import gtls), supporting default limb-darkened, grazing, and box templates. - Substantial GPU speedup: Evaluates trial periods in batches via CuPy and custom CUDA kernels, with both TLS2 backends (
fused-plandfused). - Automatic memory management: Adapts period batch sizes to free GPU VRAM, enabling multi-year, high-cadence searches on a single GPU.
- Multi-GPU scaling: Run on a specific card (
GPUDeviceID=0) or split one search across multiple GPUs (GPUDeviceIDs=[0, 1]) with identical results.
Installation
Prerequisites
- An NVIDIA GPU with CUDA support (
nvidia-smishould list your GPU) - Python ≥ 3.8
- CuPy matching your CUDA version
Install with pip
Note that the PyPI package name is gputls (imported in Python as gputls).
| Environment | Install command | Notes |
|---|---|---|
| CUDA 12.x (recommended) | pip install "gputls[cuda12]" |
Installs cupy-cuda12x[ctk] with CUDA headers |
| CUDA 13.x | pip install "gputls[cuda13]" |
Installs cupy-cuda13x[ctk] with CUDA headers |
| CUDA 11.x | pip install "gputls[cuda11]" |
Requires a local CUDA Toolkit (CUDA_PATH) |
| CuPy already installed | pip install gputls |
Uses your existing CuPy installation |
Or install from source:
git clone https://github.com/Farthing-0/GTLS.git
cd GTLS
pip install .
Verify your installation
python -c "import cupy, gputls; print('gputls:', gputls.__version__, '| GPUs:', cupy.cuda.runtime.getDeviceCount())"
Troubleshooting (
Failed to find CUDA headers): GTLS compiles its CUDA kernels at runtime via CuPy. If you installed CuPy manually without CUDA headers, reinstall withpip install "cupy-cuda12x[ctk]"(orcupy-cuda13x[ctk]), or pointCUDA_PATHto your local CUDA Toolkit (e.g.,export CUDA_PATH=/usr/local/cuda-11.8).
Quick start
Self-contained example
Copy and run this minimal script—no external light-curve files required:
import numpy as np
from gputls import gtls
# 1. Create a 60-day synthetic light curve with a 5.0-day transit
rng = np.random.default_rng(42)
time = np.linspace(0, 60, 60 * 48) # 30-min cadence, in days
flux = np.ones_like(time) + rng.normal(0, 3e-4, time.size)
in_transit = np.abs((time - 1.2 + 2.5) % 5.0 - 2.5) < 0.06
flux[in_transit] -= 0.002 # 2000 ppm transit depth
# 2. Run the GPU transit search
model = gtls(time, flux)
result = model.power()
print(
f"Period = {result.period:.4f} d, T0 = {result.T0:.4f} d, "
f"Depth = {result.depth:.5f}, SDE = {result.SDE:.1f}"
)
Expected output (numbers vary slightly with GPU precision):
Period = 5.0003 d, T0 = 1.1988 d, Depth = 0.00226, SDE = 31.7
Input data requirements
Before passing a real light curve (e.g., from Kepler or TESS) to gtls(time, flux, dy=None):
time(1D array, days): Time stamps must be finite and span $> 0$ days (at least 3 valid points).NaN/infentries are filtered out automatically.flux(1D array, normalised): Flux must be positive, finite, and detrended around1.0(GTLS warns if the mean flux falls outside0.99–1.01). For real stellar light curves, detrend first with a filter such aswotan.dy(1D array, optional): Per-point flux uncertainties. If omitted, GTLS assigns a uniform uncertainty equal tonp.std(flux).
Migrating from CPU TLS
Switching from transitleastsquares usually requires changing only the import and constructor:
# Before (CPU TLS)
# from transitleastsquares import transitleastsquares
# result = transitleastsquares(time, flux, dy).power()
# After (GTLS)
from gputls import gtls
result = gtls(time, flux, dy).power()
Important differences from CPU
TLS:
result.depthconvention: GTLS reports the fractional transit depth (1 - flux_in_transit, e.g.0.002for a 0.2% transit), whereas upstream TLS reports the in-transit flux level (1 - depth = 0.998).- Legacy/CPU-only arguments:
use_threads,show_progress_bar, andverboseare accepted inpower()for compatibility and ignored.- Removed/empty fields:
snrFitandsnrFitPinkhave been removed;possiblePeriodsandpossiblePeriodsIndicesare returned as empty lists.
Common options and choosing a backend
power() accepts standard TLS keyword arguments alongside GPU controls. Most users only need the options below:
| Argument | Default | Description |
|---|---|---|
backend |
"fused-pl" |
Residual scoring kernel: "fused-pl" (piecewise-linear template approximation, TLS2 style) or "fused" (exact full-template scoring) |
period_min, period_max |
0, inf |
Search bounds in days (0 and inf use the automatic physical bounds) |
periods |
[] |
Explicit array of trial periods (days); overrides the automatic grid |
n_transits_min |
2 |
Minimum number of transits required; sets the default upper period limit (baseline / n_transits_min) |
R_star, M_star |
1.0, 1.0 |
Host star radius and mass (solar units) used to construct the frequency grid |
R_star_min, R_star_max |
0.13, 3.5 |
Stellar radius bounds (solar units) for the trial duration grid |
M_star_min, M_star_max |
0.1, 1.0 |
Stellar mass bounds (solar units) for the trial duration grid |
oversampling_factor |
3 |
Frequency-grid oversampling factor |
duration_grid_step |
1.1 |
Multiplicative step between adjacent trial durations |
transit_depth_min |
1e-5 |
Minimum trial transit depth to evaluate |
transit_template |
"default" |
"default" (limb-darkened), "grazing", or "box" |
GPUDeviceID |
0 |
CUDA device index for single-GPU runs |
GPUDeviceIDs |
None |
List of CUDA device indices to split one search across multiple GPUs (e.g., [0, 1]); overrides GPUDeviceID |
fast |
False |
If True, returns only (periods, power) and skips final epoch refinement and transit statistics |
Which backend should I use?
backend="fused-pl"(default): Fastest for almost all standard searches—including Kepler long cadence, 2-minute TESS sectors, and multi-year light curves down to ~100 s cadence. Uses TLS 2.0.4's piecewise-linear template approximation, coarse initial phase scan (T0_coarsen=3), and duration scouting (scout_every=4), followed by a full-template final epoch fit.backend="fused": Evaluates the exact sampled template without piecewise-linear approximation or duration scouting. Recommended if you want zero template approximation, or on very densely sampled, multi-year light curves (e.g., 25–50 s cadence over 1–4 years), where preparing cumulative sums infused-ploutweighs its scoring savings.
Advanced tuning parameters & environment variables
| Argument / Env Var | Default | Description |
|---|---|---|
T0_fit_margin |
0.01 |
Base phase step as a fraction of trial duration (0 to 0.125; 0 tests every folded sample). Legacy T0_refine_margin is deprecated |
T0_coarsen / TLS_T0_COARSEN |
3 (fused-pl), 1 (fused) |
Set 3 to scan every third base-grid start (when 3 * T0_fit_margin * width >= 2) and refine locally (±2 steps); set 1 to scan every base-grid start |
scout_every / TLS_SCOUT_EVERY |
4 (fused-pl), 0 (fused) |
For curves with >= 2000 points, scans all phases at every scout_every-th duration (plus shortest and longest) and searches remaining durations near those peaks. Set 0 or 1 to disable |
screening_tolerances |
None |
Strictly decreasing positive certificate tolerances for fused pruning. None uses (0.05, 0.015, 0.005, 0.00025); () disables pruning. Affects runtime only, not the final periodogram |
screening_policy |
"fixed" |
"auto" benchmarks 1–4 leading cascade levels per period band on the fly (model.screening_diagnostics records timing). Cannot be combined with explicit screening_tolerances |
bar_location |
0 |
tqdm progress bar vertical offset when running multiple searches concurrently |
TLS_BACKEND |
"fused-pl" |
Default backend when backend is not passed to power() |
TLS_PL_EPS, TLS_PL_A2_SPREAD_MAX |
0.02, 0.1 |
Piecewise-linear fit relative tolerance and weight-spread limit for fused-pl |
Implementation notes:
- Four-level fused screening: Curves with
>= 32,768samples and batches with>= 128periods run a single fused screening cascade with early block termination; smaller workloads keep separate kernels to avoid extra register pressure. - Auto screening (
screening_policy="auto"): Measures disjoint interleaved subsets per period band (factors of 32 for< 32,768samples, factors of 8 for larger curves) and prefers fewer levels within 5% of the fastest measurement. Calibration work contributes to the search itself and is included in total runtime. - Pink-noise S/N (
snrPink): Uses GPU window standard deviations for finitefloat64inputs with>= 4096windows and widths<= 1024points, preserving NumPy summation order; other inputs use the CPU path.
Search outputs (gtlsResult)
power() returns a gtlsResult object (unless fast=True):
| Attribute | Description |
|---|---|
period |
Best orbital period (days) |
T0 |
Mid-transit epoch of the first transit (days) |
duration |
Fitted transit duration (days) |
depth |
Fractional transit depth (1 - flux_in_transit) |
SDE |
Peak Signal Detection Efficiency |
snr, snrPink |
White-noise and pink-noise (correlated) signal-to-noise ratios |
transitTimes |
Mid-transit times falling within the light curve (days) |
periods, power |
Trial period grid and corresponding SDE periodogram |
Additional & legacy attributes on gtlsResult
| Attribute | Description |
|---|---|
chi2 |
Minimum weighted $\chi^2$ per trial period after refinement |
raw_power, raw_chi2 |
Unmasked SDE power and $\chi^2$ from the single period-grid scan |
rawDuration, rawDurations |
Best fractional duration (duration / period) and master fractional-duration grid |
durationPoints |
Best template width in phase-folded data points |
possiblePeriods, possiblePeriodsIndices |
Legacy TLS fields, returned as empty lists |
Examples & tutorials
The examples/ directory contains side-by-side Jupyter notebooks comparing GTLS and TLS on real space-telescope light curves:
kepler_tutorial.ipynb: Searching a Kepler target downloaded withlightkurvetess_tutorial.ipynb: Searching a TESS target
Notebook extras: pip install matplotlib astropy transitleastsquares lightkurve wotan.
Testing & benchmarks
Install test dependencies (pytest, astropy, lightkurve) with:
pip install "gputls[test]"
Run the GPU test suite (end-to-end synthetic injection-recovery, fast mode, real Kepler data in tests/data/, VRAM cleanup, and single- vs. multi-GPU parity):
./run_tests.sh # build + test on GPU 0
./run_tests.sh 1 # build + test on GPU 1
PYTHON=/path/to/python ./run_tests.sh
Or run pytest tests directly (select the GPU via GTLS_GPU_DEVICE).
To benchmark against CPU TLS 1.32 and TLS 2.0.4 (see tests/tls_compare/):
python tests/compare_tls.py # standard suite -> report.md + report.json
python tests/compare_tls.py --suite full --plot
pytest tests/test_tls_compare.py # injection recovery and agreement checks
Project structure
GTLS/
├── src/gputls/ # Core Python + CUDA package
│ ├── main.py # gtls class (public API)
│ ├── core.py # GPU search driver and multi-GPU coordination
│ ├── kernels.cu # CUDA kernels compiled at runtime by CuPy
│ ├── grid.py # Ofir (2014) period grid and duration grid
│ ├── transit.py # Limb-darkened transit templates (batman)
│ ├── stats.py # Periodogram, SDE, and S/N calculations
│ ├── validate.py # Input and argument validation
│ └── constants.py # Default parameters and physical constants
├── examples/ # Kepler and TESS tutorial notebooks
├── tests/ # GPU test suite, TLS comparison tools, sample data
├── docs/images/ # Documentation figures
├── run_tests.sh # Local build and GPU test script
└── pyproject.toml
Release notes (v2.2.3 – v2.2.7)
- v2.2.7: Added TLS2-style phase coarsening (
T0_coarsen) with local refinement and duration scouting (scout_every) tofused-pl; computes the periodogram in a single pass over the period grid; fixed duration-grid mass/radius corner pairing and empty-window baseline fallback. - v2.2.6: Switched default backend to TLS2-style piecewise-linear scoring (
backend="fused-pl"), withbackend="fused"for full-template scoring and full-template final epoch fitting. - v2.2.5: Added
screening_policy="auto", fused four-level screening with early block termination on large workloads, and GPU sliding-windowsnrPink; removedsnrFitandsnrFitPink. - v2.2.4: Aligned final candidate epoch fitting and duration conversion with TLS 2.0.4.
- v2.2.3: Fixed out-of-transit noise-mask duration units (days instead of fractional phase) in
snrandsnrPink.
Citation, acknowledgements, and license
GTLS is adapted from TLS by Michael Hippke and René Heller. If you use GTLS in published work, please cite both the GTLS paper (Hu et al., submitted to A&A) and the original TLS paper:
- Hippke, M. & Heller, R. (2019), Optimized transit detection algorithm to search for periodic transits of small planets, A&A 623, A39.
Both TLS and GTLS are released under the MIT License.
Metadata
Release files for gputls 2.2.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gputls-2.2.7.tar.gz | 97.7 kB | Without provenance | Details for gputls-2.2.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gputls-2.2.7-py3-none-any.whl | Python 3 | none | any | Details for gputls-2.2.7-py3-none-any.whl |
Total release size: 170.4 kB
Release files / gputls-2.2.7.tar.gz
| Download URL | gputls-2.2.7.tar.gz |
|---|---|
| Size | 97.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
32552073894a26958b8055615d7aa5aad8c68bde3bf078ab2446d515be2e014e
|
|
BLAKE2b-256 checksum How to use checksums |
dc46d6e78c532b539242cf5ab2b703a2d63c2b405ff62a2b0e990db398e69633
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / gputls-2.2.7-py3-none-any.whl
| Download URL | gputls-2.2.7-py3-none-any.whl |
|---|---|
| Size | 72.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca91f625526f738e2aebff3e78030609a78f3cc28733eb49f9e0c9711fa6f07e
|
|
BLAKE2b-256 checksum How to use checksums |
c0e52c2e5b5abf568d554490e4fbef6943108731a1f6ba67a805a37c2381703e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for gputls 2.2.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.