Skip to content

Remove manual Cholesky workaround when PyMC fixes LKJ bug #1

Description

@thomaspinder

Context

PyMC 5.28 + PyTensor 2.38 + NumPy 2.4 have a compatibility bug where pm.LKJCholeskyCov and pm.LKJCorr fail with:

ValueError: not enough values to unpack (expected 5, got 3)

in pytensor/tensor/einsum.py. The einsum_path returns 3-tuples but PyTensor expects 5-tuples.

Current workaround

src/litterman/spec.py uses a manual Cholesky parameterization instead:

sd = pm.HalfCauchy("sigma_sd", beta=2.5, shape=n_vars)
L = pt.zeros((n_vars, n_vars))
L = pt.set_subtensor(L[np.diag_indices(n_vars)], sd)
if n_tril > 0:
    tril_vals = pm.Normal("tril_offdiag", mu=0, sigma=0.5, shape=n_tril)
    # fill lower triangle manually

What needs to happen

  • Monitor PyMC/PyTensor releases for a fix to the LKJ einsum bug
  • Once fixed, replace manual Cholesky with pm.LKJCholeskyCov for cleaner parameterization
  • Test that the LKJ version produces equivalent posteriors

Labels

tech-debt, upstream-dependency

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions