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

created and tested bindings for hyperreduction #7

Merged
merged 12 commits into from
Aug 30, 2023

Conversation

pravija12345
Copy link
Collaborator

@pravija12345 pravija12345 commented Aug 22, 2023

S_OPT

The input argument std::vector<int> *init_samples cannot have a default value nullptr. See the pybind11 documentation.

Although, init_samples needs not be a pointer in S_OPT implementation. Therefore, we switched it into std::vector<int> &, and set the default value to be std::vector<int>(0). This does not impact the internal execution.

The arguments f_sampled_row and f_sampled_rows_per_proc are STL-type output variables, which cannot change its value if it is passed as an input argument. Therefore it is removed from the input argument list, and the python function return these two variables as tuple:

import pylibROM.hyperreduction as hyperreduction
f_sampled_row, f_sampled_rows_per_proc = hyperreduction.S_OPT(u, num_basis_vectors, f_basis_sampled_inv, myid, num_procs, num_samples)

Note that Matrix& f_basis_sampled_inv is both input and output, and it is not a STL-type. This allows us passing it as an input argument which can modify its value within the function.

@dreamer2368
Copy link
Collaborator

dreamer2368 commented Aug 23, 2023

Based on the pybind11 documentation, copy is the default action for STL-type arguments. This means that input/output variables of type std::vector<T> will essentially always involve a deep copy, unless we set a custom casting action.

@chldkdtn , do you have an idea about the typical size of std::vector<int> variables passed into libROM's hyperreduction routines, such as DEIM, GNAT, S_OPT, QDEIM? If they are not so large, then we may not need to do anything particular.

@dreamer2368
Copy link
Collaborator

This is for a future reference. If we do not want to have the 'out-of-box' copy action for std::vector, we have to construct py::list or py::array_t and return them, not directly returning std::vector. See this post.

@chldkdtn
Copy link
Collaborator

Based on the pybind11 documentation, copy is the default action for STL-type arguments. This means that input/output variables of type std::vector<T> will essentially always involve a deep copy, unless we set a custom casting action.

@chldkdtn , do you have an idea about the typical size of std::vector<int> variables passed into libROM's hyperreduction routines, such as DEIM, GNAT, S_OPT, QDEIM? If they are not so large, then we may not need to do anything particular.

Ideally, we do not want it to be big because the whole purpose of the hyper-reduction is to be able to represent a big size of nonlinear vector function with a small number of samples, say 50 or 100 (or perhaps in worst case 1000 at maximum). By the way, this deep copy is only for the output index only, right? which will be part of offline training cost. This should be okay for now, but let's keep it in mind so that in the future, in the context of "on-the-fly," we might need to avoid deep copy to make the efficiency optimized.

@chldkdtn chldkdtn added the RFR Ready for review label Aug 28, 2023
bindings/pylibROM/python_utils/cpp_utils.hpp Outdated Show resolved Hide resolved
bindings/pylibROM/hyperreduction/pyQDEIM.cpp Outdated Show resolved Hide resolved
bindings/pylibROM/hyperreduction/__init__.py Outdated Show resolved Hide resolved
@pravija12345
Copy link
Collaborator Author

pravija12345 commented Aug 30, 2023

Created bindings for the following classes in hyper reduction module:

  • DEIM
  • GNAT
  • QDEIM
  • S_OPT
  • STSampling
  • Utilities

In these classes a key modification has been made to the init_samples parameter. The input argument std::vector *init_samples cannot have a default value nullptr, so, we switched it into std::vector &, and set the default value to be std::vector(0) (Note: These changes doesn't impact the internal execution).

Further more another key modification is made to the parameters f_sampled_row, f_sampled_rows_per_proc, and t_samples which were originally passed as input arguments. As these arguments f_sampled_row, f_sampled_rows_per_proc, and t_samples are STL-type output variables, which cannot change its value if it is passed as an input argument. Therefore it is removed from the input argument list, and the python function returns these variables as tuple if necessary.

@pravija12345 pravija12345 merged commit 4a8b2bc into main Aug 30, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants