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

descriptive error messages for incomplete probability library calls #987

Closed
bob-carpenter opened this issue Oct 1, 2021 · 7 comments · Fixed by #1021
Closed

descriptive error messages for incomplete probability library calls #987

bob-carpenter opened this issue Oct 1, 2021 · 7 comments · Fixed by #1021
Labels

Comments

@bob-carpenter
Copy link
Contributor

Description

Our probability-distribution functions come in familes, e.g., normal_X(), where X can be any of
lpdf, lupdf, cdf, lcdf, lccdf, rng. But not all probability distributions implement each expected probability function. When a user calls foo_X for a probability distribution foo that exists, but foo_X doesn't exist, we should have a more specific message informing them of that so they don't think they've made a typo or waste time looking in the doc.

Motivation

Quoted from @betanalpha's comment stan-dev/design-docs#42 (comment):

Most of the probability libraries in R, Python, Mathematica, etc have a pretty uniform coverage of the exposed representations. One you know the name of a family of distributions you know how to call the corresponding density, CDF, quantile function, rng, etc. At the point the coverage in Stan is pretty uniform, but it’s becoming less and less uniform as more obscure families are added without all of the functionality. If a user is assuming that everything will be uniformly available but gets an error message then can become frustrating assuming that there’s a spelling error or other typo somewhere and not just a non-implemented functionality.

It would be great to add functionality to the compiler to fill in these gaps so that if a user calls for some functionality that has not yet been implemented then they get a precise error message noting that gap and not the default error message noting the the function being requested just doesn’t exist.

@WardBrian
Copy link
Member

Is the idea that these enhanced error messages occur for any X when foo_X is requested, or only when X is one of the existing kinds (rng, lpdf, etc)?

Phrased another way, would "normal_weird" warn me that the normal family doesn't support "_weird", or would it just give the current warning about unknown identifier? I think this ends up determining what information we'd need to store to produce these

@nhuurre
Copy link
Collaborator

nhuurre commented Oct 1, 2021

No reason to speculate about unknown suffixes.
All we need is that mk_declarative_sig should record the missing names somewhere. (that includes _lpmf for continuous distributions and _lpdf for discrete ones) (but ignore UnaryVectorized)

let mk_declarative_sig (fnkinds, name, args, mem_pattern) =
let sfxes = function
| Lpmf -> ["_lpmf"; "_log"]
| Lpdf -> ["_lpdf"; "_log"]
| Rng -> ["_rng"]
| Cdf -> ["_cdf"; "_cdf_log"; "_lcdf"]
| Ccdf -> ["_ccdf_log"; "_lccdf"]
| UnaryVectorized -> [""]
in

@WardBrian
Copy link
Member

I'm not even sure if we'd need that, would

  1. Does this function exist (which we do right now)
  2. If not, does it have one of the special suffixes
  3. If so, report this new error, else report the current error

work?

@nhuurre
Copy link
Collaborator

nhuurre commented Oct 1, 2021

I think it makes sense to distinguish between a totally unknown distribution and "this distribution family is known but the specific suffix is not supported" but it depends on the exact phrasing of the new error message.

@WardBrian
Copy link
Member

That's probably better. We just need a list of known families and a list of known suffixes at that point. I don't think we need to explicitly construct the matrix of which suffixes are available for which families however, given those two lists and our existing list of available functions we can very quickly determine whether or not we are in this situation.

roughly

if (is_undefined ident) then
  if (is_known_family (remove_suffix ident)) && (is_known_suffix (get_suffix ident)) then
    (*special error*)
  else
    (* current error *)

I'll have to look but I know we already have a lot of utilities for getting or removing the suffixes in the code

@nhuurre
Copy link
Collaborator

nhuurre commented Oct 1, 2021

I don't think we need to explicitly construct the matrix of which suffixes are available for which families

True enough. It just seems that Stan_math_signatures.ml currently prefers constructing explicit matrices. Issue #324 has been open for quite a while.

@betanalpha
Copy link

betanalpha commented Oct 1, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants