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

Unhandled "Exception initializing step size." #308

Closed
Gibbsdavidl opened this issue Jun 1, 2021 · 5 comments
Closed

Unhandled "Exception initializing step size." #308

Gibbsdavidl opened this issue Jun 1, 2021 · 5 comments

Comments

@Gibbsdavidl
Copy link

Describe the bug

Describe your system

Steps/Code to Reproduce

m5_1_priors =  '''
data {
  int N;
}

generated quantities {
  // Parameters
  real<lower=0> phi;
  real<lower=0> sigma_0;

  // Data
  real ell[N];
  phi = lognormal_rng(3.0, 0.75);
  sigma_0 = gamma_rng(2.0, 10.0);

  for (i in 1:N) {
    ell[i] = normal_rng(phi, sigma_0 * phi);
  }
}
'''

d_dict = {'N':20}

prior51 = stan.build(m5_1_priors, data=d_dict)

prior_fit_51 = prior51.sample(num_chains=4, num_samples=1000)

prior_df_51 = prior_fit_51.to_frame()

Sampling...
Messages received during sampling:
Gradient evaluation took 1e-06 seconds
1000 transitions using 10 leapfrog steps per transition would take 0.01 seconds.
Adjust your expectations accordingly!
Exception initializing step size.
Posterior is improper. Please check your model.
Gradient evaluation took 0 seconds
1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
Adjust your expectations accordingly!
Exception initializing step size.
Posterior is improper. Please check your model.
Gradient evaluation took 1e-06 seconds
1000 transitions using 10 leapfrog steps per transition would take 0.01 seconds.
Adjust your expectations accordingly!
Exception initializing step size.
Posterior is improper. Please check your model.
Gradient evaluation took 1e-06 seconds
1000 transitions using 10 leapfrog steps per transition would take 0.01 seconds.
Adjust your expectations accordingly!
Exception initializing step size.
Posterior is improper. Please check your model.
0 [>---------------------------] 1 sec
Done.


AssertionError Traceback (most recent call last)
in
----> 1 prior_fit_51 = prior51.sample(num_chains=4, num_samples=1000)
2
3 prior_df_51 = prior_fit_51.to_frame()

~/.local/lib/python3.8/site-packages/stan/model.py in sample(self, **kwargs)
66
67 """
---> 68 return self.hmc_nuts_diag_e_adapt(**kwargs)
69
70 def hmc_nuts_diag_e_adapt(self, **kwargs) -> stan.fit.Fit:

~/.local/lib/python3.8/site-packages/stan/model.py in hmc_nuts_diag_e_adapt(self, **kwargs)
86 """
87 kwargs["function"] = "stan::services::sample::hmc_nuts_diag_e_adapt"
---> 88 return self._create_fit(kwargs)
89
90 def fixed_param(self, **kwargs) -> stan.fit.Fit:

~/.local/lib/python3.8/site-packages/stan/model.py in _create_fit(self, payload)
270
271 try:
--> 272 return asyncio.run(go())
273 except KeyboardInterrupt:
274 return # type: ignore

/usr/lib/python3.8/asyncio/runners.py in run(main, debug)
41 events.set_event_loop(loop)
42 loop.set_debug(debug)
---> 43 return loop.run_until_complete(main)
44 finally:
45 try:

/usr/lib/python3.8/asyncio/base_events.py in run_until_complete(self, future)
614 raise RuntimeError('Event loop stopped before Future completed.')
615
--> 616 return future.result()
617
618 def stop(self):

~/.local/lib/python3.8/site-packages/stan/model.py in go()
252 io.error_line("\nDone.")
253
--> 254 fit = stan.fit.Fit(
255 stan_outputs,
256 num_chains,

~/.local/lib/python3.8/site-packages/stan/fit.py in init(self, stan_outputs, num_chains, param_names, constrained_param_names, dims, num_warmup, num_samples, num_thin, save_warmup)
93 self._draws[:, draw_index, chain_index] = draw_row
94 draw_index += 1
---> 95 assert draw_index == num_samples_saved
96 assert self.sample_and_sampler_param_names and self._draws.size
97 self._draws.flags["WRITEABLE"] = False

AssertionError:

@Gibbsdavidl Gibbsdavidl added the bug label Jun 1, 2021
@riddell-stan
Copy link
Contributor

Interesting! Thanks for the report.

Does this work in CmdStan?

Looks like each chain fails on "Exception initializing step size." Assuming this is what has happened, pystan needs to give useful information to the user. The current behavior is wrong.

@riddell-stan
Copy link
Contributor

Or was this intended to be run under fixed_param. Seems to work in that case.

@Gibbsdavidl
Copy link
Author

Yeah! Looks like fixed_param was the right way to go... just wasn't clear what was wrong from the message.

Maybe that would be a good docs entry: "if you're trying to do PPC, use fixed_param" ... I guess I'm still not clear on what the difference is between sample and fixed_param... also a good docs entry: "here's the difference between functions you can call on a model object".

Thanks! I guess this could probably be closed.

@riddell-stan riddell-stan changed the title prior predictive checks Unhandled "Exception initializing step size." Jun 1, 2021
@riddell-stan
Copy link
Contributor

Glad fixed_param works.

This is still certainly a bug. I changed the title to better indicate what needs to be done.

@stale
Copy link

stale bot commented Sep 3, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 3, 2021
@stale stale bot closed this as completed Sep 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants