Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppressor not working with Julia 1.7.1 and SimpleGraphAlgorithms #40

Open
sflammia opened this issue Dec 27, 2021 · 3 comments
Open

Suppressor not working with Julia 1.7.1 and SimpleGraphAlgorithms #40

sflammia opened this issue Dec 27, 2021 · 3 comments

Comments

@sflammia
Copy link

sflammia commented Dec 27, 2021

I recently upgraded to Julia 1.7.1 and I noticed that Suppressor.jl is not working anymore with some code where it was previously working just fine. Here is a minimal working example:

julia> using SimpleGraphs, SimpleGraphAlgorithms, Suppressor

julia> G = SimpleGraph([0 1; 1 0])
SimpleGraph{Int64} (n=2, m=1)

julia> @suppress vertex_color(G)

I was expecting the output to just be

Dict{Int64, Int64} with 2 entries:
  2 => 1
  1 => 2

but instead, I get a very verbose output from the solver that computes the vertex coloring. This same code worked fine in Julia 1.6.3, so I'm not sure what has changed.

When running from the command line, the second and subsequent times that I run the last line, I get the expected output. However, when I'm in a Jupyter notebook, I keep getting the verbose text every time.

@Roger-luo
Copy link

Roger-luo commented Dec 29, 2021

Hi Steve, I just run into the same issue, a simple fix is to define the following in your code

Base.get(::Base.PipeEndpoint, key::Symbol, default) = key === :color ? Base.get_have_color() : default

but I think this cannot be added to a package right now, since it might break other things which I'm not sure about. I think this is a Julia issue, just filed an issue (above) in JuliaLang repo.


I misunderstand part of your issue, I think the other part that has been changed is the return value of redirect_stdout, it is now only one Pipe object instead of two. so this line is not correct anymore

out_rd, out_wr = redirect_stdout()

I think one could just use the following on 1.7 without using Suppress now

redirect_stdout(Pipe()) do
    vertex_color(G)
end

(it's a bit of surprise that Pipe() is not a default value for redirect_stdout(f)...)

@sflammia
Copy link
Author

Thanks Roger! That work around helps, but it doesn't solve the problem for more complicated use cases. For example, if I put vertex_color inside another function, then it doesn't seem to work. For example, the following gives me verbose output in my jupyter notebook. (I didn't try command line.)

using SimpleGraphs, SimpleGraphAlgorithms

G = SimpleGraph([0 1; 1 0])

function quiet_color(G)
    redirect_stdout(Pipe()) do
        vertex_color(G)
    end
end

quiet_color(G)

I don't understand why redirect_stdout has different behavior inside or outside of a function.

@Roger-luo
Copy link

Roger-luo commented Dec 31, 2021

I think to ignore the stdout from C, one needs to redirect it to devnull, so the following code should do the trick, but I'm not sure why the printing is pasted to REPL when exiting, but this should work in scripts.

using SimpleGraphs, SimpleGraphAlgorithms

G = SimpleGraph([0 1; 1 0])

function quiet_color(G)
    redirect_stdout(devnull) do
        vertex_color(G)
    end
end

quiet_color(G)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants