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

Enhance mps/mpo reproducibility; Print git hash for easier debugging;… #162

Merged
merged 4 commits into from
Sep 20, 2023

Conversation

jiangtong1000
Copy link
Collaborator

@jiangtong1000 jiangtong1000 commented Sep 13, 2023

  • Enhance mps/mpo reproducibility; Currently, even with preset random seed, the MPO or the subsequent ground state MPS will be different for two runs. The MPO is different because the Op order can be different before doing Hopcroft-Corp; The MPS can be different because the sign carried by the eigenvectors. This does not influence the final energy, but keeping everything reproducible could be important at sometime, especially for debugging purpose
  • The git hash information is printed every time running the package, for easier debugging
  • Fix mp dump/load

@liwt31
Copy link
Collaborator

liwt31 commented Sep 13, 2023

I really like this commit but there are some technical problems. Please see the comments

@@ -383,10 +383,10 @@ def eigh_direct(
nroots = mps.optimize_config.nroots
if nroots == 1:
e = w[0]
c = v[:, 0]
c = v[:, 0] / np.sign(np.max(v[:, 0]))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this works as expected. You might first want to take absolute values before calling max. Also, this "canonicalize" logic is used below. Maybe it's better to wrap it as a utility function

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

util function added and bug fixed

if nroots == 1:
return e, c/np.sign(np.max(c))
else:
return e, c/np.sign(np.max(c, axis=0))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might cause the bug in CI. Taking max along the 0th axis will eliminate the 0th axis, resulting a vector with size N, where N is the dimension of c.

@codecov
Copy link

codecov bot commented Sep 13, 2023

Codecov Report

Patch coverage: 87.50% and no project coverage change.

Comparison is base (1576c3c) 84.79% compared to head (bf6af3c) 84.80%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #162   +/-   ##
=======================================
  Coverage   84.79%   84.80%           
=======================================
  Files         105      105           
  Lines       10184    10207   +23     
=======================================
+ Hits         8636     8656   +20     
- Misses       1548     1551    +3     
Files Changed Coverage Δ
renormalizer/mps/mpo.py 91.12% <ø> (-0.04%) ⬇️
renormalizer/mps/mp.py 84.80% <66.66%> (+0.04%) ⬆️
renormalizer/mps/backend.py 70.83% <82.35%> (+1.02%) ⬆️
renormalizer/mps/gs.py 96.04% <100.00%> (+0.11%) ⬆️
renormalizer/mps/symbolic_mpo.py 75.76% <100.00%> (+0.06%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

def sign_fix(c, nroots):
if nroots > 1:
if isinstance(c, list):
return [ci / np.sign(np.max(np.abs(ci))) for ci in c]
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Taking abs loses the sign information
  2. Add abs for the following branches as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. yea you are right. my mistake
  2. what do you mean the following branches?

Copy link
Collaborator

Choose a reason for hiding this comment

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

when c is not a list and when nroots == 1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

got it!

else:
return c / np.sign(np.max(c, axis=0))
return c / np.sign(np.max(np.abs(c), axis=0))
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems in this branch it still does not work properly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks for pointing out! Now I think it is resolved.

@liwt31 liwt31 merged commit b10fcaf into master Sep 20, 2023
4 checks passed
@liwt31 liwt31 deleted the reproducible branch September 20, 2023 10:56
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.

2 participants