Skip to content

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

@jonathon-reflect

Description

@jonathon-reflect

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:

"/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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions