Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with examples/ode_models/ODE_Lotka_Volterra_multiple_ways.ipynb #739

Open
wd60622 opened this issue Nov 15, 2024 · 0 comments
Open

Comments

@wd60622
Copy link

wd60622 commented Nov 15, 2024

Wasn't able to get this to work:

──────────────────────────────────── Error running examples/ode_models/ODE_Lotka_Volterra_multiple_ways.ipynb ────────────────────────────────────

---------------------------------------------------------------------------
Exception encountered at "In [36]":
---------------------------------------------------------------------------
_RemoteTraceback                          Traceback (most recent call last)
_RemoteTraceback:
"""
Traceback (most recent call last):
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/compile/function/types.py", line 959, in __call__
    self.vm()
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/graph/op.py", line 524, in rval
    r = p(n, [x[0] for x in i], o)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/tensor/random/op.py", line 403, in perform
    smpl_val = self.rng_fn(rng, *([*args, size]))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/distributions/simulator.py", line 53, in rng_fn
    return cls.fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/ipykernel_8285/1052673333.py", line 4, in simulator_forward_model
    mu = odeint(func=rhs, y0=theta[-2:], t=data.year, args=(theta,))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/scipy/integrate/_odepack_py.py", line 243, in odeint
    output = _odepack.odeint(func, y0, t, args, Dfun, col_deriv, ml, mu,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Initial condition y0 must be one-dimensional.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/concurrent/futures/process.py", line 261, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/smc/sampling.py", line 303, in _sample_smc_int
    smc._initialize_kernel()
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/smc/kernels.py", line 249, in _initialize_kernel
    likelihoods =
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/smc/kernels.py", line 249, in <listcomp>
    likelihoods =
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/compile/function/types.py", line 972, in __call__
    raise_with_op(
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/link/utils.py", line 524, in raise_with_op
    raise exc_value.with_traceback(exc_trace)
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/compile/function/types.py", line 959, in __call__
    self.vm()
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/graph/op.py", line 524, in rval
    r = p(n, [x[0] for x in i], o)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pytensor/tensor/random/op.py", line 403, in perform
    smpl_val = self.rng_fn(rng, *([*args, size]))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/distributions/simulator.py", line 53, in rng_fn
    return cls.fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/ipykernel_8285/1052673333.py", line 4, in simulator_forward_model
    mu = odeint(func=rhs, y0=theta[-2:], t=data.year, args=(theta,))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/scipy/integrate/_odepack_py.py", line 243, in odeint
    output = _odepack.odeint(func, y0, t, args, Dfun, col_deriv, ml, mu,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Initial condition y0 must be one-dimensional.
Apply node that caused the error: Simulator_Y_obs_rv{"(),(),(),(),(),(),()->()"}(simulator_rng, [21  2], Exp.0, Exp.0, Exp.0, Exp.0, Exp.0, Exp.0,
Exp.0)
Toposort index: 28
Inputs types: [RandomGeneratorType, TensorType(int64, shape=(2,)), TensorType(float64, shape=(1, 1)), TensorType(float64, shape=(1, 1)),
TensorType(float64, shape=(1, 1)), TensorType(float64, shape=(1, 1)), TensorType(float64, shape=(1, 1)), TensorType(float64, shape=(1, 1)),
TensorType(float64, shape=(1, 1))]
Inputs shapes: ['No shapes', (2,), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1)]
Inputs strides: ['No strides', (8,), (8, 8), (8, 8), (8, 8), (8, 8), (8, 8), (8, 8), (8, 8)]
Inputs values: [Generator(PCG64) at 0x7F05A7926340, array([21,  2]), array([[0.48120495]]), array([[0.02483187]]), array([[0.92600529]]),
array([[0.02753258]]), array([[34.91413614]]), array([[3.86199914]]), array([[7.58273893]])]
Outputs clients: [[output[1](Simulator_Y_obs_rv{"(),(),(),(),(),(),()->()"}.0)], [Composite{sqr((i0 - i1))}(Y_obs{[[30.   4. ... 4.7  8.6]]},
Simulator_Y_obs_rv{"(),(),(),(),(),(),()->()"}.out)]]

Backtrace when the node is created (use PyTensor flag traceback__limit=N to make it longer):
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/concurrent/futures/process.py", line 261, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/smc/sampling.py", line 303, in _sample_smc_int
    smc._initialize_kernel()
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/smc/kernels.py", line 244, in _initialize_kernel
    self.likelihood_logp_func = _logp_forw(
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/smc/kernels.py", line 636, in _logp_forw
    out_list, inarray0 = join_nonshared_inputs(
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/pytensorf.py", line 619, in join_nonshared_inputs
    new_outputs = [
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/pytensorf.py", line 620, in <listcomp>
    pytensor.clone_replace(output, replace, rebuild_strict=False) for output in outputs

HINT: Use the PyTensor flag `exception_verbosity=high` for a debug print-out and storage map footprint of this Apply node.
"""

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
Cell In[36], line 4
      2 draws = 2000
      3 with model:
----> 4     trace_SMC_e1 = pm.sample_smc(draws=draws, progressbar=False)
      5 trace = trace_SMC_e1
      6 az.summary(trace)

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/smc/sampling.py:180, in sample_smc(draws, kernel, start, model,
random_seed, chains, cores, compute_convergence_checks, return_inferencedata, idata_kwargs, progressbar, **kernel_kwargs)
    171 params = (
    172     draws,
    173     kernel,
    174     start,
    175     model,
    176 )
    178 t1 = time.time()
--> 180 results = run_chains(chains, progressbar, params, random_seed, kernel_kwargs, cores)
    182 (
    183     traces,
    184     sample_stats,
    185     sample_settings,
    186 ) = zip(*results)
    188 trace = MultiTrace(traces)

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/smc/sampling.py:385, in run_chains(chains, progressbar, params,
random_seed, kernel_kwargs, cores)
    378                 # update the progress bar for this task:
    379                 progress.update(
    380                     status=f"Stage: {stage} Beta: {beta:.3f}",
    381                     task_id=task_id,
    382                     refresh=True,
    383                 )
--> 385 return tuple(cloudpickle.loads(r.result()) for r in done)

File ~/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/smc/sampling.py:385, in <genexpr>(.0)
    378                 # update the progress bar for this task:
    379                 progress.update(
    380                     status=f"Stage: {stage} Beta: {beta:.3f}",
    381                     task_id=task_id,
    382                     refresh=True,
    383                 )
--> 385 return tuple(cloudpickle.loads(r.result()) for r in done)

File ~/micromamba/envs/pymc-examples/lib/python3.11/concurrent/futures/_base.py:449, in Future.result(self, timeout)
    447     raise CancelledError()
    448 elif self._state == FINISHED:
--> 449     return self.__get_result()
    451 self._condition.wait(timeout)
    453 if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:

File ~/micromamba/envs/pymc-examples/lib/python3.11/concurrent/futures/_base.py:401, in Future.__get_result(self)
    399 if self._exception:
    400     try:
--> 401         raise self._exception
    402     finally:
    403         # Break a reference cycle with the exception in self._exception
    404         self = None

ValueError: Initial condition y0 must be one-dimensional.
Apply node that caused the error: Simulator_Y_obs_rv{"(),(),(),(),(),(),()->()"}(simulator_rng, [21  2], Exp.0, Exp.0, Exp.0, Exp.0, Exp.0, Exp.0,
Exp.0)
Toposort index: 28
Inputs types: [RandomGeneratorType, TensorType(int64, shape=(2,)), TensorType(float64, shape=(1, 1)), TensorType(float64, shape=(1, 1)),
TensorType(float64, shape=(1, 1)), TensorType(float64, shape=(1, 1)), TensorType(float64, shape=(1, 1)), TensorType(float64, shape=(1, 1)),
TensorType(float64, shape=(1, 1))]
Inputs shapes: ['No shapes', (2,), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1)]
Inputs strides: ['No strides', (8,), (8, 8), (8, 8), (8, 8), (8, 8), (8, 8), (8, 8), (8, 8)]
Inputs values: [Generator(PCG64) at 0x7F05A7926340, array([21,  2]), array([[0.48120495]]), array([[0.02483187]]), array([[0.92600529]]),
array([[0.02753258]]), array([[34.91413614]]), array([[3.86199914]]), array([[7.58273893]])]
Outputs clients: [[output[1](Simulator_Y_obs_rv{"(),(),(),(),(),(),()->()"}.0)], [Composite{sqr((i0 - i1))}(Y_obs{[[30.   4. ... 4.7  8.6]]},
Simulator_Y_obs_rv{"(),(),(),(),(),(),()->()"}.out)]]

Backtrace when the node is created (use PyTensor flag traceback__limit=N to make it longer):
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/concurrent/futures/process.py", line 261, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/smc/sampling.py", line 303, in _sample_smc_int
    smc._initialize_kernel()
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/smc/kernels.py", line 244, in _initialize_kernel
    self.likelihood_logp_func = _logp_forw(
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/smc/kernels.py", line 636, in _logp_forw
    out_list, inarray0 = join_nonshared_inputs(
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/pytensorf.py", line 619, in join_nonshared_inputs
    new_outputs = [
  File "/home/wdean/micromamba/envs/pymc-examples/lib/python3.11/site-packages/pymc/pytensorf.py", line 620, in <listcomp>
    pytensor.clone_replace(output, replace, rebuild_strict=False) for output in outputs

HINT: Use the PyTensor flag `exception_verbosity=high` for a debug print-out and storage map footprint of this Apply node.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant