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

Add QDEIM option to some examples #229

Merged
merged 14 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ dependencies
*.log
*.status

# Do not track backup files
*~

# Do not track autogenerated config headers
CAROM_config.h
FCMangle.h
Expand Down
147 changes: 49 additions & 98 deletions examples/prom/mixed_nonlinear_diffusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,57 @@
// Analytic test (reproductive)
// mpirun -n 1 ./mixed_nonlinear_diffusion -offline
// mpirun -n 1 ./mixed_nonlinear_diffusion -merge -ns 1
// mpirun -n 1 ./mixed_nonlinear_diffusion -online -rrdim 8 -rwdim 8 -nldim 20 -nsdim 20
// mpirun -n 1 ./mixed_nonlinear_diffusion -online -rrdim 8 -rwdim 8 -nldim 20 -nsdim 20 -sopt
// mpirun -n 1 ./mixed_nonlinear_diffusion -online -rrdim 8 -rwdim 8 -nldim 20 -nsdim 20 -hrtype deim
// mpirun -n 1 ./mixed_nonlinear_diffusion -online -rrdim 8 -rwdim 8 -nldim 20 -nsdim 20 -hrtype qdeim
// mpirun -n 1 ./mixed_nonlinear_diffusion -online -rrdim 8 -rwdim 8 -nldim 20 -nsdim 20 -hrtype sopt
// mpirun -n 1 ./mixed_nonlinear_diffusion -online -rrdim 8 -rwdim 8 -nldim 20 -nsdim 20 -ns 1 -eqp
//
// Relative l2 error of ROM solution at final timestep using DEIM sampling: 1.096776797994166e-08
Copy link
Member

Choose a reason for hiding this comment

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

I believe this result corresponds to -hrtype deim? Perhaps we should report the example results for Q-DEIM and S-OPT here and in the libROM webpage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My first thought was not to add it, because the QDEIM result is almost the same as DEIM. For completeness, I went ahead and added it. I agree that the webpage should be updated as well, to let users know about the QDEIM option.
I actually updated all the run times. Reporting run times is troublesome, because they vary even on the same machine. When a new result is added, all runs have to be updated for a fair comparison.

// Elapsed time for time integration loop using DEIM sampling: 0.6351594580000001
// Elapsed time for time integration loop using DEIM sampling: 0.5686423310000001
// Relative l2 error of ROM solution at final timestep using QDEIM sampling: 1.227055339859034e-08
// Elapsed time for time integration loop using QDEIM sampling: 0.575228571
// Relative l2 error of ROM solution at final timestep using S_OPT sampling: 1.01945081122054e-08
// Elapsed time for time integration loop using S_OPT sampling: 0.6669736559999999
// Relative l2 error of ROM solution at final timestep using EQP: 1.46205848438194e-07
// Elapsed time for time integration loop using EQP: 0.431521853
// Elapsed time for time integration loop using S_OPT sampling: 0.5311964850000001
// Relative l2 error of ROM solution at final timestep using EQP: 1.052559143494963e-08
// Elapsed time for time integration loop using EQP: 0.346165296
//
// Note that the timing of the time integration loop does not include setup,
// which can be greater for S_OPT and EQP than for DEIM.
//
// Initial step test (reproductive)
// mpirun -n 1 ./mixed_nonlinear_diffusion -offline -p 1
// mpirun -n 1 ./mixed_nonlinear_diffusion -merge -ns 1 -p 1
// mpirun -n 1 ./mixed_nonlinear_diffusion -online -rrdim 8 -rwdim 8 -nldim 20 -p 1
// mpirun -n 1 ./mixed_nonlinear_diffusion -online -rrdim 8 -rwdim 8 -nldim 20 -p 1 -sopt
// mpirun -n 1 ./mixed_nonlinear_diffusion -online -rrdim 8 -rwdim 8 -nldim 20 -p 1 -hrtype deim
// mpirun -n 1 ./mixed_nonlinear_diffusion -online -rrdim 8 -rwdim 8 -nldim 20 -p 1 -hrtype sopt
// mpirun -n 1 ./mixed_nonlinear_diffusion -online -rrdim 8 -rwdim 8 -nldim 20 -p 1 -ns 1 -eqp
//
// Relative l2 error of ROM solution at final timestep using DEIM sampling: 0.0003712362376412496
// Elapsed time for time integration loop using DEIM sampling: 0.364855569
// Elapsed time for time integration loop using DEIM sampling: 0.339288686
// Relative l2 error of ROM solution at final timestep using QDEIM sampling: 0.000375066186385267
// Elapsed time for time integration loop using QDEIM sampling: 0.32320409
// Relative l2 error of ROM solution at final timestep using S_OPT sampling: 0.0003797338657417907
// Elapsed time for time integration loop using S_OPT sampling: 0.300462563
// Relative l2 error of ROM solution at final timestep using EQP sampling: 0.0003710336208386964
// Elapsed time for time integration loop using EQP sampling: 0.481740662
// Elapsed time for time integration loop using S_OPT sampling: 0.32422266
// Relative l2 error of ROM solution at final timestep using EQP sampling: 0.0003709977143117392
// Elapsed time for time integration loop using EQP sampling: 0.457011311
//
// Initial step parametric test (predictive)
// mpirun -n 1 ./mixed_nonlinear_diffusion -p 1 -offline -id 0 -sh 0.25
// mpirun -n 1 ./mixed_nonlinear_diffusion -p 1 -offline -id 1 -sh 0.15
// mpirun -n 1 ./mixed_nonlinear_diffusion -p 1 -offline -id 2 -sh 0.35
// mpirun -n 1 ./mixed_nonlinear_diffusion -p 1 -merge -ns 3
// mpirun -n 1 ./mixed_nonlinear_diffusion -p 1 -offline -id 3 -sh 0.3
// mpirun -n 1 ./mixed_nonlinear_diffusion -p 1 -online -rrdim 8 -rwdim 8 -nldim 20 -sh 0.3 -id 3
// mpirun -n 1 ./mixed_nonlinear_diffusion -p 1 -online -rrdim 8 -rwdim 8 -nldim 20 -sh 0.3 -id 3 -sopt
// mpirun -n 1 ./mixed_nonlinear_diffusion -p 1 -online -rrdim 8 -rwdim 8 -nldim 20 -sh 0.3 -id 3 -hrtype deim
// mpirun -n 1 ./mixed_nonlinear_diffusion -p 1 -online -rrdim 8 -rwdim 8 -nldim 20 -sh 0.3 -id 3 -hrtype sopt
// mpirun -n 1 ./mixed_nonlinear_diffusion -p 1 -online -rrdim 8 -rwdim 8 -nldim 20 -sh 0.3 -id 3 -ns 3 -eqp -maxnnls 30
//
// Relative l2 error of ROM solution at final timestep using DEIM sampling: 0.002681387312231006
// Elapsed time for time integration loop using DEIM sampling: 0.355846074
// Elapsed time for time integration loop using DEIM sampling: 0.359206509
// Relative l2 error of ROM solution at final timestep using QDEIM sampling: 0.00266355670204476
// Elapsed time for time integration loop using QDEIM sampling: 0.309432016
// Relative l2 error of ROM solution at final timestep using S_OPT sampling: 0.002701713369494112
// Elapsed time for time integration loop using S_OPT sampling: 0.348985935
// Elapsed time for time integration loop using S_OPT sampling: 0.41139788
// Relative l2 error of ROM solution at final timestep using EQP: 0.002659978000520714
// Elapsed time for time integration loop using EQP sampling: 0.176821221
// Elapsed time for time integration loop using EQP sampling: 0.164961644
//
// Pointwise snapshots for DMD input
// mpirun -n 1 ./mixed_nonlinear_diffusion -pwsnap -pwx 101 -pwy 101
Expand All @@ -90,9 +97,7 @@
#include "linalg/BasisGenerator.h"
#include "linalg/BasisReader.h"
#include "linalg/NNLS.h"
#include "hyperreduction/DEIM.h"
#include "hyperreduction/GNAT.h"
#include "hyperreduction/S_OPT.h"
#include "hyperreduction/Hyperreduction.h"
#include "mfem/SampleMesh.hpp"
#include "mfem/PointwiseSnapshot.hpp"

Expand Down Expand Up @@ -550,7 +555,7 @@ int main(int argc, char *argv[])
bool offline = false;
bool merge = false;
bool online = false;
bool use_sopt = false;
const char *samplingType = "deim";
bool use_eqp = false;
bool writeSampleMesh = false;
int num_samples_req = -1;
Expand Down Expand Up @@ -619,8 +624,8 @@ int main(int argc, char *argv[])
"Enable or disable the online phase.");
args.AddOption(&merge, "-merge", "--merge", "-no-merge", "--no-merge",
"Enable or disable the merge phase.");
args.AddOption(&use_sopt, "-sopt", "--sopt", "-no-sopt", "--no-sopt",
"Use S-OPT sampling instead of DEIM for the hyperreduction.");
args.AddOption(&samplingType, "-hrtype", "--hrsamplingtype",
"Sampling type for hyperreduction.");
Copy link
Member

Choose a reason for hiding this comment

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

I recommend adding different hyper-reduction sampling types in the regression test for this example, similar to the mixed nonlinear diffusion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

args.AddOption(&num_samples_req, "-nsr", "--nsr",
"Number of samples for the sampling algorithm to select.");
args.AddOption(&use_eqp, "-eqp", "--eqp", "-no-eqp", "--no-eqp",
Expand Down Expand Up @@ -950,8 +955,6 @@ int main(int argc, char *argv[])
CAROM::BasisReader readerFR("basisFR");
FR_librom = readerFR.getSpatialBasis(0.0);

// Compute sample points using DEIM, for hyperreduction

if (nldim == -1)
{
nldim = FR_librom->numColumns();
Expand Down Expand Up @@ -1005,6 +1008,7 @@ int main(int argc, char *argv[])
else
{
// Setup hyperreduction using DEIM, GNAT, or S-OPT
CAROM::Hyperreduction hr(samplingType);
vector<int> num_sample_dofs_per_proc(num_procs);

if (num_samples_req != -1)
Expand All @@ -1019,44 +1023,15 @@ int main(int argc, char *argv[])
// Now execute the chosen sampling algorithm to get the sampling information.
Bsinv = new CAROM::Matrix(nsamp_R, nldim, false);
vector<int> sample_dofs(nsamp_R); // Indices of the sampled rows
if (use_sopt)
{
if (myid == 0)
printf("Using S_OPT sampling\n");
CAROM::S_OPT(FR_librom,
nldim,
sample_dofs,
num_sample_dofs_per_proc,
*Bsinv,
myid,
num_procs,
nsamp_R);
}
else if (nsamp_R != nldim)
{
if (myid == 0)
printf("Using GNAT sampling\n");
CAROM::GNAT(FR_librom,
nldim,
sample_dofs,
num_sample_dofs_per_proc,
*Bsinv,
myid,
num_procs,
nsamp_R);
}
else
{
if (myid == 0)
printf("Using DEIM sampling\n");
CAROM::DEIM(FR_librom,
nldim,
sample_dofs,
num_sample_dofs_per_proc,
*Bsinv,
myid,
num_procs);
}

hr.ComputeSamples(FR_librom,
nldim,
sample_dofs,
num_sample_dofs_per_proc,
*Bsinv,
myid,
num_procs,
nsamp_R);

vector<int> sample_dofs_S; // Indices of the sampled rows
vector<int> num_sample_dofs_per_proc_S(num_procs);
Expand All @@ -1068,8 +1043,6 @@ int main(int argc, char *argv[])
readerS = new CAROM::BasisReader("basisS");
S_librom = readerS->getSpatialBasis(0.0);

// Compute sample points using DEIM

if (nsdim == -1)
{
nsdim = S_librom->numColumns();
Expand All @@ -1083,7 +1056,7 @@ int main(int argc, char *argv[])
if (myid == 0)
printf("reduced S dim = %d\n",nsdim);

// Now execute the DEIM algorithm to get the sampling information.
// Now use a hyperreduction method to compute samples.
if (num_samples_req != -1)
{
nsamp_S = num_samples_req;
Expand All @@ -1095,38 +1068,16 @@ int main(int argc, char *argv[])

Ssinv = new CAROM::Matrix(nsamp_S, nsdim, false);
sample_dofs_S.resize(nsamp_S);
if (use_sopt)
{
CAROM::S_OPT(S_librom,
nsdim,
sample_dofs_S,
num_sample_dofs_per_proc_S,
*Ssinv,
myid,
num_procs,
nsamp_S);
}
else if (nsamp_S != nsdim)
{
CAROM::GNAT(S_librom,
nsdim,
sample_dofs_S,
num_sample_dofs_per_proc_S,
*Ssinv,
myid,
num_procs,
nsamp_S);
}
else
{
CAROM::DEIM(S_librom,
nsdim,
sample_dofs_S,
num_sample_dofs_per_proc_S,
*Ssinv,
myid,
num_procs);
}


hr.ComputeSamples(S_librom,
nsdim,
sample_dofs_S,
num_sample_dofs_per_proc_S,
*Ssinv,
myid,
num_procs,
nsamp_S);
}

// Construct sample mesh
Expand Down
Loading