diff --git a/docs/methods.rst b/docs/methods.rst index ae30ac8295..68628358f7 100644 --- a/docs/methods.rst +++ b/docs/methods.rst @@ -1143,6 +1143,26 @@ the values found in the \*.sXXX.opt.h5 file. Be careful to keep the pair of optimized CI coefficients and Jastrow coefficients together to avoid inconsistencies. +Output of intermediate values +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Use the following parameters to the linear optimizers to output intermediate values such as the overlap and Hamiltonian matrices. + + +-------------------------+--------------+-------------+-------------+--------------------------------------------------+ + | **Name** | **Datatype** | **Values** | **Default** | **Description** | + +=========================+==============+=============+=============+==================================================+ + | ``output_matrices_csv`` | text | yes, no | no | Output linear method matrices to CSV files | + +-------------------------+--------------+-------------+-------------+--------------------------------------------------+ + | ``output_matrices_hdf`` | text | yes, no | no | Output linear method matrices to HDF file | + +-------------------------+--------------+-------------+-------------+--------------------------------------------------+ + | ``freeze_parameters`` | text | yes, no | no | Do not update parameters between iterations | + +-------------------------+--------------+-------------+-------------+--------------------------------------------------+ + + The ``output_matrices_csv`` parameter will write to .ham.s000.scalar.dat and .ovl.scalar.dat. One line per iteration of the optimizer loop. Combined with ``freeze_parameters``, this allows computing error bars on the matrices for use in regression testing. + + The ``output_matrices_hdf`` parameter will output in HDF format the matrices used in the linear method along with the shifts and the eigenvalue and eigenvector produced by QMCPACK. The file is named "..linear_matrices.h5". It only works with the batched optimizer (``linear_batch``) + + .. _dmc: Diffusion Monte Carlo diff --git a/src/QMCDrivers/WFOpt/QMCFixedSampleLinearOptimize.cpp b/src/QMCDrivers/WFOpt/QMCFixedSampleLinearOptimize.cpp index ff9b3146da..5a4f85fb74 100644 --- a/src/QMCDrivers/WFOpt/QMCFixedSampleLinearOptimize.cpp +++ b/src/QMCDrivers/WFOpt/QMCFixedSampleLinearOptimize.cpp @@ -472,7 +472,7 @@ bool QMCFixedSampleLinearOptimize::put(xmlNodePtr q) oAttrib.add(vmcMove, "move"); oAttrib.add(ReportToH5, "hdf5"); - m_param.add(OutputMatrices, "output_matrices"); + m_param.add(OutputMatrices, "output_matrices_csv"); m_param.add(FreezeParameters, "freeze_parameters"); oAttrib.put(q); diff --git a/src/QMCDrivers/WFOpt/QMCFixedSampleLinearOptimizeBatched.cpp b/src/QMCDrivers/WFOpt/QMCFixedSampleLinearOptimizeBatched.cpp index 58145b33f9..a05ba7091f 100644 --- a/src/QMCDrivers/WFOpt/QMCFixedSampleLinearOptimizeBatched.cpp +++ b/src/QMCDrivers/WFOpt/QMCFixedSampleLinearOptimizeBatched.cpp @@ -99,7 +99,8 @@ QMCFixedSampleLinearOptimizeBatched::QMCFixedSampleLinearOptimizeBatched(const P MinMethod("OneShiftOnly"), previous_optimizer_type_(OptimizerType::NONE), current_optimizer_type_(OptimizerType::NONE), - do_output_matrices_(false), + do_output_matrices_csv_(false), + do_output_matrices_hdf_(false), output_matrices_initialized_(false), freeze_parameters_(false) @@ -207,7 +208,7 @@ QMCFixedSampleLinearOptimizeBatched::RealType QMCFixedSampleLinearOptimizeBatche bool QMCFixedSampleLinearOptimizeBatched::run() { - if (do_output_matrices_ && !output_matrices_initialized_) + if (do_output_matrices_csv_ && !output_matrices_initialized_) { numParams = optTarget->getNumParams(); int N = numParams + 1; @@ -324,7 +325,7 @@ bool QMCFixedSampleLinearOptimizeBatched::previous_linear_methods_run() app_log() << " Using XS:" << XS << " " << failedTries << " " << stability << std::endl; eigenvalue_timer_.start(); getLowestEigenvector(Right, currentParameterDirections); - Lambda = getNonLinearRescale(currentParameterDirections, S); + Lambda = getNonLinearRescale(currentParameterDirections, S); eigenvalue_timer_.stop(); // biggest gradient in the parameter direction vector RealType bigVec(0); @@ -471,20 +472,23 @@ void QMCFixedSampleLinearOptimizeBatched::process(xmlNodePtr q) std::string vmcMove("pbyp"); std::string ReportToH5("no"); std::string OutputMatrices("no"); + std::string OutputMatricesHDF("no"); std::string FreezeParameters("no"); OhmmsAttributeSet oAttrib; oAttrib.add(useGPU, "gpu"); oAttrib.add(vmcMove, "move"); oAttrib.add(ReportToH5, "hdf5"); - m_param.add(OutputMatrices, "output_matrices"); - m_param.add(FreezeParameters, "freeze_parameters"); + m_param.add(OutputMatrices, "output_matrices_csv", {"no", "yes"}); + m_param.add(OutputMatricesHDF, "output_matrices_hdf", {"no", "yes"}); + m_param.add(FreezeParameters, "freeze_parameters", {"no", "yes"}); oAttrib.put(q); m_param.put(q); - do_output_matrices_ = (OutputMatrices != "no"); - freeze_parameters_ = (FreezeParameters != "no"); + do_output_matrices_csv_ = (OutputMatrices == "yes"); + do_output_matrices_hdf_ = (OutputMatricesHDF == "yes"); + freeze_parameters_ = (FreezeParameters == "yes"); // Use freeze_parameters with output_matrices to generate multiple lines in the output with // the same parameters so statistics can be computed in post-processing. @@ -1282,12 +1286,23 @@ bool QMCFixedSampleLinearOptimizeBatched::one_shift_run() optTarget->fillOverlapHamiltonianMatrices(hamMat, ovlMat); invMat.copy(ovlMat); - if (do_output_matrices_) + if (do_output_matrices_csv_) { output_overlap_.output(ovlMat); output_hamiltonian_.output(hamMat); } + hdf_archive hout; + if (do_output_matrices_hdf_) + { + std::string newh5 = get_root_name() + ".linear_matrices.h5"; + hout.create(newh5, H5F_ACC_TRUNC); + hout.write(ovlMat, "overlap"); + hout.write(hamMat, "Hamiltonian"); + hout.write(bestShift_i, "bestShift_i"); + hout.write(bestShift_s, "bestShift_s"); + } + // apply the identity shift for (int i = 1; i < N; i++) { @@ -1313,11 +1328,19 @@ bool QMCFixedSampleLinearOptimizeBatched::one_shift_run() std::swap(prdMat(i, j), prdMat(j, i)); // compute the lowest eigenvalue of the product matrix and the corresponding eigenvector - getLowestEigenvector(prdMat, parameterDirections); + RealType lowestEV = getLowestEigenvector(prdMat, parameterDirections); // compute the scaling constant to apply to the update Lambda = getNonLinearRescale(parameterDirections, ovlMat); + if (do_output_matrices_hdf_) + { + hout.write(lowestEV, "lowest_eigenvalue"); + hout.write(parameterDirections, "scaled_eigenvector"); + hout.write(Lambda, "non_linear_rescale"); + hout.close(); + } + // scale the update by the scaling constant for (int i = 0; i < numParams; i++) parameterDirections.at(i + 1) *= Lambda; diff --git a/src/QMCDrivers/WFOpt/QMCFixedSampleLinearOptimizeBatched.h b/src/QMCDrivers/WFOpt/QMCFixedSampleLinearOptimizeBatched.h index 356dd032cc..f810a5f968 100644 --- a/src/QMCDrivers/WFOpt/QMCFixedSampleLinearOptimizeBatched.h +++ b/src/QMCDrivers/WFOpt/QMCFixedSampleLinearOptimizeBatched.h @@ -205,7 +205,10 @@ class QMCFixedSampleLinearOptimizeBatched : public QMCLinearOptimizeBatched, bool doHybrid; // Output Hamiltonian and overlap matrices - bool do_output_matrices_; + bool do_output_matrices_csv_; + + // Output Hamiltonian and overlap matrices in HDF format + bool do_output_matrices_hdf_; // Flag to open the files on first pass and print header line bool output_matrices_initialized_;