stan icon indicating copy to clipboard operation
stan copied to clipboard

Add exit() to the language

Open syclik opened this issue 9 years ago • 2 comments

Summary:

Add an exit() function to the language.

We could also call it error(), fatal(), or fatal_error().

Description:

Currently, we have reject() in the Stan language. Using reject() rejects the current iteration.

We should have matching exit() calls in the Stan language. Using exit() should stop algorithms from continuing. This will indicate that there is something wrong and shouldn't be ignored. As opposed to reject() which will continue onto the next iteration.

  • [ ] Decide on what to throw in the C++ when exit() is used
  • [ ] If necessary, add a function to call to the math library.
  • [ ] Add exit(...) to the language to match the function signatures of reject().
  • [ ] Update manual with description of behavior of reject() and exit().
  • [ ] Update algorithms to exit with exit() call.

Reproducible Steps:

Here's an example:

parameters {
  real<lower = 0, upper = 1> theta;
}
model {
  exit();
}

Current Output:

Currently, this will show that the 100 tries for initialization failed.

Expected Output:

Exit the algorithm.

Current Version:

v2.11.0

syclik avatar Aug 22 '16 15:08 syclik

I think action is on me to come up with possible exceptions to throw.

syclik avatar Aug 22 '16 15:08 syclik

I would suggest using std::system_error (introduced in C++11). http://www.cplusplus.com/reference/system_error/system_error/

It takes a string and an error code. With pull request #2307, this should pass through and stop the samplers.

syclik avatar May 09 '17 21:05 syclik