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?
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 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.
^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.
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?
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?