Skip to content

Sympy throws on returning a tuple out of diophantine call #561

@DanielFabian

Description

@DanielFabian

I respect that most bugs are in SymPyCore, but this one looks like a serialization / type error, so maybe it belongs here (happy to move if you think no).

When I tried following a sympy tutorial, I consistently get a type error. Here's the python snippet

from sympy import symbols
from sympy.solvers.diophantine import diophantine
x, y, z = symbols("x, y, z", integer=True)
print(diophantine(x**2 + y**2 - z**2))

and this is my translation to julia:

using SymPy

@syms a::integer, b::integer, c::integer
pythag_eq = Eq(a^2 + b^2, c^2)

typeof(pythag_eq)

sympy.solvers.diophantine(pythag_eq)

And I get this error:

I'm trying to learn how to translate python examples to julia. In particulae, I have a little bit of python code:

```python
from sympy import symbols
from sympy.solvers.diophantine import diophantine
x, y, z = symbols("x, y, z", integer=True)
print(diophantine(2*x + 3*y - 5))

and I'm trying to translate it to julia as this:

using SymPy

@syms a::integer, b::integer, c::integer
pythag_eq = Eq(a^2 + b^2, c^2)

typeof(pythag_eq)

sympy.solvers.diophantine(pythag_eq)

and I'm getting crashes at the last call:

ERROR: MethodError: Cannot `convert` an object of type 
  Tuple{PyCall.PyObject, PyCall.PyObject, PyCall.PyObject} to an object of type 
  Sym
The function `convert` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  Sym(::Tuple)
   @ SymPyCore ~/.julia/packages/SymPyCore/Dg45i/src/types.jl:38
  Sym(::T) where T
   @ SymPyCore ~/.julia/packages/SymPyCore/Dg45i/src/types.jl:30
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:126
  ...

Stacktrace:
 [1] push!(a::Vector{Sym}, item::Tuple{PyCall.PyObject, PyCall.PyObject, PyCall.PyObject})
   @ Base ./array.jl:1260
 [2] collect(::Type{Sym}, o::PyCall.PyObject)
   @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyiterator.jl:93
 [3] ↑(::Type{PyCall.PyObject}, x::PyCall.PyObject)
   @ SymPy ~/.julia/packages/SymPy/qBv8D/src/python_connection.jl:52
 [4] ↑(x::PyCall.PyObject)
   @ SymPyCore ~/.julia/packages/SymPyCore/Dg45i/src/gen_methods.jl:191
 [5] (::SymPyCore.SymbolicCallable{PyCall.PyObject})(::Sym{PyCall.PyObject}, ::Vararg{Sym{…}}; kwargs::@Kwargs{})

I have verified that `diophantine` is found as a python callable object. It looks more like an interop issue. But I have no idea what.

I have verified that diophantine is found as a python callable object. It looks more like an interop issue. But I have no idea what.

I even asked on the julia discord and someone else looked at the issue too:

https://discord.com/channels/762167454973296644/1341536826501890198

and when they added a type conversion like this:

Base.convert(::Type{Sym}, pos::NTuple{N, SymPy.PyCall.PyObject}) where N = Sym(Ref(pos));

we do indeed see a result, which is why they recommended to file an upstream bug. Apparently the result from the diophantine call throws every time (fairly independent of the input).

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