SymPy makes REPL to stuck

When I tried the following in REPL, it gets stuck when I types the last line. I cannot keep typing. The command top shows that Julia is using all the CPU. Any suggestion on how to trouble shoot the problem?

I thought it might be due to the fact that I am using kitty terminal emulator. However, other terminal emulators have the same issue.

Also, it seems that running SymPy.jl code as a script does not have this issue.

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.2 (2024-12-01)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using SymPy

julia> @syms n
(n,)

julia> ex = 1/(n*(n+3))
    1    
─────────
nβ‹…(n + 3)

julia> sympy.apart(e
1 Like

Installed SymPy to check, happens to me too. The middle lines weren’t needed, anything typed after just using SymPy and sympy.apart( freezes the REPL. Windows Task Manager doesn’t say Julia is using all the CPU though. I have no earthly idea why writing a partial function call would freeze on a non-space character, and I’m very curious. Other properties freeze upon the parentheses too:

julia> sympy.apart
Callable SymPy method

julia> sympy.sin
Callable SymPy method

julia> sympy.cos( a

In any case, SymPy.apart or just apart (because it’s exported) works as documented:

julia> using SymPy

julia> @syms n
(n,)

julia> ex = 1/(n*(n+3))
    1
─────────
nβ‹…(n + 3)

julia> apart(ex)
      1        1
- ───────── + ───
  3β‹…(n + 3)   3β‹…n

To use properties of sympy, I could work around the freezing by assigning the property access to another variable, then doing the call separately:

julia> a = sympy.apart; a(ex) # note: different object from SymPy.apart
      1        1
- ───────── + ───
  3β‹…(n + 3)   3β‹…n

julia> let b = sympy.apart; b(ex) end # local variable works too, preferred
      1        1
- ───────── + ───
  3β‹…(n + 3)   3β‹…n

or avoiding function call syntax via the 1-argument piping operator:

julia> ex |> sympy.apart
      1        1
- ───────── + ───
  3β‹…(n + 3)   3β‹…n

or writing it in a string to be parsed and evaluated (@eval call or quoted expressions freeze):

julia> eval(Meta.parse("sympy.apart(ex)"))
      1        1
- ───────── + ───
  3β‹…(n + 3)   3β‹…n

Hopefully someone knows why the REPL would freak out at these particular calls in source or quoted expressions after SymPy is imported.

1 Like

My guess is that it’s the the REPL autocomplete code that is trying to obtain possible completions from the sympy object that is causing the issue. Can the autocomplete be turned off somehow?

1 Like

You could also try Julia 1.10 …

1 Like

Yes. Julia 1.10 does not have this issue.

Possibly related: REPL hints and tab completion freezes the REPL Β· Issue #55434 Β· JuliaLang/julia Β· GitHub

1 Like

Confirmed related, disabling the v1.11 REPL hinting in one of the ways that issue linked makes this go away for me, and re-enabling the hinting brings back the freeze. Before it did, using the up-arrow to find and rerun the line worked fine.

julia> Base.active_repl.options.hint_tab_completes = false
false

julia> sympy.apart(ex)
      1        1
- ───────── + ───
  3β‹…(n + 3)   3β‹…n

julia> Base.active_repl.options.hint_tab_completes = true
true

julia> sympy.apart(ex) # up-arrow to previous line
      1        1
- ───────── + ───
  3β‹…(n + 3)   3β‹…n

julia> sympy.apart(e

I’m surprised that hinting does type inference for an incomplete call, I thought it would only need to search the scopes for names. This also doesn’t explain why the a = sympy.apart; a(ex) workaround worked; does REPL hinting just not bother inferring a(e there? Whatever it does, I’d definitely want it to give up right after I type another character, on a single thread too.

2 Likes

I have added this to ~/.julia/confg/startup.jl

atreplinit() do repl
    # Turn off hint in Julia 1.11 to deal with SymPy problem
    Base.active_repl.options.hint_tab_completes = false
end
1 Like