probsys / sppl

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

Investigate sympy.Intersection error on Interval and Range with floats #80

Closed fsaad closed 4 years ago

fsaad commented 4 years ago

When running spn.prob(GPA <= 0.0) on Indian GPA, error is encountered at this line https://github.com/probcomp/sum-product-dsl/blob/aafed1006b8f28708290911dbf946765139dd495/src/spn.py#L961

Note the use of 0.0 instead of 0 in the conditioning event.

It appears to be an error from Sympy.

>>> sympy.Intersection(sympy.Range(10,11,1), sympy.Interval(-sympy.oo, 0.0))
Traceback (most recent call last):
  File "/home/fsaad/sum-product-dsl/.venv/lib/python3.6/site-packages/sympy/core/compatibility.py", line 410, in as_int
    raise TypeError
TypeError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/fsaad/sum-product-dsl/.venv/lib/python3.6/site-packages/sympy/sets/fancysets.py", line 426, in __new__
    for w in (start, stop, step)]
  File "/home/fsaad/sum-product-dsl/.venv/lib/python3.6/site-packages/sympy/sets/fancysets.py", line 426, in <listcomp>
    for w in (start, stop, step)]
  File "/home/fsaad/sum-product-dsl/.venv/lib/python3.6/site-packages/sympy/core/compatibility.py", line 416, in as_int
    raise ValueError('%s is not an integer' % (n,))
ValueError: 1.00000000000000 is not an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/fsaad/sum-product-dsl/.venv/lib/python3.6/site-packages/sympy/sets/sets.py", line 1213, in __new__
    return simplify_intersection(args)
  File "/home/fsaad/sum-product-dsl/.venv/lib/python3.6/site-packages/sympy/sets/sets.py", line 1966, in simplify_intersection
    new_set = intersection_sets(s, t)
  File "/home/fsaad/sum-product-dsl/.venv/lib/python3.6/site-packages/sympy/multipledispatch/dispatcher.py", line 198, in __call__
    return func(*args, **kwargs)
  File "/home/fsaad/sum-product-dsl/.venv/lib/python3.6/site-packages/sympy/sets/handlers/intersection.py", line 104, in intersection_sets
    return intersection_sets(a, Range(start, end + 1))
  File "/home/fsaad/sum-product-dsl/.venv/lib/python3.6/site-packages/sympy/sets/fancysets.py", line 431, in __new__
    [0, 1/10, 1/5].'''))
ValueError: 
Finite arguments to Range must be integers; `imageset` can define
other cases, e.g. use `imageset(i, i/10, Range(3))` to give [0, 1/10,
1/5].
fsaad commented 4 years ago

https://github.com/sympy/sympy/issues/18421

Fixed in sympy 1.6, consider upgrading?