ReactiveMP.jl icon indicating copy to clipboard operation
ReactiveMP.jl copied to clipboard

Expand `RuleMethodError` with list of defined rules for given node

Open wmkouw opened this issue 9 months ago • 0 comments

Currently, when a node is connected to an edge which has a distribution that does not match any of the input argument types for the defined message rules, ReactiveMP will throw a RuleMethodError. For example, the model

@model function test(y)
   r ~ Gamma(1.,1.)
   x ~ Bernoulli(r)
   y ~ Beta(x,1.)
end
infer(model = test(), data = (y = 1.0,))

will throw:

ERROR: RuleMethodError: no method matching rule for the given arguments

Possible fix, define:

@rule Beta(:a, Marginalisation) (q_out::PointMass, q_b::PointMass, ) = begin 
    return ...
end

For new users, this error is difficult to read, interpret and overcome, especially if the user is also new to Julia and is unfamiliar with interpreting stack traces. I propose that we output the list of rules that are defined, for example:

Rules defined for Bernouilli(x|r)
-> r ~ PointMass(..)
-> r ~ Beta(..)

This may help the user specify a model for which inference can be executed successfully.

@bartvanerp already compiled a list in ReactiveMP's documentation: https://reactivebayes.github.io/ReactiveMP.jl/stable/lib/rules/#lib-rules-table. This will save a lot of time; we just need to alter the RuleMethodError code in rule.jl such that it performs a look-up and prints in a user-friendly way.

Suggestions during today's RxInfer meeting mentioned a hierarchical printout. I will look into this.

wmkouw avatar May 01 '24 14:05 wmkouw