probsys / sppl

Probabilistic programming system for fast and exact symbolic inference
Apache License 2.0
76 stars 10 forks source link

SPPL compiler replaces `==` and `in` with `<<` incorrectly at times #125

Open fsaad opened 2 years ago

fsaad commented 2 years ago

MWE

>>> source = """
i = 0.5
Y ~= bernoulli(p=0 if i == 0.5 else 1)
"""
>>> compiler = SPPL_Compiler(source)
>>> namespace = compiler.execute_module()
TypeError: unsupported operand type(s) for <<: 'float' and 'set'

The reason is that the generated Python is

# MODEL DEFINITION
command = Sequence(
    Sample(Y, bernoulli(p=(0 if (i << {0.5}) else 1))),
)

The offending line is here: https://github.com/probcomp/sppl/blob/8b0fe0c37ed15dd19936d13e0fa652c3b5237cac/src/compilers/sppl_to_python.py#L145