UM-Bridge / umbridge

UM-Bridge (the UQ and Model Bridge) provides a unified interface for numerical models that is accessible from virtually any programming language or framework.
https://um-bridge-benchmarks.readthedocs.io/en/docs/
MIT License
32 stars 15 forks source link

pymc version #13

Closed krosenfeld-IDM closed 1 year ago

krosenfeld-IDM commented 1 year ago

Hello,

I was attempting to run the example pymc client and am getting an error related to the TensorType in UmbridgeOp. First I run the benchmark:

docker run -it -p 4243:4243 linusseelinger/behmark-analytic-gaussian-mixture

and then the client:

(/home/krosenfeld/projects/umbridge_test/env) [krosenfeld@internal.idm.ctr@ipapvwks25 umbridge_test]$ python pymc-client.py http://localhost:4243
Connecting to host URL http://localhost:4243
Model output: [-48.17723351]
Check model's gradient against numerical gradient. This requires an UM-Bridge model with gradient support.
Traceback (most recent call last):
  File "pymc-client.py", line 39, in <module>
    map_estimate = pm.find_MAP()
  File "/home/krosenfeld/projects/umbridge_test/env/lib/python3.8/site-packages/pymc/tuning/starting.py", line 125, in find_MAP
    model.check_start_vals(start)
  File "/home/krosenfeld/projects/umbridge_test/env/lib/python3.8/site-packages/pymc/model.py", line 1776, in check_start_vals
    initial_eval = self.point_logps(point=elem)
  File "/home/krosenfeld/projects/umbridge_test/env/lib/python3.8/site-packages/pymc/model.py", line 1805, in point_logps
    factor_logps_fn = [at.sum(factor) for factor in self.logp(factors, sum=False)]
  File "/home/krosenfeld/projects/umbridge_test/env/lib/python3.8/site-packages/pymc/model.py", line 759, in logp
    rv_logps = joint_logp(
  File "/home/krosenfeld/projects/umbridge_test/env/lib/python3.8/site-packages/pymc/logprob/joint_logprob.py", line 293, in joint_logp
    temp_logp_terms = factorized_joint_logprob(
  File "/home/krosenfeld/projects/umbridge_test/env/lib/python3.8/site-packages/pymc/logprob/joint_logprob.py", line 211, in factorized_joint_logprob
    q_logprob_vars = _logprob(
  File "/home/krosenfeld/projects/umbridge_test/env/lib/python3.8/functools.py", line 875, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "/home/krosenfeld/projects/umbridge_test/env/lib/python3.8/site-packages/pymc/distributions/distribution.py", line 568, in custom_dist_logp
    return logp(values[0], *dist_params)
  File "/home/krosenfeld/projects/umbridge_test/env/lib/python3.8/site-packages/aesara/graph/op.py", line 297, in __call__
    node = self.make_node(*inputs, **kwargs)
  File "/home/krosenfeld/projects/umbridge_test/env/lib/python3.8/site-packages/aesara/graph/op.py", line 241, in make_node
    raise TypeError(
TypeError: Invalid input types for Op UmbridgeOp:
Input 1/1: Expected TensorType(float64, (?,)), got TensorType(float64, (2,))

I believe this is related to the version of pymc I have. I had installed umbridge following the directions on the docs:

pip install umbridge[pymc]

This did not install pymc itself so I then installed pymc:

mamba install pymc

which results in pymc 5.2.0.

If I revert to an old version of pymc:

mamba install pymc=4.0.0

The example runs:

(/home/krosenfeld/projects/umbridge_test/env) [krosenfeld@internal.idm.ctr@ipapvwks25 umbridge_test]$ python pymc-client.py http://localhost:4243
Connecting to host URL http://localhost:4243
Model output: [-48.17723351]
Check model's gradient against numerical gradient. This requires an UM-Bridge model with gradient support.
 |█████████████████████████████████████████████████████████████████████████████████████████| 100.00% [8/8 00:00<00:00 logp = -3.7296, ||grad|| = 0.025167]MAP estimate of posterior is [-1.99936594  1.99936594]
Only 400 samples in chain.
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Sequential sampling (2 chains in 1 job)
NUTS: [posterior]
Sampling 2 chains for 100 tune and 400 draw iterations (200 + 800 draws total) took 49 seconds.0.00% [500/500 00:24<00:00 Sampling chain 1, 0 divergences]
The acceptance probability does not match the target. It is 0.8838, but should be close to 0.8. Try to increase the number of tuning steps.

I am using python 3.8.16 on RHEL 8.6

linusseelinger commented 1 year ago

Thanks for reporting @krosenfeld-IDM ! It turned out pymc has (again...) changed its backend to a fork. Was enough to switch the UM-Bridge op from aesara to pytensor. Should work now if you install the umbridge Python package directly from current master via pip install . in the umbridge sources. Will push to pypi soon as well.

Let me know if there are any issues left! :)