Skip to content

Fix dloglik crash when using CG optimizer with warped BLR models#379

Merged
contsili merged 3 commits intoamarquand:devfrom
divye-joshi:fix-blr-cg-warp-crash
Feb 24, 2026
Merged

Fix dloglik crash when using CG optimizer with warped BLR models#379
contsili merged 3 commits intoamarquand:devfrom
divye-joshi:fix-blr-cg-warp-crash

Conversation

@divye-joshi
Copy link

Fix dloglik crash when using CG optimizer with warped BLR models

Description

This PR fixes a bug where BLR.fit() crashed with a misleading Unknown function dloglik error when attempting to use the cg optimizer in combination with a warp function (e.g., warpsinharcsinh).

The root cause was that analytical gradients (dloglik) are not implemented for warped models. When the user manually selected optimizer="cg", fit() passed the unsupported dloglik function to the SciPy optimizer, which resulted in a hard crash during optimization.

Changes

  • Added a validation check in BLR.fit() before optimization begins.
  • If optimizer="cg" is used with a warped model, fit() will:
    • Log a warning indicating that analytical gradients are unsupported.
    • Automatically fall back to the default l-bfgs-b optimizer, which correctly uses numerical approximations.
  • Added a new structured warning WARNINGS.BLR_CG_NOT_SUPPORTED_WITH_WARP in output.py for clarity.

Closes

Closes #378

@contsili
Copy link
Collaborator

very good catch! I only improved the error message inside the dloglik(). I don't expect this error to happen ever after the check you added but just to make sure i kept it and made it more clearly describing the issue

@contsili contsili merged commit b4a1ac2 into amarquand:dev Feb 24, 2026
2 checks passed
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