Remove Pystan log's

Hi all, in stan exist some way to remove the logs in the terminal? I’m trying take the execution time of hmc and nuts, but hmc have a lot of logs in terminal. regards and thanks :)

X = diabetes_X[:-20]
X_test = diabetes_X[-20:]

# Split the targets into training/testing sets
y =[:-20]
y_test =[-20:]

#Horseshoe-prior stan model
model_code = """
data {
  int<lower=0> n;
  int<lower=0> p;
  matrix[n,p] X;
  vector[n] y;
parameters {
  vector[p] beta;
  vector<lower=0>[p] lambda;
  real<lower=0> tau;
  real<lower=0> sigma;
model {
  lambda ~ cauchy(0, 1);
  tau ~ cauchy(0, 1);
  for (i in 1:p)
    beta[i] ~ normal(0, lambda[i] * tau);
  sigma ~ gamma(0.01,0.01);
  y ~ normal(X * beta, sigma);

n, p = X.shape 
data = dict(n=n, p=p, X=X, y=y)

print "#Horseshoe-prior with No-U-Turn-Sampler"
print "#Parameters:\n"
print "#Dataset: diabetes"
print "#N Itertations:", iterations

print "\n#Train:"
print "#Horseshoe-prior\n"

print "\n#TAKING TIME FOR NUTS..."
for k in range(K):
  start_nuts = timeit.default_timer()
  fit_nuts = pystan.stan(model_code=model_code, data=data, seed=5, iter=iterations, algorithm="NUTS")
  stop_nuts = timeit.default_timer()
  time_nuts = (stop_nuts-start_nuts)

print "\n#TAKING TIME FOR HMC..."
for k in range(K):
  start_hmc = timeit.default_timer()
  fit_hmc = pystan.stan(model_code=model_code, data=data, seed=5, iter=iterations, algorithm="HMC")
  stop_hmc = timeit.default_timer()
  time_hmc = (stop_hmc-start_hmc)

Try pystan.stan(..., refresh=0)

It did not work :( … the issue is that how this log is printed on the screen makes it difficult to measure the execution times

What do you mean by it is hard to measure execution times?

Here is one way to get output out. (Doesn’t work on Windows)

But if you run your model on ipython / jupyter lab you can use %time linemagic / %%time cell magic.

On terminal (linux) you can call your script with time python and if you just want to time sampling, then pickle your model file in another program, then read the pickled model and just do sampling.

If you want to handle log-information given by Python see our docs

edit. I read you initial post more carefully.

Gather the timing information to list/dictionary and print them later /after the sampling is done)

I still can not delete the log, specifically from HMC :(
When I use NUTS works fine … But when I use HMC print some errors from base_hamiltonian.hpp
I do not know if I’m forgetting some parameter in the call of stan. Thank you very much for your help

There’s currently no easy way to do this so the suggestions you are getting are to approach the problem differently.