[SciPy-User] fmin_l_bfgs_b stdout gets mixed into following Python stdout

Jaidev Deshpande deshpande.jaidev at gmail.com
Thu Jan 29 10:25:12 EST 2015


On Thu, Jan 29, 2015 at 8:28 PM, Daan Wynen <daan.wynen at inria.fr> wrote:

>  Hi,
>
> I couldn't find anything about this issue, and it is not critical but
> annoying.
> Whenever I run the solver, the standard output order gets mixed up.
> What I want to see is the following (blank lines stripped out for saving
> space):
>
> ...
> ME SAYS: Unoptimized objective: 0.947251976788
>
> RUNNING THE L-BFGS-B CODE
>            * * *
> Machine precision = 2.220D-16
>  N =           50     M =           20
> At X0         0 variables are exactly at the bounds
> At iterate    0    f=  9.47252D-01    |proj g|=  1.04635D-01
> At iterate    1    f=  7.95655D-01    |proj g|=  9.16550D-02
> ...
> At iterate 3769    f=  7.12543D-05    |proj g|=  2.07939D-05
> At iterate 3770    f=  7.12527D-05    |proj g|=  1.51021D-04
>            * * *
> Tit   = total number of iterations
> ...
>  Total User time 0.000E+00 seconds.
>
> ME SAYS: After optimization: 7.1252665476e-05
> ...
>
>
> Instead, what I get is this:
>
>
> ...
> ME SAYS: Unoptimized objective: 0.947251976788
>
> RUNNING THE L-BFGS-B CODE
>            * * *
> Machine precision = 2.220D-16
>  N =           50     M =           20
> At X0         0 variables are exactly at the bounds
> At iterate    0    f=  9.47252D-01    |proj g|=  1.04635D-01
> At iterate    1    f=  7.95655D-01    |proj g|=  9.16550D-02
> ...
> At iterate 3147    f=  8.09457D-05    |proj g|=  5.97659D-05
>
> ME SAYS: After optimization: 7.1252665476e-05
> At iterate 3148    f=  8.09298D-05    |proj g|=  5.19516D-05
> ...
> At iterate 3769    f=  7.12543D-05    |proj g|=  2.07939D-05
> At iterate 3770    f=  7.12527D-05    |proj g|=  1.51021D-04
>            * * *
> Tit   = total number of iterations
> ...
>  Total User time 0.000E+00 seconds.
> ...
>
> Obviously, when I run an experiment, I would like to see the result at the
> end, and not buried somewhere in the middle of the iteration outputs.
> I tried passing callback=lambda _: sys.stdout.flush() and putting another
> flush after the whole optimization, but it didn't help.
> The example is on a very fast toy calculation, but this also happens when
> each iteration takes multiple seconds.
>
> I am using:
> python 2.7.3 (virtualenv from Fedora 18 distribution)
> scipy 0.14.1
> numpy 1.9.1
> But this also happens on Canopy.
>
> Is this maybe just to be expected when interfacing with fortran, or am I
> using this the wrong way?
>
> Best Regards
> Daan Wynen
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
Perhaps this can be fixed by running your Python script in the unbuffered
output mode, as

$ python -u foo.py

-- 
JD
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150129/c9006e17/attachment.html>


More information about the SciPy-User mailing list