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

[unitaryhack] Improve the calculation of multidimensional hermite polynomials #214

Open
nquesada opened this issue Oct 27, 2020 · 10 comments
Labels
C++ enhancement New feature or request unitaryhack

Comments

@nquesada
Copy link
Collaborator

nquesada commented Oct 27, 2020

This issue has been tagged for a bounty during unitaryHACK

Currently all calculations of multidimensional hermite polynomials are carried in double precision even though the C++ functions to do these calculations are templated to allow for any datatype.

A useful addition to The Walrus would be to allow the Python modules to have the C++ functions do calculations in long double precision. Note that even if the input and output of the C++ functions is ultimately casted to double it is still useful to internally do the calculations in long double given that numerical errors can accumulate very fast. Similar issues for the calculations of hafnians have been solved by doing its internal calculation in long double.

Two alternatives come to mind to achieve this:

  1. Make a wrapper function that takes as input the matrix R and vector y as double precision arrays and then converts them to long double and pass them to the templated version of hermite_multidimensional_cpp. An array in long double would be returned and then the wrapper function would cast this array into double precision and return it to Python using the ArrayWrapper for double datatypes in libwalrus.pyx.

  2. A second option that would avoid any type conversion is to write new array wrappers that allow to pass transparently long double arrays into numpy np.longdouble.

An important caveat for testing is that in MS Visual C++ long double is an alias for double so no gain in precision can be obtained by using this compiler.

@nquesada nquesada changed the title Adding support for long double calculation of multidimensional hermite polynomials Improving the calculation of multidimensional hermite polynomials Apr 16, 2021
@co9olguy co9olguy changed the title Improving the calculation of multidimensional hermite polynomials Improve the calculation of multidimensional hermite polynomials Apr 16, 2021
@co9olguy co9olguy changed the title Improve the calculation of multidimensional hermite polynomials [unitaryhack] Improve the calculation of multidimensional hermite polynomials Apr 16, 2021
@nquesada
Copy link
Collaborator Author

A second improvement would be to find a way to parallelize the loop in line

for (ullint jj = 0; jj < Hdim-1; jj++) {
.

This might require a nontrivial amount of algorithmic thinking since this loop implements a recursion relation.

@nquesada
Copy link
Collaborator Author

Finally, it would also be interesting to think about porting this part of the code to numba.

@TripleRD
Copy link

Hi @nquesada, I didn't get the second improvement you proposed. Can you elaborate on it? Thanks!

@nquesada
Copy link
Collaborator Author

I just meant, to write an implementation of Hermite multidimensional in numba.

@TripleRD
Copy link

TripleRD commented May 14, 2021

A second improvement would be to find a way to parallelize the loop in line

for (ullint jj = 0; jj < Hdim-1; jj++) {

.
This might require a nontrivial amount of algorithmic thinking since this loop implements a recursion relation.

I was referring to this comment, can you elaborate on it? Thanks!

@co9olguy
Copy link
Member

Hi @TripleR47, the idea here is to use numba to replace that line (a serial for loop) with a parallelized version

@nquesada
Copy link
Collaborator Author

To add to @co9olguy : the challenge is that the for loop in line 114 is very long (dimensions Hdim) and implements a recursion relation, where the next element is calculated based on the values of previous ones. My comment is just to highlight that breaking a parallelzing a recursive loop might be non-trivial!

@e-eight
Copy link

e-eight commented May 29, 2021

Would love to take a stab at this. Okay if I work on this?

@co9olguy
Copy link
Member

Hi @e-eight, yes this issue is still open. Feel free to tackle it if interested :)

@e-eight
Copy link

e-eight commented May 30, 2021

Alright. Will give it a shot.

@sduquemesa sduquemesa added C++ enhancement New feature or request labels Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ enhancement New feature or request unitaryhack
Projects
None yet
Development

No branches or pull requests

5 participants