Skip to content

"TypeError: cannot pickle 'fortran' object" for sampling with multiple cores #5864

@mathtimm

Description

@mathtimm

I am getting a TypeError when I try to sample with multiple cores, the issue does not appear if cores=1.
I am working on the modeling of exoplanet transits using the code exoplanet that makes use of PyMC3.

Complete error traceback
`---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [10], in <cell line: 3>()
      1 np.random.seed(42)
      3 with model:
----> 4     trace = pm.sample(
      5         tune=3000,
      6         draws=4000,
      7         start=opt,
      8         cores=3,
      9         chains=2,
     10         init="adapt_full",
     11         target_accept=0.9,
     12         return_inferencedata=True
     13     )

File /opt/homebrew/Caskroom/miniforge/base/envs/prose-env3/lib/python3.9/site-packages/pymc3/sampling.py:559, in sample(draws, step, init, n_init, start, trace, chain_idx, chains, cores, tune, progressbar, model, random_seed, discard_tuned_samples, compute_convergence_checks, callback, jitter_max_retries, return_inferencedata, idata_kwargs, mp_ctx, pickle_backend, **kwargs)
    557 _print_step_hierarchy(step)
    558 try:
--> 559     trace = _mp_sample(**sample_args, **parallel_args)
    560 except pickle.PickleError:
    561     _log.warning("Could not pickle model, sampling singlethreaded.")

File /opt/homebrew/Caskroom/miniforge/base/envs/prose-env3/lib/python3.9/site-packages/pymc3/sampling.py:1461, in _mp_sample(draws, tune, step, chains, cores, chain, random_seed, start, progressbar, trace, model, callback, discard_tuned_samples, mp_ctx, pickle_backend, **kwargs)
   1458         strace.setup(draws + tune, idx + chain)
   1459     traces.append(strace)
-> 1461 sampler = ps.ParallelSampler(
   1462     draws,
   1463     tune,
   1464     chains,
   1465     cores,
   1466     random_seed,
   1467     start,
   1468     step,
   1469     chain,
   1470     progressbar,
   1471     mp_ctx=mp_ctx,
   1472     pickle_backend=pickle_backend,
   1473 )
   1474 try:
   1475     try:

File /opt/homebrew/Caskroom/miniforge/base/envs/prose-env3/lib/python3.9/site-packages/pymc3/parallel_sampling.py:423, in ParallelSampler.__init__(self, draws, tune, chains, cores, seeds, start_points, step_method, start_chain_num, progressbar, mp_ctx, pickle_backend)
    421 if mp_ctx.get_start_method() != "fork":
    422     if pickle_backend == "pickle":
--> 423         step_method_pickled = pickle.dumps(step_method, protocol=-1)
    424     elif pickle_backend == "dill":
    425         try:

TypeError: cannot pickle 'fortran' object`
Could this be a version issue ? I am having trouble finding the right combination of pymc3, pymc3-ext and exoplanet.

Thanks a lot in advance !

Versions and main components

  • PyMC3 Version: 3.11.4
  • pymc3-ext Version: 0.1.1
  • aesara-theano-fallback Version: 0.1.0
  • theano-pymc Version: 1.1.2
  • exoplanet Version: 0.5.2
  • Python Version: 3.9.13
  • Operating system: MacOS Monterey (12.2.1), M1 chip
  • How did you install PyMC3: pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions