# SymbolicRegression.jl freezing my terminal when running report

**URL:** <https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368>\
**Category:** Machine Learning\
**Tags:** question\
**Created:** [September 13, 2024, 11:03am UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368 "2024-09-13T11:03:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![elcup](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elcup/32/202351_2.png) [@elcup](https://discourse.julialang.org/u/elcup)\
**Post date:** [September 13, 2024, 11:03am UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368/1 "2024-09-13T11:03:31Z")

</div>

Hey!

I am starting to play with SymbolicRegression.jl and I am getting some weird behavior when running the basic example ([Examples · SymbolicRegression.jl](https://astroautomata.com/SymbolicRegression.jl/stable/examples/))

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

```julia
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!

---

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [September 13, 2024, 12:42pm UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368/2 "2024-09-13T12:42:12Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

**Author:** ![braamvandyk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/braamvandyk/32/5086_2.png) [@braamvandyk](https://discourse.julialang.org/u/braamvandyk)\
**Post date:** [September 13, 2024, 4:14pm UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368/3 "2024-09-13T16:14:05Z")

</div>

I have had similar issues ([A curious bug(?) in VS Code / Symbolic Regression](https://discourse.julialang.org/t/a-curious-bug-in-vs-code-symbolic-regression/119100)). 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.

---

<div class="post-metadata">

**Author:** ![elcup](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elcup/32/202351_2.png) [@elcup](https://discourse.julialang.org/u/elcup)\
**Post date:** [September 16, 2024, 8:37am UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368/4 "2024-09-16T08:37:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [September 16, 2024, 9:05am UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368/5 "2024-09-16T09:05:14Z")

</div>

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](https://github.com/MilesCranmer/SymbolicRegression.jl/blob/8f67533b9d7a7e3a12628948d213233fd87cee15/src/SymbolicRegression.jl#L637)?

```diff
- 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.

---

<div class="post-metadata">

**Author:** ![elcup](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elcup/32/202351_2.png) [@elcup](https://discourse.julialang.org/u/elcup)\
**Post date:** [September 16, 2024, 9:52am UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368/6 "2024-09-16T09:52:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [September 16, 2024, 10:00am UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368/7 "2024-09-16T10:00:48Z")

</div>

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)

```julia
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?

---

<div class="post-metadata">

**Author:** ![braamvandyk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/braamvandyk/32/5086_2.png) [@braamvandyk](https://discourse.julialang.org/u/braamvandyk)\
**Post date:** [September 16, 2024, 10:03am UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368/8 "2024-09-16T10:03:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [September 16, 2024, 10:08am UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368/9 "2024-09-16T10:08:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [September 16, 2024, 10:11am UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368/10 "2024-09-16T10:11:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![braamvandyk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/braamvandyk/32/5086_2.png) [@braamvandyk](https://discourse.julialang.org/u/braamvandyk)\
**Post date:** [September 18, 2024, 5:30pm UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368/11 "2024-09-18T17:30:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [December 9, 2024, 2:19am UTC](https://discourse.julialang.org/t/symbolicregression-jl-freezing-my-terminal-when-running-report/119368/12 "2024-12-09T02:19:17Z")

</div>

Hey all,

Sorry for the delay. I’ve got a patch here: [feat: allow user-specified `stdin` by MilesCranmer · Pull Request #382 · MilesCranmer/SymbolicRegression.jl · GitHub](https://github.com/MilesCranmer/SymbolicRegression.jl/pull/382). This will let you specify `input_stream=devnull` in your `SRRegressor` which will help avoid the hang.

No response from the VSCode extension team yet in [frozen REPL in VSCode when using SymbolicRegression.jl · Issue #3744 · julia-vscode/julia-vscode · GitHub](https://github.com/julia-vscode/julia-vscode/issues/3744) so this PR is a workaround in the meantime. I don’t think it’s an SR-specific issue because it seems to just be from `Base.start_reading(stdin)` which should be harmless.

Cheers,  
Miles
