pymc-devs / pymc-devs/nutpie

BUG: TypingError using pt.tensor.linalg.eig within a pymc model

Open
#344 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
207
Forks
28
Avg merge
7d 21h
Merged PRs (30d)
1

Description

The issue:

Sampling random matrices, and computing their eigenvalues with pt.tensor.linalg.eig produces a TypingError. Trying the same setup but with the svd function for comparison (they have similar signatures) does not produce an error.

Reproducable code example:
import pymc as pm
import pytensor as pt

pt.config.compiler_verbose = True

with pm.Model() as test:
    
    mat = pm.Normal('mat', size=(5,5))
        
    eigs = pm.Deterministic(
        'eigs',
        pt.tensor.linalg.eig(mat)[0] # <- problem seems to be here
#        pt.tensor.linalg.svd(mat)[1] # <- no problem here
    )
        
    idata = pm.sample()
Error message:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function setitem>) found for signature:
 
 >>> setitem(array(float64, 1d, C), ..., array(complex128, 1d, C))
 
There are 16 candidate implementations:
      - Of which 16 did not match due to:
      Overload of function 'setitem': File: <numerous>: Line N/A.
        With argument(s): '(array(float64, 1d, C), ..., array(complex128, 1d, C))':
       No match.

During: typing of staticsetitem at /venv/lib/python3.12/site-packages/nutpie/compile_pymc.py (1037)

File "venv/lib/python3.12/site-packages/nutpie/compile_pymc.py", line 1037:
    def expand_numba(dim, expanded, x_, out_, user_data_):
        <source elided>
            (values,) = extract(x, user_data_)
            out[...] = values
            ^

During: Pass nopython_type_inference
PyTensor version information:

pytensor==3.3.0
pymc==6.3.1
Python 3.12.3
Ubuntu 24.04.4 LTS x86_64

Context for the issue:

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided PyMC model with the listed Python, PyTensor, PyMC, and Ubuntu versions, comparing eig with svd. Then inspect the expand_numba function at nutpie/compile_pymc.py line 1037 and trace the dtype handling shown in the TypingError. Done means the eig example samples without the reported float64/complex128 assignment failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.