Skip to content

Conversation

@ajshephard
Copy link

This allows the print and/or summary file output to be suppressed whenever Print file and Summary file are set to empty strings. E.g. options = Dict("Print file" => "", "Summary file" => "").

@ajshephard
Copy link
Author

I will make a few more changes to this PR to address #17 . To avoid adding more options "Print file" => nothing can be used to completely suppress print output, while "Print file" => "" can be used to print to the REPL. (And similarly for the summary file.) The latter can be achieved by calling a Fortran function that returns the stdout unit defined in iso_fortran_env.

@ajshephard
Copy link
Author

ajshephard commented Sep 23, 2023

The default value of printfile is snopt-print.out so this should not break any existing programs. If "Print file" => nothing, output is suppressed, if "Print file" => "" output is directed to the terminal (which should close #17). I have also made the option non-case sensitive, so Print file, Print File, PRINT FILE, etc., are all valid. Everything here also applies to the summary file.

@martinozimek
Copy link

@ajshephard I tried this, but the behavior appears to only occur once per REPL instance. For example, if I try to run the optimization call a second time, but within the same REPL instance, then the terminal output disappears again.

@ajshephard
Copy link
Author

@martinozimek I can not reproduce this. If I run the following (based on code in examples.jl)

using Snopt

function rosenbrock(g, df, dg, x, deriv)
    f = (1 - x[1])^2 + 100*(x[2] - x[1]^2)^2
    fail = false

    if deriv
        df[1] = -2*(1 - x[1]) + 200*(x[2] - x[1]^2)*-2*x[1]
        df[2] = 200*(x[2] - x[1]^2)
    end

    return f, fail
end


x0 = [4.0; 4.0]
lx = [-5.0; -5.0]
ux = [5.0; 5.0]
lg = []
ug = []
rows = []
cols = []
options = Dict(
    "Print file" => ""
)
println("First")
xopt, fopt, info, out = snopta(rosenbrock, x0, lx, ux, lg, ug, rows, cols, options)

println("Second")
x0 = [4.0; 4.0]
xopt, fopt, info, out = snopta(rosenbrock, x0, lx, ux, lg, ug, rows, cols, options)

Then I get the same print output for both first and second call. Note that snopta is actually overwriting x0, so xopt and x0 are the same at the solution. If you call snopta without setting x0 again then it will converge immediately (so there is no iteration output to print).

@davegard1
Copy link

AJ are you able to merge your changes into a branch we can pull? I tried to grab yours manually but maybe missed some changes resulting in the one print per terminal error.

@ajshephard
Copy link
Author

AJ are you able to merge your changes into a branch we can pull? I tried to grab yours manually but maybe missed some changes resulting in the one print per terminal error.

I'm not able to merge this. I think @andrewning can if he is happy with changes.

@ajshephard ajshephard changed the title Allow printing of output files to be suppressed Allow printing of output files to be suppressed and terminal output Jan 9, 2024
@andrewning
Copy link
Member

Since we seem to be having conflicting behavior probably would be best if we had some additional testing before pulling into the main branch. But note that there is already a branch you can pull from though to test these changes, the branch the pull request is coming from: https://github.com/ajshephard/Snopt.jl/tree/disable_printing

@davegard1
Copy link

davegard1 commented Jan 10, 2024

Got the branch, thanks both.

AJ here are screenshots of my repl output, using your test file:
test_problem

repl_output_p1
repl_output_p2

I am on your branch so that should all be aligned. Also I followed instructions in the snopt repo for making changes to the snopt src:
"You will need to make a couple of changes to subroutine sn02lib.f. Function snSet, snSeti, and snSetr require the following changes:"
"sn27lu.f, sn27lu77.f, and sn27lu90.f contain duplicate symbols. You'll need to keep only one file. I deleted the latter two files. If you are building with SNOPT v7.7 and do not define any user functions, you will also need to delete snopth.f."

I did both steps, which are working fine. I also found I am able to build/use snopt without doing the changes to snSet/Seti/Setr though. I am using snopt v7.7, I did not test the deletion of the files.

I am using WSL and Julia 1.9.2, could it be a WSL or julia version difference? I also had a few others on my team repeat the first print second no print to make sure it wasn't just myself.

Thank you a ton for your time on this! It's been a big help.

@andrewning
Copy link
Member

You all probably know this, but to view progress in realtime I use tail (e.g., tail -f filename). I prefer that over the repl anyway as I can check in on progress in real time (then close it when I don't want to keep monitoring the whole time), and that history is saved so I can compare different runs. Anyway, just an option.

@ajshephard
Copy link
Author

I can't reproduce this issue.

Can you add the following to the end of the test file, and let me know the output each time you run this?

println(Snopt.STDOUTNUM, ",", Snopt.get_stdout())

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

Successfully merging this pull request may close these issues.

4 participants