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

Corrected IETS #240

Merged
merged 6 commits into from
Dec 19, 2023
Merged

Corrected IETS #240

merged 6 commits into from
Dec 19, 2023

Conversation

ProkopHapala
Copy link
Collaborator

@ProkopHapala ProkopHapala commented Dec 6, 2023

fixes #71

I found error in the IETS simulations which was found by @ondrejkrejci (as I mentioned previously here #71 (comment) )

Basically the whole problem was that the pointer to the Forcefield grid become invalid in C++ because Python garbage-collected correspoding numpy array FF which was local to perform_relaxation() function.

To solve this issue I simply made this array global by adding global FF at the begining of perform_relaxation() function, which prevents the grabage collectro from de-allocating.

I know the memory-managament in ppafm (especially python/C++ sharing) is pretty nasty. These bugs are hard to find. If you have some better ideas how to do this sharing let me know.

…y from which we read in getPPforce() is invalid?
…s Grabare-collected in python, so it crase when I access it in C++ stiffnessMatrix(); Solved by making FF global in HighLevel.py:perform_relaxation(); keeping debug-prints for reference (will be removed later)
Copy link

codecov bot commented Dec 6, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (5b1e71b) 46.45% compared to head (9a13272) 46.41%.

Files Patch % Lines
ppafm/cli/relaxed_scan.py 0.00% 3 Missing ⚠️
ppafm/core.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #240      +/-   ##
==========================================
- Coverage   46.45%   46.41%   -0.05%     
==========================================
  Files          35       35              
  Lines        5179     5184       +5     
==========================================
  Hits         2406     2406              
- Misses       2773     2778       +5     
Flag Coverage Δ
python-3.10 46.42% <0.00%> (-0.05%) ⬇️
python-3.11 46.38% <0.00%> (-0.05%) ⬇️
python-3.12 46.38% <0.00%> (-0.05%) ⬇️
python-3.7 46.21% <0.00%> (-0.05%) ⬇️
python-3.9 46.30% <0.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@ProkopHapala
Copy link
Collaborator Author

@yakutovicha this codecov complains again that my modifications lowered the coverage, and fails the checks? Can we turn it of somehow?

@yakutovicha
Copy link
Collaborator

@yakutovicha this codecov complains again that my modifications lowered the coverage, and fails the checks? Can we turn it of somehow?

Please ignore the failing test at the moment. I will fix it before our next meeting. Here is the issue #241

@yakutovicha
Copy link
Collaborator

I have no time/capacity to review things at the moment, so I removed myself from the reviewers.

@yakutovicha yakutovicha removed their request for review December 6, 2023 20:55
Copy link
Collaborator

@ondrejkrejci ondrejkrejci left a comment

Choose a reason for hiding this comment

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

Just comments for now, pleae have a look especially on the makefile. Thank you @ProkopHapala !

@@ -175,6 +175,9 @@ def main(argv=None):
tip_positions_x, tip_positions_y, tip_positions_z, lvec_scan = common.prepareScanGrids()
r_tips = np.array(np.meshgrid(tip_positions_x, tip_positions_y, tip_positions_z)).transpose(3, 1, 2, 0).copy()
evals, evecs = core.stiffnessMatrix(r_tips.reshape((-1, 3)), pp_positions.reshape((-1, 3)), which=which, ddisp=common.params["ddisp"])
print("vib eigenval 1 min..max : ", np.min(evals[:, 0]), np.max(evals[:, 0]))
Copy link
Collaborator

Choose a reason for hiding this comment

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

May, I ask you, why is the printing necessary?

Copy link
Collaborator Author

@ProkopHapala ProkopHapala Dec 7, 2023

Choose a reason for hiding this comment

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

It is not necessary, but I think it is useful to see some summary in the output imediately, before you start plotting images. In case you see some non-sense value (NaNs, all zero, super high, super low) then you know immedietely something went wrong. So yes, it is just for debugging, but I think it is debugging which user will often do. The question is computing cost. I think it does not cost too much, but maybe it would be better do it inside C++ loop (that would be even cheaper).

for i in range(which):
evecs[i] = np.zeros((n, 3))
print("py.core.stiffnessMatrix() 1 ")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is just a check that the stiffness matrix was initialized?

// symmetrize - to make sure that our symmetric matrix solver work properly
double tmp;
tmp = 0.5*(dynmat.xy + dynmat.yx); dynmat.xy = tmp; dynmat.yx = tmp;
tmp = 0.5*(dynmat.yz + dynmat.zy); dynmat.yz = tmp; dynmat.zy = tmp;
tmp = 0.5*(dynmat.zx + dynmat.xz); dynmat.zx = tmp; dynmat.xz = tmp;
// solve mat
Vec3d evals; dynmat.eigenvals( evals ); Vec3d temp;
double eval_check = evals.a * evals.b * evals.c;
//if( fabs(eval_check) < 1e-16 ){ };
if( isnan(eval_check) ){ printf( "C++ stiffnessMatrix[%i] is NaN evals (%g,%g,%g) \n", i, evals.a, evals.b, evals.c ); exit(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 guess that we used to have couple of NaNs in the past, but we have used floating average to get rid of it in Python.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think in principle we should not have NaNs (we offset from zero for that reason). So I think it is better to have this check, to spot if there are really some NaNs to be able to debug that case.

#CPPFLAGS= -fPIC -std=c++11 -O2 -mtune=native
CPPFLAGS= -fPIC -std=c++11 -O2 -mtune=native -fopenmp
#CPPFLAGS= -fPIC -std=c++11 -Og -g
Copy link
Collaborator

Choose a reason for hiding this comment

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

Beware, I think that the changes in the makefile are not neccessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually I don't understand why you removed the debug options from the Makefile. I would keep them there, so that we can debug it easily in future.

@yakutovicha
Copy link
Collaborator

Codecov is finally tamed 🎉

Copy link
Collaborator

@ondrejkrejci ondrejkrejci left a comment

Choose a reason for hiding this comment

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

Ok, after all the explanations, I am happy.

@yakutovicha yakutovicha merged commit d629c6d into main Dec 19, 2023
@yakutovicha yakutovicha deleted the debug_IETS branch December 19, 2023 11:13
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.

CoPc-IETS example corrupted
3 participants