Hitting a weird error to do with RNGs in Scan in a custom function inside a Potential

I dug into the UserWarning: RNG Variable RandomGeneratorSharedVariable(<Generator(PCG64) at 0x14942FBC0>) has multiple clients. This is likely an inconsistent random graph.

Indeed here in collect_default_updates each one of the 2 RNGs was linked to the same y_c RV in my model - I think as a result of passing the y_c into my get_log_jcd_scan()

Now that I’ve figured out the scan issues, I tried mdl.replace_rvs_by_values, and lo and behold - it seems to work!

y_c_vals = mdl.replace_rvs_by_values([y_c])[0]
_ = pm.Potential('pot_jcd_y_c_on_y', get_log_jcd_scan(y_c_vals, y), dims='oid')

I think I’ll treat this thread as closed, since I changed several things and finally somehow arrived at a model that includes the log_jcd and samples without complaint! I’m going to carefully extend it through the full workflow and watch for issues…

Thanks guys for all your help! I may try to add an example notebook one day with my learnings - once I more fully understand things :slight_smile:

1 Like