SymbolicRegression.jl freezing my terminal when running report

Hey!

I am starting to play with SymbolicRegression.jl and I am getting some weird behavior when running the basic example (Examples · SymbolicRegression.jl)

To give some context, I am running the following code:

using SymbolicRegression
using MLJ


X = 2randn(1000, 5)
y = @. 2*cos(X[:, 4]) + X[:, 1]^2 - 2

model = SRRegressor(
    binary_operators=[+, -, *, /],
    unary_operators=[cos],
    niterations=30
)
mach = machine(model, X, y)
fit!(mach)

r = report(mach)

This is the exact same code used in the first example of the documentation.
Now, everything works fine. I get the results.

The problem is that after I run the last line (r = report(mach)), my terminal freezes and I can’t type anything else.
I can keep running code, as I am using VS Code, so I just go to the file and Ctrl+Enter to run whatever I want, but the terminal is completely blocked for me to type directly in it.

Am I doing something wrong? or is this a common bug?

I’m using Julia 1.10.4, btw

Thank you!

Does the same thing occur every time?

You don’t seem to be doing anything wrong. This is not common behavior, I just ran it now, and it seems to works find for me on the current version of dependencies.

What happens if you run

r = report(mach);

Note the semi-colon there. Without the semi-colon it will try to print the report. I want to verify if it is creating the report or printing it where your terminal freezes.

I have had similar issues (A curious bug(?) in VS Code / Symbolic Regression). This happens only in VSCode, not when running Julia in a terminal.

I logged an issue under the VSCode add-in, but the devs could not replicate, which leads me to suspect that there is a configuration issue at play. For what it is worth, I can replicate this on both my machines and a colleague’s work laptop as well.

Yes. It happens all the time. I’ve even restarted VS code.
I also tried running it with the semi-colon and the REPL still freezes.

Actually, I have just realized that it freezes when I run fit!(mach); before r = report(mach);

As @braamvandyk said, it only happens when I run it under the VSCode add-in. If I type fit!(mach);directly in the REPL, it works perfectly fine.

Are you also running it in VS code? Which version and dependencies are you using?

Very odd. I haven’t seen this myself.

Since I can’t repro it on my machine, can you run some tests for me?

  1. Does progress=false change things? This will disable the progress bar.
  2. Does verbosity=0 change things?
  3. Does it change depending on the number of threads? e.g., with JULIA_NUM_THREADS=1?
  4. Can you try making the following change to this line?
-    stdin_reader = watch_stream(stdin)
+    stdin_reader = watch_stream(devnull)

^I wonder if it’s some interaction between stdin and VSCode that’s causing it. This mechanism is only used for checking if the user wants to exit early, so switching it to devnull shouldn’t be an issue.


Also, what operating system are you both using? I’m trying to figure out if there’s some pattern between your systems that will give me a signal I can use.

2 Likes

Thanks for your answer, @MilesCranmer

Tests 1, 2, and 3 also failed with the same behavior as before.
(btw, I could not change verbosity to 0 directly in SRRegressor in the code I was using, as I got this error: ERROR: You cannot set verbosity in both the search parameters Options and the call to equation_search. So I had o run that test with equation_search instead. Maybe something to check?)

But test 4 worked! Making the change you said unfreezes my REPL and I get a normal behavior.

Regarding OS, I get this error when I run the code on Windows 11.

Fantastic, thank you, that is very informative. @braamvandyk are you also running on Windows?

So I think the issue comes from something like the following code (when executed on Windows, in your VSCode setup)

Base.start_reading(stdin)
for _ in 1:100
    bytes = bytesavailable(stdin)
    if bytes > 0
        data = read(stdin, bytes)
    end
    sleep(0.01)
end
Base.stop_reading(stdin)

Can you try to use this to produce a smaller example of this behavior?

Basically when you replace stdin with devnull in this code, it does nothing. So I’m curious why reading from stdin on Windows in VSCode causes a hang… Maybe stdin is getting fed some stream as input by VSCode? Could it be an issue in the Julia VSCode extension I wonder?

Yes, both Win 10 Pro (2 machines) and Win 10 Home (1 machine).

One possible patch would be to disable reading stdin on Windows. Or maybe just have the default stdin behavior be different between Windows/Linux/macOS.

I’m curious if there are any known issues about Base.start_reading(stdin) on Windows… Maybe a passerby can comment on this.


@braamvandyk can you verify the above patch works?

It’s also weird that this issue has only sprung up now - I see @braamvandyk’s issue was posted 10 days ago. However, the Base.start_reading(stdin) has been in use in SymbolicRegression.jl for multiple years now. Are there any recent changes in the VSCode extension that might interact with this @davidanthoff?

Sorry for the delay. I was travelling. I can confirm that tests 1-3 did not make a difference.

Patching the file, as proposed, worked like a charm! Thank you for the assistance and for the truly great tool that SymbolicRegression is.