Skip to content

Commit

Permalink
#718: logger: fix use of logger in pressio; add macros for logging; s…
Browse files Browse the repository at this point in the history
…implify initialization in tests
  • Loading branch information
cwschilly committed Feb 5, 2025
1 parent 821a3c6 commit 5941c10
Show file tree
Hide file tree
Showing 55 changed files with 81 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
with:
repository: Pressio/pressio-templates-usage-as-library
path: examples
ref: 2-update-logging-to-use-pressio-log
ref: main

- name: Checkout pressio-log
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-kokkos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
with:
repository: Pressio/pressio-templates-usage-as-library
path: examples
ref: 2-update-logging-to-use-pressio-log
ref: main

- name: Checkout pressio-log
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-trilinos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
with:
repository: Pressio/pressio-templates-usage-as-library
path: examples
ref: 2-update-logging-to-use-pressio-log
ref: main

- name: Checkout pressio-log
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion include/pressio/ode/impl/ode_advance_to_target_time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void to_target_time_with_step_size_policy(StepperType & stepper,
throw std::runtime_error("Violation of minimum time step while trying to recover time step");
}

PRESSIOLOG_ERROR("time step={} failed, retrying with dt={}", step, dt.get());
PRESSIOLOG_WARNING("time step={} failed, retrying with dt={}", step, dt.get());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/pressio/solvers_nonlinear/impl/diagnostics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class DiagnosticsLogger

const auto pd = dm.publicNames();

#if !defined(PRESSIO_ENABLE_INTERNAL_SPDLOG)
#if !defined(PRESSIO_ENABLE_LOGGING)

int rank = 0;
#if defined PRESSIO_ENABLE_TPL_MPI
Expand All @@ -282,7 +282,7 @@ class DiagnosticsLogger
std::cout << "\n";
}
#else
PRESSIOLOG_INFO(rootWithLabels_, iStep, lam(pd[Is], dm[pd[Is]]) ...);
PRESSIOLOG_BASIC(rootWithLabels_, iStep, lam(pd[Is], dm[pd[Is]]) ...);
#endif

}
Expand Down
24 changes: 21 additions & 3 deletions tests/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,30 @@ if (PRESSIO_ENABLE_DEBUG_PRINT)
add_definitions(-DPRESSIO_ENABLE_DEBUG_PRINT)
endif()

option(PRESSIO_ENABLE_INTERNAL_SPDLOG "Enable the use of the internal spdlog" ON)
if (PRESSIO_ENABLE_INTERNAL_SPDLOG)
add_definitions(-DPRESSIO_ENABLE_INTERNAL_SPDLOG)
# LOGGING MACROS

option(PRESSIO_ENABLE_LOGGING "Enable logging via pressio-log" ON)
if (PRESSIO_ENABLE_LOGGING)
add_compile_definitions(PRESSIO_ENABLE_LOGGING=1)
else()
add_compile_definitions(PRESSIO_ENABLE_LOGGING=0)
endif()

option(PRESSIO_SILENCE_WARNINGS "Enable or disable warnings" OFF)
if (PRESSIO_SILENCE_WARNINGS)
add_compile_definitions(PRESSIO_SILENCE_WARNINGS=1)
else ()
add_compile_definitions(PRESSIO_SILENCE_WARNINGS=0)
endif()

option(PRESSIO_ENABLE_COLORIZED_OUTPUT "Enable or disable colorized logging" OFF)
if (PRESSIO_ENABLE_COLORIZED_OUTPUT)
add_compile_definitions(PRESSIO_ENABLE_COLORIZED_OUTPUT=1)
else ()
add_compile_definitions(PRESSIO_ENABLE_COLORIZED_OUTPUT=0)
endif()

# TPLs
option(PRESSIO_ENABLE_TPL_EIGEN "Enable Eigen TPL" ON)
option(PRESSIO_ENABLE_TPL_TRILINOS "Enable Trilinos TPL" OFF)
option(PRESSIO_ENABLE_TPL_KOKKOS "Enable Kokkos TPL" OFF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct MyFakeSolver

int main()
{
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::basic, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::basic);

using app_t = MyApp;
using state_t = typename app_t::state_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ struct FakeNonLinearSolver2{

#define ODE_MASS_MATRIX_CHECK_TEST(NAME) \
std::cout << "\n"; \
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::info, pressiolog::LogTo::console); \
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::info); \
using namespace pressio; \
srand(342556331); \
const auto nsteps = ::pressio::ode::StepCount(4); \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ struct FakeNonLinearSolver2{

#define ODE_MASS_MATRIX_CHECK_TEST(NAME) \
std::cout << "\n"; \
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::info, pressiolog::LogTo::console); \
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::info); \
using namespace pressio; \
srand(342556331); \
const auto nsteps = ::pressio::ode::StepCount(4); \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct MyFakeSolver

int main()
{
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

using app_t = MyApp;
using state_t = typename app_t::state_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct MyFakeSolver

TEST(ode, implicit_bdf1_step_strong_condition_correctness_A)
{
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

using namespace pressio;
using problem_t = MyApp;
Expand Down Expand Up @@ -90,7 +90,7 @@ TEST(ode, implicit_bdf1_step_strong_condition_correctness_A)

TEST(ode, implicit_bdf1_step_strong_condition_correctness_B)
{
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

using namespace pressio;
using problem_t = MyApp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct MyFakeSolver

TEST(ode, implicit_bdf2_step_strong_condition_correctness_A)
{
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

using namespace pressio;
using problem_t = MyApp;
Expand Down Expand Up @@ -118,7 +118,7 @@ TEST(ode, implicit_bdf2_step_strong_condition_correctness_B)
1 1.3
*/

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

using namespace pressio;
using problem_t = MyApp;
Expand Down Expand Up @@ -177,7 +177,7 @@ TEST(ode, implicit_bdf2_step_strong_condition_correctness_C)
1 1.3 1.6 1.8
*/

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

using namespace pressio;
using problem_t = MyApp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ struct MyFakeSolver

TEST(ode, implicit_crank_nicolson_correctness_default_policy)
{
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

using app_t = MyApp;
using state_t = typename app_t::state_type;
Expand All @@ -247,7 +247,7 @@ TEST(ode, implicit_crank_nicolson_correctness_default_policy)

TEST(ode, implicit_crank_nicolson_correctness_custom_policy)
{
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

using app_t = MyApp;
using state_t = typename app_t::state_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ struct MyFakeSolver

TEST(ode, implicit_crank_nicolson_correctness_default_policy)
{
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

using app_t = MyApp;
using state_t = typename app_t::state_type;
Expand All @@ -237,7 +237,7 @@ TEST(ode, implicit_crank_nicolson_correctness_default_policy)

TEST(ode, implicit_crank_nicolson_correctness_custom_policy)
{
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

using app_t = MyApp;
using state_t = typename app_t::state_type;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_small/rom/galerkin_steady/main1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct FakeNonLinSolverSteady
TEST(rom_galerkin_steady, default)
{

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

constexpr int N = 8;
using fom_t = MyFom;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_small/rom/galerkin_steady/main2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TEST(rom_galerkin_steady, default_matrix_free)
just supposed to compile for now
*/

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

constexpr int N = 8;
using fom_t = MyFom;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_small/rom/galerkin_steady/main3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ TEST(rom_galerkin_steady, hyperreduced)
except that we pretend here to do a hyper-reduced problem
*/

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

const int nStencil = 13;
const std::vector<int> validStateIndices = {2,3,4,5,6,10,11,12};
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_small/rom/galerkin_steady/main4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ TEST(rom_galerkin_steady, masked)
{
/* steady galerkin masked */

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

constexpr int N = 13;
/* corrupt indices are those that we mess up on purpose */\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ TEST(rom_galerkin_explicit, default)
rom_state|_step2 = [0,51,102]^T + phi^T f(y_fom, t=1.) = [0, 2611, 5222]
*/

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

// create fom
constexpr int N = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ TEST(rom_galerkin_explicit, hyperreduced_velo_euler_forward)
we fake hypereduction by mimicing a stencil/sample mesh
*/

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

const std::vector<int> sampleMeshIndices = {1,3,5,7,9,11,13,15,17,19};
const int nstencil = 20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ TEST(rom_galerkin_explicit, masked_velo_euler_forward)
is doing the same thing the default galerkin main1.cc
*/

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

constexpr int nFull = 20;\
const std::vector<int> sample_indices = {0,2,4,6,8,10,12,14,16,18};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ TEST(rom_galerkin_explicit, test5)
phi^T f = [70; 140; 210]
*/

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

constexpr int N = 5;
using fom_t = MyFom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ TEST(rom_galerkin_implicit, default_bdf1)
// test for default implicit galerkin using BDF1
// all numbers have been computed manually

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

// create fom
using fom_t = MyFom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ TEST(rom_galerkin_implicit, hyperreduced_bdf1)
// test for hypred implicit galerkin using BDF1
// all numbers have been computed manually

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

const int nStencil = 20;
const int nSample = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ TEST(rom_galerkin_implicit, masked_bdf1)
// test for masked implicit galerkin using BDF1
// all numbers have been computed manually

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

constexpr int nFull = 20;
const std::vector<int> sample_indices = {0,2,4,6,8,10,12,14,16,18};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ TEST(rom_galerkin_implicit, default_fullydiscrete_n2)
{
/* default galerkin impliacit eigen with fully discrete API */

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

constexpr int N = 5;
using fom_t = MyFom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ TEST(rom_galerkin_implicit, default_fullydiscrete_n3)
{
/* default galerkin impliacit eigen with fully discrete API */

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

constexpr int N = 5;
using fom_t = MyFom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ TEST(rom_galerkin_implicit, default_with_massmatrix_bdf1)
{
// implicit default galerkin with mass matrix

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

// create fom
using fom_t = MyFom;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_small/rom/lspg_steady/main1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ TEST(rom_lspg_steady, test1)
- fom applyJac appJac(B) always returns B += 1
*/

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

constexpr int N = 8;
using fom_t = MyFom;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_small/rom/lspg_steady/main2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ TEST(rom_lspg_steady, test2)
{
/* default steady lspg with preconditioning */

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

namespace plspg = pressio::rom::lspg;

Expand Down
2 changes: 1 addition & 1 deletion tests/functional_small/rom/lspg_steady/main3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ TEST(rom_lspg_steady, test3)
steady hyper-reduced lspg
*/

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

const int nStencil = 15;
const int nSample = 8;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_small/rom/lspg_steady/main4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ TEST(rom_lspg_steady, test4)
{
/* steady masked LSPG */

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

const int N = 15;
const std::vector<int> indices_to_corrupt = {1,3,5,7,9,11,13};
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_small/rom/lspg_unsteady/main1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ TEST(rom_lspg_unsteady, test1)
{
/* default lspg eigen */

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

constexpr int N = 8;
using fom_t = MyFom;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_small/rom/lspg_unsteady/main2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ TEST(rom_lspg_unsteady, test2)
{
/* hyper-reduced lspg eigen */

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

const int nstencil = 15;
const std::vector<int> sample_indices = {0,2,4,6,8,10,12,14};
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_small/rom/lspg_unsteady/main3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ TEST(rom_lspg_unsteady, test3)
{
/* masked lspg eigen */

PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug, pressiolog::LogTo::console);
PRESSIOLOG_INITIALIZE(pressiolog::LogLevel::debug);

const std::vector<int> rows_to_corrupt_ = {1,3,5,7,9,11,13};\
const std::vector<int> sample_indices = {0,2,4,6,8,10,12,14};\
Expand Down
Loading

0 comments on commit 5941c10

Please sign in to comment.