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

use json-writer to write hmc tuning params #3181

Closed mitzimorris closed 1 year ago

mitzimorris commented 1 year ago

Summary:

Produce the metric and stepsize as a JSON output file instead of as comments embedded in CSV.

Description:

Using the implementation in stan-dev/stan/issues/3176, add methods which use json_writer to write metric and stepsize.

Current Output:

Using example model examples/bernoulli/bernoulli.stan (which has a single parameter), the output of a run of the NUTS-HMC sampler, adaptation on, diagonal metric, is:

# Adaptation terminated
# Step size = 0.885758
# Diagonal elements of inverse mass matrix:
# 0.489379

Expected Output:

JSON object:

{ "stepsize" : 0.885758,
   "diagnoal_metric" : [ 0.489379 ]
}

Current Version:

v2.32.0

mitzimorris commented 1 year ago

current HMC service methods have 2 flavors: (single chain) unit metric vs. pre-specified metric - 26, 27 args, respectively

plus multi-chain - adds another factor of 2: multi-chain versions call single-chain verison repeatedly - 31, 33 args.

this PR would add another 4 versions with add'l arg metric_file - 27, 28, 32, 34 args. respectively. ugh. or we need to add a final optional param metric_file which defaults to no-op instance. also ugh.

WardBrian commented 1 year ago

I think we're free to only add this feature to certain overloads - for example, only the multi-chain versions are used in CmdStan as of this version