Skip to content

fix(RVFWHMmodel): preserve prior precision in save_setup#57

Open
dgegen wants to merge 2 commits intokima-org:mainfrom
dgegen:fix/rvfwhm-prior-precision
Open

fix(RVFWHMmodel): preserve prior precision in save_setup#57
dgegen wants to merge 2 commits intokima-org:mainfrom
dgegen:fix/rvfwhm-prior-precision

Conversation

@dgegen
Copy link
Copy Markdown
Contributor

@dgegen dgegen commented Mar 24, 2026

Problem

RVFWHMmodel::save_setup writes the setup file without std::fixed, so the default C++ stream formatting uses only 6 significant figures. For large BJD-scale values, this truncates distinct prior bounds to the same value — e.g. Tcprior bounds 2458520.644883 and 2458520.656756 both become 2.45852e+06. When load_results reads the setup file back, it fails with:

ValueError: Uniform distribution must have lower < upper limits

This affects any prior whose bounds are large-magnitude values, and is likely the root cause of the error reported in #24.

RVmodel already uses std::fixed and is not affected.

Fix

  • Add std::fixed to fout at the start of save_setup, matching the approach in RVmodel
  • Remove the fout.precision(15) / fout.precision(6) workaround around M0_epoch, which was a narrow patch for the same root cause

After applying this fix and recompiling, RVFWHMmodel runs as before, but load_results now correctly reads back the setup file for models with the correct large-magnitude prior bounds for BJD-scale transit times, allowing me to use this model.

Note

The same pattern existed in BINARIESmodel, ETVmodel, GAIAmodel, GPmodel, RVFWHMRHKmodel, RVGAIAmodel, SPLEAFmodel, and TRANSITmodel. I have applied the same fix to all of these, and additionally added fout.precision(15) globally across all models to ensure full double precision is preserved regardless of the magnitude of prior bounds.

Let me know what you think!

Cheers,
David

…ision

Without std::fixed, the default stream formatting uses 6 significant
figures, which truncates large BJD-scale values (e.g. Tcprior bounds
~2458520.644 and ~2458520.656 both round to 2.45852e+06). This caused
load_results to fail with "Uniform distribution must have lower < upper
limits". Also removes the narrow precision(15)/precision(6) workaround
around M0_epoch, which was a symptom of the same root cause.
Copilot AI review requested due to automatic review settings March 24, 2026 00:26
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes precision loss when RVFWHMmodel::save_setup serializes model priors to kima_model_setup.txt, preventing large-magnitude prior bounds (e.g., BJD-scale times) from being rounded into identical values and subsequently breaking load_results.

Changes:

  • Enable std::fixed formatting for the setup-file stream in RVFWHMmodel::save_setup (matching RVmodel behavior).
  • Remove the local precision(15) / precision(6) formatting toggle around M0_epoch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…across all models

Add `std::fixed` and `fout.precision(15)` globally in `save_setup` for all
models that were missing it (BINARIESmodel, ETVmodel, GAIAmodel, GPmodel,
OutlierRVmodel, RVFWHMRHKmodel, RVGAIAmodel, SPLEAFmodel, TRANSITmodel) and
add `fout.precision(15)` to models that already had `std::fixed` but lacked
explicit precision (ApodizedRVmodel, RVFWHMmodel, RVHGPMmodel, RVmodel).

Also removes the narrow `precision(15)`/`precision(6)` workarounds around
`M0_epoch` that were present in several files, as these are now superseded
by the global setting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants