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

Pathfinder diagnostic_file output missing newline #3200

Closed mitzimorris closed 1 year ago

mitzimorris commented 1 year ago

Summary:

The JSON diagnostic files for a single-path pathfinder don't have a final newline - should the pathfinder service add one? should the stan::callbacks::json_writer have special method to output newline?

Description:

From CmdStan WIP branch feature/1149-pathfinder-v2, ran Stan executable:

./examples/bernoulli/bernoulli data file=examples/bernoulli/bernoulli.data.json pathfinder output file=test/pathfinder.csv diagnostic_file=test/pathfinder.json

The size of all output files looks good, but the number of lines in the .json files is reported as 0. The cat command returns w/out a newline:

cat test/pathfinder_1.json 
{"0": {"iter" : 0, "unconstrained_parameters" : [ 1.26697 ], "grads" : [ -6.36269 ]},"1": {"iter" : 1, "unconstrained_parameters" : [ 1.26697 ], "grads" : [ -6.36269 ], "history_size" : 1, "lbfgs_success" : true, "pathfinder_success" : true, "x_center" : [ 0.905332 ], "logDetCholHk" : -2.86755, "L_approx" : [ [ -0.0568378 ] ], "Qk" : [  ], "alpha" : [ 1 ], "full" : true, "lbfgs_note" : ""},"2": {"iter" : 2, "unconstrained_parameters" : [ 0.630704 ], "grads" : [ 4.83179 ], "history_size" : 2, "lbfgs_success" : true, "pathfinder_success" : true, "x_center" : [ -1.06815 ], "logDetCholHk" : -0.522633, "L_approx" : [ [ 0.592957 ] ], "Qk" : [  ], "alpha" : [ 0.351598 ], "full" : true, "lbfgs_note" : ""},"3": {"iter" : 3, "unconstrained_parameters" : [ -0.924617 ], "grads" : [ 0.408217 ], "history_size" : 3, "lbfgs_success" : true, "pathfinder_success" : true, "x_center" : [ -1.09657 ], "logDetCholHk" : -0.432289, "L_approx" : [ [ 0.649022 ] ], "Qk" : [  ], "alpha" : [ 0.421229 ], "full" : true, "lbfgs_note" : ""},"4": {"iter" : 4, "unconstrained_parameters" : [ -1.0479 ], "grads" : [ 0.115554 ], "history_size" : 4, "lbfgs_success" : true, "pathfinder_success" : true, "x_center" : [ -1.09859 ], "logDetCholHk" : -0.411988, "L_approx" : [ [ 0.662332 ] ], "Qk" : [  ], "alpha" : [ 0.438684 ], "full" : true, "lbfgs_note" : ""},"5": {"iter" : 5, "unconstrained_parameters" : [ -1.09657 ], "grads" : [ 0.00459793 ], "history_size" : 5, "lbfgs_success" : true, "pathfinder_success" : true, "x_center" : [ -1.09861 ], "logDetCholHk" : -0.405723, "L_approx" : [ [ 0.666494 ] ], "Qk" : [  ], "alpha" : [ 0.444215 ], "full" : true, "lbfgs_note" : ""}}~/github/stan-dev/cmdstan (feature/1149-pathfinder-v2)> 

Reproducible Steps:

see above

Current Output:

see above

Expected Output:

File ends with eol.

Current Version:

v2.32.2