sandialabs / GenTen

Software for Generalized Tensor Decompositions
Other
4 stars 1 forks source link

How to compute sparse reconstruction using CLI on Windows #2

Open scott-uses-git opened 1 week ago

scott-uses-git commented 1 week ago

Hello,

First of all, I want to say that the algorithms included in this repo are incredible and I really appreciate the work that's gone into them.

I have been running the GCP SGD algorithm on sparse 3-way tensor data on Windows using the Command Line Interface. I want to compute the reconstruction for the non-zeros in my data.

Based on the CLI help documentation, I think these are the corresponding arguments:

Driver options: 
  --output-dense-reconstruction <string>  output file name for saving the tensor reconstruction as a dense tensor
  --output-sparse-reconstruction <string>  output file name for saving the tensor reconstruction as a sparse tensor

Here is the command I am using:

"C:/path/to/GenTen/build/bin/genten.exe" --input data-tensor.txt --output-file model-fit.txt **--output-sparse-reconstruction model-recon.txt** --rank 30 --type poisson --method gcp-sgd --sampling stratified --fit  --maxiters 100 --epochiters 500

This results in an error

Error!  Unknown command line arguments: --output-sparse-reconstruction model-recon.txt 

Am I doing something wrong here? If I remove the "--output-sparse-reconstruction model-recon.txt" from the command line arguments, the model fit is able to run okay.

etphipp commented 1 week ago

Thanks for the comments and reporting this! It looks like the documentation for the command-line argument is incorrect. The correct options appear to be

  --dense-reconstruction <string>  output file name for saving the tensor reconstruction as a dense tensor
  --sparse-reconstruction <string>  output file name for saving the tensor reconstruction as a sparse tensor

(drop the output-). I will fix this shortly.

etphipp commented 1 week ago

This should be fixed now. Let me know if it works for you.

Btw, would you mind sharing how you are building on Windows? I don't have any Windows machines to build/test on myself, and I tried putting together a github actions build here but couldn't get it to work.

scott-uses-git commented 1 week ago

Thanks for getting back to me! I'm glad it was an easy fix. I changed the argument and the program was able to run. However, the program got stuck on generating the reconstruction file. My assumption is that the sparse reconstruction would only reconstruct the non-zero elements, but it seems that the entire tensor is being reconstructed, then dropping zeros and put into sparse format. Is there any way to only reconstruct the non-zeros using GenTen, or would I need to write my own script for this?

I'm completely clueless when it comes to C++, so I used Claude AI to help me build. Here is a set of instructions written by Claude, including dependencies for build: genten-windows-installation-guide.md. This build process was pretty painful to be honest. Is there any plan to release pre-built binaries in the future for Windows/MacOS/Linux?

Additionally, I got an error while building

C:\path\to\GenTen\src\Genten_Annealer.hpp:99:74: error: 'M_PI' was not declared
in this scope
   99 |            0.5 * (max_lr - min_lr) * (1 + std::cos(ttb_real(Tcur) / Ti * M_PI));
      |                                                                          ^~~~
mingw32-make[2]: *** [CMakeFiles\gentenlib.dir\build.make:766: CMakeFiles/gentenlib.dir/src/Genten_GCP_SGD.cpp.obj] Error 1

Claude recommended a simple fix by adding these lines to Genten_Annealer.hpp, right after the last #include statement,:

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

Claude's Explanation:

Origin of the issue: 'M_PI' is defined in the header on many systems, but it's not guaranteed to be available everywhere, especially on Windows with certain compiler settings. Potential fixes: a) The simplest fix would be to explicitly define M_PI in the code. This could be done by adding the following at the top of the file: cppCopy#ifndef M_PI

define M_PI 3.14159265358979323846

endif

b) Another approach is to use std::numbers::pi from C++20, but this requires C++20 support. c) Ensure that the correct headers are included and that the appropriate preprocessor definitions are set.

etphipp commented 1 week ago

Thanks for the info, this is helpful. I had not tried to go the MinGW route (theoretically Kokkos builds just fine natively under Windows, so GenTen should too).

There are already pre-built binaries for Linux available through pip as described here but that's really only useful if you are using GenTen through python (the executables are included in the pip binary installation, but the step that makes the python module "universal" across linux distros appears to break the genten executables). I've tried to provide pre-built binaries for MacOS as well, but the python module doesn't seem to work correctly. However, for both Linux and MacOS, you can have pip build from source, which does work:

pip install --no-binary pygenten pygenten