stan-dev / stan

Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
2.61k stars 369 forks source link

laplace_sample service console output has too many newlines #3151

Closed mitzimorris closed 1 year ago

mitzimorris commented 2 years ago

Summary:

The console output of the laplace_sample method contains hundreds of blank lines.

Description:

This arises from two things:

To fix the former, remove newlines. To fix the latter, check the stringstream before calling the logger.

 model.write_array(rng, unc_draw, draw_vec, include_tp, include_gq, &write_array_msgs);
    if (refresh > 0) {
      if (write_array_msgs.peek() != std::char_traits<char>::eof())
        logger.info(write_array_msgs);

Reproducible Steps:

Use CmdStan branch https://github.com/stan-dev/cmdstan/tree/feature/1123-laplace-approx to invoke the laplace_sample method, model and input files are in the src/test/test-models/ directory.

>  src/test/test-models/multi_normal_model laplace mode=src/test/test-models/multi_normal_mode.csv

Current Output:

the beginning of the console ouput from call to laplace_sample - refresh is default 100, so lots of whitespace between iteration messages.

Calculating Hessian

Calculating inverse of Cholesky factor

Generating draws

iteration: 
0

Expected Output:

Calculating Hessian
Calculating inverse of Cholesky factor
Generating draws
iteration: 0
iteration: 100
iteration: 200
iteration: 300
iteration: 400
iteration: 500
iteration: 600
iteration: 700
iteration: 800
iteration: 900

Additional Information:

Provide any additional information here.

Current Version:

v2.30.0

bob-carpenter commented 2 years ago

Thanks for figuring this out. This is why I was asking if there was a newline appended to all of the callbacks. I had thought the answer was "no", but it's apparently "yes"!

WardBrian commented 2 years ago

There is a longstanding issue to make the logger ignore blank lines: #2577. Partial fix was started in #3098

bob-carpenter commented 2 years ago

The issue arose because I assumed there wasn't a newline inserted at the end of each message. If we are going to add newlines, then we probably do not want to ignore blank lines, as they correspond to newlines in the output.

WardBrian commented 2 years ago

In that case we can probably close those two

WardBrian commented 1 year ago

Closed by https://github.com/stan-dev/stan/pull/3153