TimeSliceCrossValidator breaks when passing rng in sampler

Pymc marketing version used: 0.18.0

In the cross validation 0.18.0 guide rng is set to rng: np.random.Generator = np.random.default_rng(seed=seed).

cv is then run with

results = cv.run(
    X,
    y,
    # You can also pass sampler_config here to speed things up
    sampler_config={
        "tune": 1_000,
        "draws": 1_000,
        "chains": 4,
        "random_seed": seed,
        "target_accept": 0.90,
        "nuts_sampler": "numpyro",
    },
    yaml_path=data_dir / "config_files" / "multi_dimensional_example_model.yml",
)

if instead of a yml file an mmm build_model object is passed error TypeError: Object of type Generator is not JSON serializable is returned.

Hey! Thanks for reporting! Does it work for you if you use “random_seed”: 42 (or any number)?

It does seem to work when passing an int. Is this intentional? Other instances of random_seed that I could find uses the rng except this one, and I couldn’t find any documentation saying that rng was not supported here.

No, it’s a bug. Still, the integer seed will work for now. I will try to fix it soon.

@fountainpen ~~I found the error and pushed a fix https://github.com/pymc-labs/pymc-marketing/pull/2308~~

I am checking the expected behaviour with other devs.

This will be available in the next patch release :slight_smile:

ok! merged :tada: !

1 Like