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

Loss of precision in Python #116

Closed
scemama opened this issue May 4, 2023 · 3 comments
Closed

Loss of precision in Python #116

scemama opened this issue May 4, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@scemama
Copy link
Member

scemama commented May 4, 2023

I wrote the nuclear repulsion in a TREXIO file. The nuclear repulsion computed by quantum package is

* Nuclear repulsion energy                           9.189533758614488    

I store it in a TREXIO file, and when I read it back in Python I get:

trexio.read_nucleus_repulsion(f)
9.189534187316895

The value given by Python is the same with both the text and the HDF5 back-ends.

When I inspect the text files produced by the text backend, I can see that the value of the nuclear repulsion is correct:

nucleus_repulsion   9.1895337586144876e+00                                                   

So I believe there is a conversion from float64 to float32 in the python interface after reading, but I could not figure out where it comes from...

It seems that I get the problem only for scalars. Arrays seem to be OK.

@scemama scemama added the bug Something isn't working label May 4, 2023
@scemama
Copy link
Member Author

scemama commented May 4, 2023

Note: When I read the value in C, it is correct.

#include <trexio.h>
#include <stdio.h>

int main() {
  trexio_exit_code rc;
  trexio_t* trexio_file = trexio_open("h2o_dz.h5", 'r', TREXIO_AUTO, &rc);

  double rep;
  rc = trexio_read_nucleus_repulsion(trexio_file, &rep);                                     
  printf("%25.20f\n", rep);
}
$ ./a.out
   9.18953375861448762407

@q-posev
Copy link
Member

q-posev commented May 5, 2023

@scemama You can try to replace the following line with the following %apply double *OUTPUT { double* const num}; and re-install the Python API

@scemama
Copy link
Member Author

scemama commented May 5, 2023

Thanks! It works! :-)

scemama added a commit that referenced this issue May 5, 2023
@scemama scemama closed this as completed May 5, 2023
scemama added a commit that referenced this issue May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants