'NominalVariable' object has no attribute 'shape' when using pytensor.scan

import pymc as pm
import pytensor

basic_model = pm.Model()

with basic_model:
    beta = pm.Exponential("beta", lam=0.1)
    inter = pm.Exponential("inter", lam=1.0, shape=5)

    test, _ = pytensor.scan(
        fn=lambda foo: foo * beta,
        sequences=[inter],
        outputs_info=None,
    )
    pm.Potential("test", test[0])

with basic_model:
    idata = pm.sample()

I get an error when running this code:

AttributeError: 'NominalVariable' object has no attribute 'shape'

replacing the lambda in scan by either: lambda foo: beta or lambda foo: foo gets rid of the error

using pymc-5.2.0, pytensor-2.10.1 via pip on on x86_64 linux

Try to pass beta explicitly as a non-sequence in which case it should also show up in you lambda. Does that fix it?

Not related to the issue but I assume you want test[-1] in the potential? Maybe that was just for you example

Thanks for the reply! passing beta explicitly as a non-sequence does fix the issue.

I’m not sure if this problem is related:

import pymc as pm
import pytensor

basic_model = pm.Model()

with basic_model:
    beta = pm.Exponential("beta", lam=0.1)
    inter = pm.Exponential("inter", lam=1.0, shape=5)

    def mk_scan(foo, beta):
        return pm.Potential("scan", foo * beta)

    test, _ = pytensor.scan(
        fn=mk_scan,
        sequences=[inter],
        outputs_info=None,
        non_sequences=beta,
    )

with basic_model:
    idata = pm.sample()

Doing this yields this exception:

MissingInputError: Input 0 (inter[t]) of the graph (indices start from 0), used to compute Elemwise{mul,no_inplace}(inter[t], beta), was not provided and not given a value. Use the PyTensor flag exception_verbosity='high', for more information on this error.

Dont put the Potential (or any PyMC named variables inside the scan). You can pass variables created before (like your beta) and use the results in model variables afterwards (like the potential). Inside you should only have operations.

So instead, call pm.Potential("pot", test) on the output of the scan.