# SMC-ABC in PyMC v4

**URL:** <https://discourse.pymc.io/t/smc-abc-in-pymc-v4/9347>\
**Category:** v5\
**Created:** [May 6, 2022, 12:57pm UTC](https://discourse.pymc.io/t/smc-abc-in-pymc-v4/9347 "2022-05-06T12:57:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![amanda.azevedo](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@amanda.azevedo](https://discourse.pymc.io/u/amanda.azevedo)\
**Post date:** [May 6, 2022, 12:57pm UTC](https://discourse.pymc.io/t/smc-abc-in-pymc-v4/9347/1 "2022-05-06T12:57:50Z")

</div>

Hi everyone,

I am having some trouble running SMC-ABC in PyMC v4. I have followed the topic [Does PyMC work for ABC SMC?](https://discourse.pymc.io/t/does-pymc-work-for-abc-smc/8798/9) 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](https://docs.pymc.io/en/latest/api/distributions/generated/pymc.Simulator.html), 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:

```auto
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:

```auto
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](https://github.com/pymc-devs/pymc/wiki/Installation-Guide-(MacOS)) 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!

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [May 6, 2022, 1:59pm UTC](https://discourse.pymc.io/t/smc-abc-in-pymc-v4/9347/2 "2022-05-06T13:59:00Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![amanda.azevedo](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@amanda.azevedo](https://discourse.pymc.io/u/amanda.azevedo)\
**Post date:** [May 6, 2022, 2:00pm UTC](https://discourse.pymc.io/t/smc-abc-in-pymc-v4/9347/3 "2022-05-06T14:00:30Z")

</div>

Sure!

```auto
    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()

```

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [May 6, 2022, 2:04pm UTC](https://discourse.pymc.io/t/smc-abc-in-pymc-v4/9347/4 "2022-05-06T14:04:28Z")

</div>

Strange, that runs just fine on my machine

---

<div class="post-metadata">

**Author:** ![amanda.azevedo](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@amanda.azevedo](https://discourse.pymc.io/u/amanda.azevedo)\
**Post date:** [May 6, 2022, 2:15pm UTC](https://discourse.pymc.io/t/smc-abc-in-pymc-v4/9347/5 "2022-05-06T14:15:15Z")

</div>

I wonder if it could be related to @anne’s problem [here](https://discourse.pymc.io/t/after-installation-of-pymc4-pytest-is-failing-with-modulenotfounderror-no-module-named-aesara/9290/8) ?

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [May 11, 2022, 1:28am UTC](https://discourse.pymc.io/t/smc-abc-in-pymc-v4/9347/6 "2022-05-11T01:28:25Z")

</div>

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

```bash
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.

---

<div class="post-metadata">

**Author:** ![amanda.azevedo](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@amanda.azevedo](https://discourse.pymc.io/u/amanda.azevedo)\
**Post date:** [May 11, 2022, 9:05am UTC](https://discourse.pymc.io/t/smc-abc-in-pymc-v4/9347/7 "2022-05-11T09:05:42Z")

</div>

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).
