huggingface / huggingface/Math-Verify

[bug] some inputs to parse lead to pickling errors due to latex2sympy2_extended

Open
#77 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.2k
Forks
60
PR merge metrics
No merged PRs in 30d

Description

Thanks for the very useful library :)

This bug came up when trying to run `math_verify.parse` in separate processes, which lead to the following error:

```bash
"/usr/local/lib/python3.12/concurrent/futures/process.py", line 432, in wait_result_broken_or_wakeup
result_item = result_reader.recv()
"/usr/local/lib/python3.12/multiprocessing/connection.py", line 251, in recv
return _ForkingPickler.loads(buf.getbuffer())
"/lib/python3.12/site-packages/latex2sympy2_extended/logic.py", line 11, in __new__
obj._unsorted_args = args
AttributeError: 'Equality' object has no attribute '_unsorted_args'
```

After a bunch of digging and testing I think the issue is due to the `latex2sympy2_extended` parser creating relational args with `evaluate=False`, but sympy's `__getnewargs__` doesn't preserve that kwarg so during unpickling, numeric comparisons re-evaluate to True, `LatticeOp` filters them as identity elements, and `And.__new__` returns a non-And type that crashes on `_unsorted_args` assignment.

I encountered this in `latex2sympy2_extended 1.11.0` with `sympy 1.14.0`

I was able to reproduce the errors with:

```python
import pickle

import math_verify

FAILING_INPUTS = [
r'\boxed{0 < 1 < x}',
r'\boxed{1 = 1 = x}',
r'\boxed{x > 3 > 1}',
]

for pred in FAILING_INPUTS:
parsed = math_verify.parse(pred)
data = pickle.dumps(parsed)
pickle.loads(data)
```

I am not deeply familar with the exact working of `latex2sympy2` or `sympy` so definitely treat this as a best guess.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.