Did SymPy change the syntax?

i have this function where i’m using PyCall and SymPy:

using SymPy
using PyCall
function op_mat(op)
    op = op[:as_poly](domain="C")    # return the input as a polynom
    op_a = op.x[:gens]        # give us the generators of the polynom for example x and y
    nab = op[:length]()
    op_ab = ones(SymPy.Sym, nab)
    coef = zeros(Complex, nab)
    mat = zeros(Int64, length(op_a), nab)
    for (i, (ps, c)) in enumerate(op[:as_dict]())
        for (j, p) in enumerate(ps)
            mat[j, i] = p
            op_ab[i] = op_a[j]^p * op_ab[i]
        coef[i] = c
    return op_a, op_ab, mat, coef

but everytime i call this function op_mat(x+y)of course with x=symbols("x") ; y=symbols("y") i get this error:

ERROR: MethodError: no method matching getindex(::Sym, ::Symbol)
Closest candidates are:
  getindex(::Sym, ::Sym...) at /Users/midow/.julia/packages/SymPy/1Cwgd/src/utils.jl:18
  getindex(::Number) at number.jl:75
  getindex(::Number, ::Integer) at number.jl:77
 [1] op_mat(::Sym) at /Users/midow/.julia/packages/QuantumRelay/pjKWG/src/operateurs.jl:70
 [2] top-level scope at REPL[7]:1 

i don’t k,ow if a problem of syntax or not

You need to use op.as_poly instead of op[:as_poly]. Same for op.x[:gens], op[:length], etc.

1 Like