Smc in pymc v4 gives too many arguments

I tried to rerun the code of this example that work in pymc3

def normal_sim(a, b):
    return np.random.normal(a, b, 1000)

with pm.Model() as example:
    a = pm.Normal("a", mu=0, sigma=5)
    b = pm.HalfNormal("b", sigma=1)
    s = pm.Simulator("s", normal_sim, params=(a, b), sum_stat="sort", epsilon=1, observed=data)

    idata = pm.sample_smc(kernel="ABC", parallel=True, save_sim_data=True)

And get the following error back

TypeError: normal_sim() takes 2 positional arguments but 4 were given
Apply node that caused the error: Simulator_rv{0, (0, 0), floatX, True}(RandomGeneratorSharedVariable(<Generator(PCG64) at 0x7F841D993320>), TensorConstant{(1,) of 1000}, TensorConstant{11}, Subtensor{int64}.0, b_log___log)
Toposort index: 9
Inputs types: [RandomGeneratorType, TensorType(int64, (1,)), TensorType(int64, ()), TensorType(float64, ()), TensorType(float64, ())]
Inputs shapes: ['No shapes', (1,), (), (), ()]
Inputs strides: ['No strides', (8,), (), (), ()]
Inputs values: [Generator(PCG64) at 0x7F841D993320, array([1000]), array(11), array(-0.12968173), array(0.79790006)]
Outputs clients: [['output'], [SortOp{quicksort, None}(sim_value, TensorConstant{-1})]]

HINT: Re-running with most Aesara optimizations disabled could provide a back-trace showing when this node was created. This can be done by setting the Aesara flag 'optimizer=fast_compile'. If that does not work, Aesara optimizations can be disabled with 'optimizer=None'.
HINT: Use the Aesara flag `exception_verbosity=high` for a debug print-out and storage map footprint of this Apply node.

you can find the whole notebook on colab

Any advice, suggestions?

1 Like

The simulator function API for Simulator is different in V4. It should be something like:

def normal_sim(rng, a, b, size=None):
    return rng.normal(a, b, size=size)
1 Like

What is ring in this context ?

1 Like

It’s the new(ish) numpy random number generation (RNG) scheme. Details here.

1 Like