SMC-ABC in PyMC v4

Hi everyone,

I am having some trouble running SMC-ABC in PyMC v4. I have followed the topic Does PyMC work for ABC SMC? and, as suggested, decided to open a new topic for this.

I have not found any example for SMC-ABC for the new release, but after reading the documentation on pymc.Simulator, I expected to be able to run at least the example there.

When I run the example on the Simulator doc, I get the following message:

Running on PyMC v4.0.0b6
Initializing SMC sampler...
Sampling 4 chains in 4 jobs
multiprocessing.pool.RemoteTraceback: ----------------------------------------------------------------| 0.00% [0/100 00:00<00:00  Stage: 0 Beta: 0]
"""
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
  File "/usr/local/lib/python3.9/site-packages/pymc/smc/sample_smc.py", line 439, in _apply_args_and_kwargs
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pymc/smc/sample_smc.py", line 363, in _sample_smc_int
    smc._initialize_kernel()
  File "/usr/local/lib/python3.9/site-packages/pymc/smc/smc.py", line 217, in _initialize_kernel
    initial_point, [self.model.datalogpt], self.variables, shared
  File "/usr/local/lib/python3.9/site-packages/pymc/model.py", line 865, in datalogpt
    return self.observedlogpt + self.potentiallogpt
  File "/usr/local/lib/python3.9/site-packages/pymc/model.py", line 882, in observedlogpt
    return self.logpt(vars=self.observed_RVs)
  File "/usr/local/lib/python3.9/site-packages/pymc/model.py", line 763, in logpt
    rv_logps = joint_logpt(list(rv_values.keys()), rv_values, sum=False, jacobian=jacobian)
  File "/usr/local/lib/python3.9/site-packages/pymc/distributions/logprob.py", line 224, in joint_logpt
    temp_logp_var_dict = factorized_joint_logprob(
  File "/usr/local/lib/python3.9/site-packages/aeppl-0.0.28-py3.9.egg/aeppl/joint_logprob.py", line 186, in factorized_joint_logprob
    q_logprob_vars = _logprob(
  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/functools.py", line 888, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "/usr/local/lib/python3.9/site-packages/aeppl-0.0.28-py3.9.egg/aeppl/logprob.py", line 85, in _logprob
    raise NotImplementedError(f"Logprob method not implemented for {op}")
NotImplementedError: Logprob method not implemented for Simulator_rv{0, (0, 0), floatX, False}
"""

So I decided to run pytest test_smc.py and got 5 failures:

FAILED test_smc.py::TestSimulator::test_custom_dist_sum_stat[float32] - NotImplementedError: Logprob method not implemented for Simulator_rv{0, (0, 0), floatX, False}
FAILED test_smc.py::TestSimulator::test_custom_dist_sum_stat[float64] - NotImplementedError: Logprob method not implemented for Simulator_rv{0, (0, 0), floatX, False}
FAILED test_smc.py::TestSimulator::test_multiple_simulators - NotImplementedError: Logprob method not implemented for Simulator_rv{0, (0, 0), floatX, False}
FAILED test_smc.py::TestSimulator::test_nested_simulators - NotImplementedError: Logprob method not implemented for Simulator_rv{0, (0, 0), floatX, False}
FAILED test_smc.py::TestSimulator::test_named_model - NotImplementedError: Logprob method not implemented for Simulator_rv{0, (0, 0), floatX, False}

I have installed PyMC v4 using the instructions on github for MacOS, so I would expect everything to be running smoothly.

Did I miss something in the install/config or am I doing sth wrong here?

Thanks!

Can you share the code you tried to run the example with (not the tests)? Asking because the documentation example is not self contained, it misses some variables definitions on purpose, like data

Sure!

    mu1 = 0.5
    sigma1 = 0.1
    data = np.random.normal(loc=mu1, scale=sigma1, size=1000)

    def simulator_fn(rng, loc, scale, size):
        return rng.normal(loc, scale, size=size)

    with pm.Model() as m:
        loc = pm.Normal("loc", 0, 1)
        scale = pm.HalfNormal("scale", 1)
        simulator = pm.Simulator("simulator", simulator_fn, loc, scale, observed=data)
        idata = pm.sample_smc()
2 Likes

Strange, that runs just fine on my machine

I wonder if it could be related to @anneā€™s problem here ?

The beta installation instructions have been updated to now recommend installing from conda-forge:

conda create -c conda-forge -n pymc_env python=3.9 pymc
conda activate pymc_env

The v4b6 was missed during packaging, so this will currently install v4b5. But you could try that and see if you are still having difficulties.

2 Likes

Thanks, @cluhmann!

Even with conda-forge I am still having the same error message on macOS. When installing it via pip on Linux everything works fine, so my guess it must be something specific to the installation on Mac (and Iā€™m not even on the M1 chip).