Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor&Feature: add default value controlling decimal length of output for out_mat_hs 1 case and expose user control keyword out_ndigits #3377

Merged
merged 13 commits into from
Jan 5, 2024

Conversation

kirk0830
Copy link
Collaborator

@kirk0830 kirk0830 commented Dec 23, 2023

Motivation

The precision loss of output is a large problem for any postprocessing, also for restarting tasks. When I print out Hamiltonian matrix and overlap, also wavefunctions, I find wavefunctions' orthonormalities are quite poor if I calculate psi@S@psi.conj().T with numpy directly, this is because of loss of numerical precision when outputting H and S matrix.
There is also other user @QG-phy mention the low efficiency of restarting SCF from a converged, output charge density and has addressed the problem raises from the lack of output precision control.
The formatting of output will be a relatively long-term task because there are many output files, we need to refactor them with formatter library one-by-one.
It is also a pre-requisite of implementation of QO, PR #3236

Results

In INPUT, write:

...
out_mat_hs 1
out_ndigits 10

Then find files in OUT.${suffix} directory:

26 (-4.17692579e-01,0.00000000e+00) (-8.25088205e-01,0.00000000e+00) (1.05161523e-16,0.00000000e+00) (1.61710920e-16,0.00000000e+00) (-1.64819880e-16,0.00000000e+00) (-2.44735352e-17,0.00000000e+00) (1.34155519e-16,0.00000000e+00) (-1.55070663e-16,0.00000000e+00) (5.47256130e-17,0.00000000e+00) (1.00917570e-16,0.00000000e+00) (-1.13651916e-16,0.00000000e+00) (5.67914496e-16,0.00000000e+00) (2.61974586e-17,0.00000000e+00) (-6.18508722e-01,0.00000000e+00) (-4.99914119e-01,0.00000000e+00) (-5.17536714e-17,0.00000000e+00) (-1.57853108e-16,0.00000000e+00) (1.24107296e-16,0.00000000e+00) (2.62584160e-17,0.00000000e+00) (-5.66502583e-18,0.00000000e+00) (1.08152054e-17,0.00000000e+00) (1.54453122e-16,0.00000000e+00) (1.51381726e-16,0.00000000e+00) (-2.40438784e-17,0.00000000e+00) (2.89587216e-16,0.00000000e+00) (-3.24278119e-17,0.00000000e+00)
 (8.12531923e-01,0.00000000e+00) (-2.30443779e-17,0.00000000e+00) (2.34782967e-17,0.00000000e+00) (-7.54155828e-17,0.00000000e+00) (8.28061401e-18,0.00000000e+00) (1.41954682e-16,0.00000000e+00) (-1.59716497e-17,0.00000000e+00) (1.80898335e-16,0.00000000e+00) (-2.50044123e-17,0.00000000e+00) (1.26059687e-17,0.00000000e+00) (2.70914304e-16,0.00000000e+00) (3.10683211e-17,0.00000000e+00) (-4.99914119e-01,0.00000000e+00) (7.25966376e-02,0.00000000e+00) (1.18232785e-16,0.00000000e+00) (-6.52689190e-17,0.00000000e+00) (-6.38592875e-17,0.00000000e+00) (4.95509727e-17,0.00000000e+00) (6.54849468e-17,0.00000000e+00) (-9.23721506e-17,0.00000000e+00) (4.68092003e-17,0.00000000e+00) (6.21112850e-17,0.00000000e+00) (6.83453958e-17,0.00000000e+00) (3.29627550e-16,0.00000000e+00) (-1.12214659e-17,0.00000000e+00)
 (3.51881441e-01,0.00000000e+00) (-4.91312989e-17,0.00000000e+00) (-1.81112573e-17,0.00000000e+00) (3.77316936e-01,0.00000000e+00) (1.73425760e-16,0.00000000e+00) (7.49120190e-17,0.00000000e+00) (-4.45517731e-16,0.00000000e+00) (9.69190884e-18,0.00000000e+00) (-2.88825003e-17,0.00000000e+00) (-5.51985961e-17,0.00000000e+00) (6.67473696e-02,0.00000000e+00) (-1.80584078e-16,0.00000000e+00) (-9.08024701e-17,0.00000000e+00) (-2.92935234e-02,0.00000000e+00) (2.85416140e-17,0.00000000e+00) (1.52781036e-16,0.00000000e+00) (-3.73147925e-03,0.00000000e+00) (8.18842099e-17,0.00000000e+00) (-6.74915646e-17,0.00000000e+00) (-7.78273500e-17,0.00000000e+00) (-5.20730475e-17,0.00000000e+00) (1.70044089e-17,0.00000000e+00) (-1.82281472e-17,0.00000000e+00) (-1.48125029e-01,0.00000000e+00)
 (3.51881441e-01,0.00000000e+00) (-4.62916208e-17,0.00000000e+00) (1.45594801e-16,0.00000000e+00) (3.77316936e-01,0.00000000e+00) (1.37365029e-16,0.00000000e+00) (-1.40458468e-16,0.00000000e+00) (1.62052226e-16,0.00000000e+00) (6.67473696e-02,0.00000000e+00) (-8.15349614e-17,0.00000000e+00) (-1.57507894e-17,0.00000000e+00) (-3.30139082e-17,0.00000000e+00) (8.96634679e-17,0.00000000e+00) (-5.43795234e-17,0.00000000e+00) (-2.92935234e-02,0.00000000e+00) (-4.89517098e-17,0.00000000e+00) (4.62954005e-17,0.00000000e+00) (-3.73147925e-03,0.00000000e+00) (9.07477954e-17,0.00000000e+00) (1.41615836e-18,0.00000000e+00) (-5.26244696e-17,0.00000000e+00) (-1.48125029e-01,0.00000000e+00) (-1.29432616e-18,0.00000000e+00) (3.82316857e-17,0.00000000e+00)
 (3.51881441e-01,0.00000000e+00) (-3.63919253e-17,0.00000000e+00) (6.45032529e-17,0.00000000e+00) (3.77316936e-01,0.00000000e+00) (6.08482530e-17,0.00000000e+00) (6.67473696e-02,0.00000000e+00) (1.71374935e-16,0.00000000e+00) (-3.43767260e-17,0.00000000e+00) (1.66083730e-16,0.00000000e+00) (-6.72883257e-17,0.00000000e+00) (-7.60027927e-17,0.00000000e+00) (-1.48467841e-17,0.00000000e+00) (-5.24211568e-17,0.00000000e+00) (-2.92935234e-02,0.00000000e+00) (1.24683489e-17,0.00000000e+00) (-7.93635464e-17,0.00000000e+00) (-3.73147925e-03,0.00000000e+00) (2.77820072e-18,0.00000000e+00) (-1.48125029e-01,0.00000000e+00) (6.31395324e-17,0.00000000e+00) (3.60500390e-18,0.00000000e+00) (3.60361752e-17,0.00000000e+00)
 (7.14941523e-01,0.00000000e+00) (-5.42236655e-17,0.00000000e+00) (-1.34888298e-16,0.00000000e+00) (8.58192570e-18,0.00000000e+00) (-5.02334398e-17,0.00000000e+00) (2.49614467e-16,0.00000000e+00) (-4.62128473e-17,0.00000000e+00) (3.86652462e-02,0.00000000e+00) (-8.00416200e-17,0.00000000e+00) (9.37541535e-18,0.00000000e+00) (-3.73147925e-03,0.00000000e+00) (-7.94449465e-17,0.00000000e+00) (-8.40254289e-18,0.00000000e+00) (1.38783181e-01,0.00000000e+00) (3.16589511e-17,0.00000000e+00) (-2.22262014e-17,0.00000000e+00) (3.13395124e-17,0.00000000e+00) (-4.20721568e-18,0.00000000e+00) (5.58169274e-17,0.00000000e+00) (-4.81116573e-18,0.00000000e+00) (-6.79510076e-03,0.00000000e+00)
 (7.14941523e-01,0.00000000e+00) (-1.00642765e-16,0.00000000e+00) (5.48125341e-17,0.00000000e+00) (1.03169461e-16,0.00000000e+00) (3.86652462e-02,0.00000000e+00) (-9.66065958e-17,0.00000000e+00) (2.65663406e-17,0.00000000e+00) (-9.07205473e-17,0.00000000e+00) (-5.16071590e-17,0.00000000e+00) (6.71661654e-17,0.00000000e+00) (-3.73147925e-03,0.00000000e+00) (7.58946784e-18,0.00000000e+00) (1.05818380e-16,0.00000000e+00) (1.38783181e-01,0.00000000e+00) (-1.22298181e-16,0.00000000e+00) (-3.52636523e-17,0.00000000e+00) (-1.86483006e-17,0.00000000e+00) (-6.79510076e-03,0.00000000e+00) (4.66206933e-17,0.00000000e+00) (6.33174367e-17,0.00000000e+00)
 (7.14941523e-01,0.00000000e+00) (3.86806594e-17,0.00000000e+00) (3.86652462e-02,0.00000000e+00) (-2.46932344e-17,0.00000000e+00) (-7.03799674e-17,0.00000000e+00) (8.17002016e-17,0.00000000e+00) (1.03568124e-16,0.00000000e+00) (9.32395123e-17,0.00000000e+00) (-4.83553962e-17,0.00000000e+00) (8.13158986e-18,0.00000000e+00) (-3.73147925e-03,0.00000000e+00) (2.88397210e-17,0.00000000e+00) (-7.37275055e-18,0.00000000e+00) (1.38783181e-01,0.00000000e+00) (-6.17983799e-18,0.00000000e+00) (-6.79510076e-03,0.00000000e+00) (3.72220069e-17,0.00000000e+00) (-9.21897730e-19,0.00000000e+00) (4.42354539e-17,0.00000000e+00)
 (1.40993516e+00,0.00000000e+00) (1.15010134e-17,0.00000000e+00) (-1.54947658e-16,0.00000000e+00) (3.71359792e-17,0.00000000e+00) (-8.40767021e-17,0.00000000e+00) (2.08532787e-16,0.00000000e+00) (1.00910889e-16,0.00000000e+00) (-2.01421747e-17,0.00000000e+00) (4.88162835e-17,0.00000000e+00) (7.26348366e-17,0.00000000e+00) (2.39615747e-17,0.00000000e+00) (2.56955681e-17,0.00000000e+00) (5.58634025e-17,0.00000000e+00) (-2.74384397e-01,0.00000000e+00) (8.64989909e-18,0.00000000e+00) (-4.55707282e-19,0.00000000e+00) (-5.38476285e-17,0.00000000e+00) (-6.26431660e-17,0.00000000e+00)
 (1.33944855e+00,0.00000000e+00) (-8.93121863e-17,0.00000000e+00) (-2.34545541e-17,0.00000000e+00) (-5.82293858e-17,0.00000000e+00) (7.13201488e-18,0.00000000e+00) (2.52348586e-17,0.00000000e+00) (6.24271783e-17,0.00000000e+00) (-2.22396904e-17,0.00000000e+00) (1.48125029e-01,0.00000000e+00) (-1.20908021e-16,0.00000000e+00) (3.84894091e-18,0.00000000e+00) (6.79510076e-03,0.00000000e+00) (1.30053425e-17,0.00000000e+00) (1.00268940e-01,0.00000000e+00) (-6.56094768e-17,0.00000000e+00) (5.93871716e-17,0.00000000e+00) (-7.44033810e-18,0.00000000e+00)
 (1.33944855e+00,0.00000000e+00) (-5.83188007e-17,0.00000000e+00) (-3.70723821e-17,0.00000000e+00) (-5.24389639e-17,0.00000000e+00) (3.19636366e-17,0.00000000e+00) (-4.78320538e-18,0.00000000e+00) (1.48125029e-01,0.00000000e+00) (-2.69424265e-17,0.00000000e+00) (-6.36714639e-17,0.00000000e+00) (6.79510076e-03,0.00000000e+00) (-1.10859583e-17,0.00000000e+00) (3.44233834e-18,0.00000000e+00) (4.63055983e-17,0.00000000e+00) (1.00268940e-01,0.00000000e+00) (-3.54398883e-18,0.00000000e+00) (5.58702940e-17,0.00000000e+00)
 (1.40993516e+00,0.00000000e+00) (4.87382758e-17,0.00000000e+00) (3.41632308e-16,0.00000000e+00) (3.30901487e-16,0.00000000e+00) (-4.73762487e-17,0.00000000e+00) (5.08626942e-17,0.00000000e+00) (7.84284430e-17,0.00000000e+00) (-3.00730392e-17,0.00000000e+00) (-4.93311981e-18,0.00000000e+00) (1.71036152e-17,0.00000000e+00) (-3.82876333e-17,0.00000000e+00) (1.03681066e-16,0.00000000e+00) (2.15366567e-17,0.00000000e+00) (-2.74384397e-01,0.00000000e+00) (1.77538153e-17,0.00000000e+00)
 (1.33944855e+00,0.00000000e+00) (2.18195434e-18,0.00000000e+00) (-1.17690146e-16,0.00000000e+00) (1.48125029e-01,0.00000000e+00) (-7.18284598e-18,0.00000000e+00) (-3.51349321e-17,0.00000000e+00) (6.79510076e-03,0.00000000e+00) (5.38848182e-17,0.00000000e+00) (-6.49979255e-17,0.00000000e+00) (-1.28647337e-17,0.00000000e+00) (5.11218258e-17,0.00000000e+00) (-3.28411606e-17,0.00000000e+00) (-1.70151931e-17,0.00000000e+00) (1.00268940e-01,0.00000000e+00)
 (-4.17692579e-01,0.00000000e+00) (-8.25088205e-01,0.00000000e+00) (-1.12834151e-16,0.00000000e+00) (-1.63818356e-16,0.00000000e+00) (-6.54312868e-17,0.00000000e+00) (-3.95901744e-17,0.00000000e+00) (-3.14070592e-16,0.00000000e+00) (-1.37203773e-16,0.00000000e+00) (8.96356933e-17,0.00000000e+00) (7.13233165e-17,0.00000000e+00) (1.24319875e-16,0.00000000e+00) (4.25931690e-16,0.00000000e+00) (1.97114950e-16,0.00000000e+00)
 (8.12531923e-01,0.00000000e+00) (7.13225300e-17,0.00000000e+00) (1.10035006e-16,0.00000000e+00) (-2.95921019e-17,0.00000000e+00) (1.08701856e-16,0.00000000e+00) (-4.27833165e-17,0.00000000e+00) (5.36013037e-17,0.00000000e+00) (5.01340934e-17,0.00000000e+00) (4.68101125e-17,0.00000000e+00) (-4.75727268e-17,0.00000000e+00) (3.56720289e-16,0.00000000e+00) (1.30653375e-17,0.00000000e+00)
 (3.51881441e-01,0.00000000e+00) (1.95187055e-16,0.00000000e+00) (8.24277780e-17,0.00000000e+00) (3.77316936e-01,0.00000000e+00) (-2.74198566e-17,0.00000000e+00) (-6.81745348e-17,0.00000000e+00) (9.39386008e-18,0.00000000e+00) (8.24266209e-17,0.00000000e+00) (-8.92105064e-17,0.00000000e+00) (3.80746374e-18,0.00000000e+00) (-6.67473696e-02,0.00000000e+00)
 (3.51881441e-01,0.00000000e+00) (-4.17423451e-17,0.00000000e+00) (-1.15413057e-16,0.00000000e+00) (3.77316936e-01,0.00000000e+00) (2.23341302e-17,0.00000000e+00) (-4.51088323e-17,0.00000000e+00) (4.52757455e-17,0.00000000e+00) (-6.67473696e-02,0.00000000e+00) (1.64796414e-17,0.00000000e+00) (1.30185055e-16,0.00000000e+00)
 (3.51881441e-01,0.00000000e+00) (-7.93982519e-17,0.00000000e+00) (9.32406738e-17,0.00000000e+00) (3.77316936e-01,0.00000000e+00) (-9.45848274e-18,0.00000000e+00) (-6.67473696e-02,0.00000000e+00) (1.37668978e-16,0.00000000e+00) (-5.64400221e-17,0.00000000e+00) (3.96687125e-17,0.00000000e+00)
 (7.14941523e-01,0.00000000e+00) (-2.21504151e-17,0.00000000e+00) (1.40939321e-16,0.00000000e+00) (-1.98881960e-16,0.00000000e+00) (1.01538681e-16,0.00000000e+00) (1.62903751e-16,0.00000000e+00) (-4.50501840e-17,0.00000000e+00) (-3.86652462e-02,0.00000000e+00)
 (7.14941523e-01,0.00000000e+00) (-5.89756016e-17,0.00000000e+00) (-1.65227024e-16,0.00000000e+00) (5.55209679e-17,0.00000000e+00) (-3.86652462e-02,0.00000000e+00) (-1.19134390e-17,0.00000000e+00) (-3.36093295e-17,0.00000000e+00)
 (7.14941523e-01,0.00000000e+00) (-1.13359425e-16,0.00000000e+00) (-3.86652462e-02,0.00000000e+00) (1.24909963e-16,0.00000000e+00) (-2.59027466e-16,0.00000000e+00) (4.63520479e-19,0.00000000e+00)
 (1.40993516e+00,0.00000000e+00) (7.62437225e-17,0.00000000e+00) (3.52814359e-17,0.00000000e+00) (-1.72563685e-16,0.00000000e+00) (5.59719207e-17,0.00000000e+00)
 (1.33944855e+00,0.00000000e+00) (-5.90975926e-17,0.00000000e+00) (-3.06146007e-17,0.00000000e+00) (6.42012408e-17,0.00000000e+00)
 (1.33944855e+00,0.00000000e+00) (-8.39994268e-17,0.00000000e+00) (1.72443739e-16,0.00000000e+00)
 (1.40993516e+00,0.00000000e+00) (6.44337904e-17,0.00000000e+00)
 (1.33944855e+00,0.00000000e+00)

Reminder

  • Have you linked an issue with this pull request?
  • Have you noticed possible changes of behavior below or in the linked issue?
  • Have you explained the changes of codes in core modules of ESolver, HSolver, ElecState, Hamilt, Operator or Psi? (ignore if not applicable)

Linked Issue

Fix #3373

What's changed?

  • change the default precision for printing Hamiltonian and overlap matrix
  • add one keyword out_ndigits to control the output precision, default is 8.

Any changes of core modules? (ignore if not applicable)

  • no.

@kirk0830 kirk0830 requested review from YuLiu98 and QG-phy and removed request for QG-phy December 23, 2023 03:04
Copy link
Collaborator

@WHUweiqingzhou WHUweiqingzhou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR introduces a new parameter out_ndigits, which can tune the precision of output. This parameter only supports the output of Hamil and overlap currently. Thanks for your valuable effort.

@dyzheng dyzheng merged commit f8d0b90 into deepmodeling:develop Jan 5, 2024
11 checks passed
@kirk0830 kirk0830 deleted the formatter_1 branch January 5, 2024 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Precision control of output files is needed to be carefully treated
4 participants