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

refactor: Log level documentation on SolverBase and children #3230

Merged
merged 81 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
fbe6085
Add a way to expend the description of a wrapper
MelReyCG Apr 3, 2024
de6c78e
loglevel first iteration
arng40 Apr 25, 2024
55ef101
log level documentation sorted
arng40 May 16, 2024
b55bb04
log-level doc correction
arng40 May 17, 2024
d333678
enable log level + small corretion appendLogLevel
arng40 May 21, 2024
12da842
melvin review ( archi updated )
arng40 May 21, 2024
65d8ae9
renaming / constness / refacto
arng40 May 21, 2024
f957cea
uncrustify
arng40 May 21, 2024
69f94df
Merge remote-tracking branch 'origin/develop' into feature/dudes/log-…
arng40 May 21, 2024
8de5703
add missing log
arng40 May 22, 2024
a720b27
update comment
arng40 May 22, 2024
dcf4fa7
adding new doc + update
arng40 May 24, 2024
78badfa
update solver log
arng40 May 24, 2024
0c32b52
log message correction
arng40 May 24, 2024
ed7a285
doc corrections
arng40 May 27, 2024
c3cdc0d
rst added
arng40 Jun 19, 2024
de56ea7
Merge remote-tracking branch 'origin/develop' into feature/dudes/log-…
arng40 Jun 20, 2024
b47ffe8
fix and updates rst
arng40 Jun 20, 2024
c56f007
small update
arng40 Jun 27, 2024
640d1e0
add structure refacto (not working)
arng40 Jul 16, 2024
0bb745c
Merge remote-tracking branch 'origin/develop' into feature/dudes/log-…
arng40 Jul 16, 2024
ab6ddf9
beginning cohabitation witk old code
arng40 Jul 16, 2024
a8ac94c
compilation almost done
arng40 Jul 17, 2024
1553255
add traits to addLogLevel and fix compilation
arng40 Jul 18, 2024
2d9a4c9
add a macro, empty loglevelRegistry and some fix
arng40 Jul 19, 2024
548759d
add doxygen
arng40 Jul 19, 2024
dc9d1c3
omission and blank space first pass
arng40 Jul 23, 2024
f9cab87
melvin review
arng40 Jul 23, 2024
bb83468
2nd pass
arng40 Jul 23, 2024
93f29b9
blank space and unused comment
arng40 Jul 23, 2024
56683ed
uncrustify
arng40 Jul 23, 2024
9c718b3
do_not_document added for log info
arng40 Jul 23, 2024
b23046e
whitespaces removed
arng40 Jul 23, 2024
3d09a53
add end_cond
arng40 Jul 23, 2024
e36b700
doxygen
arng40 Jul 23, 2024
92127b4
missing doc
arng40 Jul 23, 2024
4ce039a
revert some minor changes
arng40 Jul 23, 2024
dfd6f3f
SAME
arng40 Jul 23, 2024
511fa2e
whitespace
arng40 Jul 23, 2024
6d57229
.
arng40 Jul 23, 2024
5a59f9f
melvin review #2
arng40 Jul 24, 2024
a46fea6
rst
arng40 Jul 24, 2024
8a4298d
xsd
arng40 Aug 20, 2024
7bb1dda
Merge remote-tracking branch 'origin/develop' into feature/dudes/log-…
arng40 Aug 20, 2024
ebc4156
reset log message on hydro
arng40 Aug 20, 2024
633880f
fix error on cmake
arng40 Aug 21, 2024
95f00b8
path updated
arng40 Aug 23, 2024
53e8dff
log level rt verification
arng40 Aug 23, 2024
6e96732
Revert "log level rt verification"
arng40 Aug 23, 2024
e516144
update GEOS_LOG_INFO to GEOS_LOG
arng40 Aug 23, 2024
e67bc3f
reorganized log info file
arng40 Aug 29, 2024
f8359bb
reorganization of function + realeased earlier m_logLevelsRegistry
arng40 Aug 30, 2024
e4d184d
uncrustify
arng40 Aug 30, 2024
67b21ef
Merge remote-tracking branch 'origin/develop' into feature/dudes/log-…
arng40 Aug 30, 2024
ebf7ccf
const function added
arng40 Aug 30, 2024
cbf01ee
rst updated
arng40 Aug 30, 2024
84122ee
fix compil crash by removing unecassery line on cmake event
arng40 Aug 30, 2024
a7a3813
Merge remote-tracking branch 'origin/develop' into feature/dudes/log-…
arng40 Sep 16, 2024
6aa91ad
update on description
arng40 Sep 16, 2024
3164e56
Merge branch 'develop' into feature/dudes/log-level-doc-poc
rrsettgast Sep 24, 2024
0b129a6
xsd
arng40 Sep 24, 2024
8526e0b
Merge branch 'feature/dudes/log-level-doc-poc' of https://github.com/…
arng40 Sep 24, 2024
2257c3c
xsd
arng40 Sep 25, 2024
f770091
Merge branch 'feature/dudes/log-level-doc-poc' of https://github.com/…
arng40 Sep 25, 2024
1fbe2ba
remove rst
arng40 Sep 25, 2024
13912db
remove rst
arng40 Sep 25, 2024
aeb0988
remove unacessary loglevel + 1st description correction
arng40 Oct 1, 2024
f449224
line search and implit step desc updated
arng40 Oct 1, 2024
8ba8cd9
hydrau descrption solverTimeStep unnecessary
arng40 Oct 1, 2024
5d33273
refactor: log levels solvers (#3378)
paveltomin Oct 3, 2024
0b2d8c2
Merge remote-tracking branch 'origin/develop' into feature/dudes/log-…
arng40 Oct 3, 2024
2ec2398
update CMFVM
arng40 Oct 3, 2024
9c173d7
add macro GEOS_LOG_LEVEL_INFO_RANK_0_NLR
arng40 Oct 4, 2024
b794899
uncrustify
arng40 Oct 4, 2024
6d63f14
move/add log structure & small correction
arng40 Oct 8, 2024
9fed5a3
attempt to fix doxy
arng40 Oct 8, 2024
8719562
space
arng40 Oct 8, 2024
d2fb32e
fix doxygen
arng40 Oct 8, 2024
430090f
Merge branch 'develop' into feature/dudes/log-level-doc-poc
MelReyCG Oct 8, 2024
f16c6ce
revert loglevel
arng40 Oct 9, 2024
e7242f0
revert loglevel
arng40 Oct 9, 2024
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
1 change: 1 addition & 0 deletions src/coreComponents/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set( common_headers
GEOS_RAJA_Interface.hpp
GeosxMacros.hpp
MemoryInfos.hpp
logger/Logger.hpp
MpiWrapper.hpp
Path.hpp
Span.hpp
Expand Down
18 changes: 18 additions & 0 deletions src/coreComponents/common/logger/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@
} \
} while( false )

/**
* @brief Conditionally log a message on screen on rank 0 without line breaking.
* @param EXP an expression that will be evaluated as a predicate
* @param msg a message to log (any expression that can be stream inserted)
*/
#define GEOS_LOG_RANK_0_IF_NLR( EXP, msg ) \
do { \
if( ::geos::logger::internal::rank == 0 && EXP ) \
{ \
std::ostringstream oss; \
oss << msg; \
std::cout << oss.str(); \
} \
} while( false )

/**
* @brief Log a message on screen on rank 0.
* @param msg a message to log (any expression that can be stream inserted)
Expand Down Expand Up @@ -456,20 +471,23 @@
* @brief Output messages based on current Group's log level.
* @param[in] minLevel minimum log level
* @param[in] msg a message to log (any expression that can be stream inserted)
* @deprecated Will be replaced by GEOS_LOG_LEVEL_INFO
MelReyCG marked this conversation as resolved.
Show resolved Hide resolved
*/
#define GEOS_LOG_LEVEL( minLevel, msg ) GEOS_LOG_IF( this->getLogLevel() >= minLevel, msg );

/**
* @brief Output messages (only on rank 0) based on current Group's log level.
* @param[in] minLevel minimum log level
* @param[in] msg a message to log (any expression that can be stream inserted)
* @deprecated Will be replaced by GEOS_LOG_LEVEL_INFO_RANK_0
*/
#define GEOS_LOG_LEVEL_RANK_0( minLevel, msg ) GEOS_LOG_RANK_0_IF( this->getLogLevel() >= minLevel, msg )

/**
* @brief Output messages (with one line per rank) based on current Group's log level.
* @param[in] minLevel minimum log level
* @param[in] msg a message to log (any expression that can be stream inserted)
* @deprecated Will be replaced by GEOS_LOG_LEVEL_INFO_BY_RANK
*/
#define GEOS_LOG_LEVEL_BY_RANK( minLevel, msg ) GEOS_LOG_RANK_IF( this->getLogLevel() >= minLevel, msg )

Expand Down
3 changes: 3 additions & 0 deletions src/coreComponents/dataRepository/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ set( dataRepository_headers
InputFlags.hpp
KeyIndexT.hpp
KeyNames.hpp
LogLevelsInfo.hpp
LogLevelsRegistry.hpp
MappedVector.hpp
ObjectCatalog.hpp
ReferenceWrapper.hpp
Expand All @@ -35,6 +37,7 @@ set( dataRepository_sources
xmlWrapper.cpp
DataContext.cpp
GroupContext.cpp
LogLevelsRegistry.cpp
WrapperContext.cpp )

set( dependencyList ${parallelDeps} codingUtilities )
Expand Down
3 changes: 2 additions & 1 deletion src/coreComponents/dataRepository/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Group::Group( string const & name,
m_restart_flags( RestartFlags::WRITE_AND_READ ),
m_input_flags( InputFlags::INVALID ),
m_conduitNode( rootNode[ name ] ),
m_logLevelsRegistry( std::make_unique< LogLevelsRegistry >() ),
m_dataContext( std::make_unique< GroupContext >( *this ) )
{}

Expand Down Expand Up @@ -80,7 +81,6 @@ void Group::deregisterWrapper( string const & name )
m_conduitNode.remove( name );
}


void Group::resize( indexType const newSize )
{
forWrappers( [newSize] ( WrapperBase & wrapper )
Expand Down Expand Up @@ -245,6 +245,7 @@ void Group::processInputFile( xmlWrapper::xmlNode const & targetNode,

void Group::postInputInitializationRecursive()
{
m_logLevelsRegistry = nullptr;
for( auto const & subGroupIter : m_subGroups )
{
subGroupIter.second->postInputInitializationRecursive();
Expand Down
39 changes: 38 additions & 1 deletion src/coreComponents/dataRepository/Group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "RestartFlags.hpp"
#include "Wrapper.hpp"
#include "xmlWrapper.hpp"
#include "LogLevelsInfo.hpp"
#include "LogLevelsRegistry.hpp"


#include <iostream>
Expand Down Expand Up @@ -863,6 +865,16 @@ class Group
///@}
//END_SPHINX_INCLUDE_REGISTER_WRAPPER

/**
* @brief Append a levelCondition and a log description to the description of the wrapped object given a log info struct.
* Must be called in constructor.
* @tparam LOG_LEVEL_INFO The log documentation to add.
* @return void if the trait is verified.
*/
template< typename LOG_LEVEL_INFO >
std::enable_if_t< geos::is_log_level_info< LOG_LEVEL_INFO >, void >
addLogLevel();
MelReyCG marked this conversation as resolved.
Show resolved Hide resolved

/**
* @name Schema generation methods
*/
Expand Down Expand Up @@ -1478,7 +1490,9 @@ class Group
*/
void loadFromConduit();

/// Enable verbosity input for object
/**
* @deprecated will be remove and replace by addLogLevel
*/
void enableLogLevelInput();

/**
Expand Down Expand Up @@ -1615,6 +1629,8 @@ class Group

/// Verbosity flag for group logs
integer m_logLevel;


//END_SPHINX_INCLUDE_02

/// Restart flag for this group... and subsequently all wrappers in this group.
Expand All @@ -1626,6 +1642,9 @@ class Group
/// Reference to the conduit::Node that mirrors this group
conduit::Node & m_conduitNode;

// Keep track of log levels & descriptions
std::unique_ptr< LogLevelsRegistry > m_logLevelsRegistry;

/// A DataContext object used to provide contextual information on this Group,
/// if it is created from an input XML file, the line or offset in that file.
std::unique_ptr< DataContext > m_dataContext;
Expand Down Expand Up @@ -1712,6 +1731,24 @@ Wrapper< T > & Group::registerWrapper( string const & name,
return rval;
}

template< typename LOG_LEVEL_INFO >
std::enable_if_t< geos::is_log_level_info< LOG_LEVEL_INFO >, void >
Group::addLogLevel()
{
GEOS_ERROR_IF( m_logLevelsRegistry == nullptr, "You cannot call addLogLevel after schema generation" );

Wrapper< integer > * wrapper = getWrapperPointer< integer >( viewKeyStruct::logLevelString() );
rrsettgast marked this conversation as resolved.
Show resolved Hide resolved
if( wrapper == nullptr )
{
wrapper = &registerWrapper( viewKeyStruct::logLevelString(), &m_logLevel );
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose this implicitly adds a logLevel wrapper to the Group. Would there be a danger of calling this outside a Group constructor and changing the schema?

Copy link
Contributor Author

@arng40 arng40 Aug 30, 2024

Choose a reason for hiding this comment

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

Good point, all m_logLevelsRegistry is set to nullptr in postInputInitializationRecursive , afer the schema generation, so I've added a GEOS_ERROR_IF in addLogLevel to check if m_logLevelsRegistry is set to nullptr

Copy link
Contributor

@MelReyCG MelReyCG Aug 30, 2024

Choose a reason for hiding this comment

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

@dkachuma
It indeed adds the logLevel wrapper, as enableLogLevel() did before this PR.
Calling it during or after the postInputInitialization phase will generate an error as the LogLevelRegistry are released (Group.cpp:248).

Your point applies to all Wrapper descriptions, we may generalize this solution for all of them later.
Maybe the descriptions should only be generated when ProblemManager::generateDocumentation() would be called?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@MelReyCG, yes I think that would be better. A compile time check would be preferable IMO but it's not obvious to me how we could do it.

Copy link
Contributor

@MelReyCG MelReyCG Oct 7, 2024

Choose a reason for hiding this comment

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

Just an idea: we could do that by adding a general GeneratedDocsRegistry that would only be created & used during ProblemManager::generateDocumentation(). This way we would not need any compile-time check.
It could have a generic GenerateDescription< GROUP_T >() method that could be implemented to generate & store the Wrapper documentation for each Group types (in their respective CPP files).
This way we could free the documentation generation & storage from the simulation runs, and the documentation would be stored at only one place rather than in each Wrapper instance of each Group. Also, it doesn't rely on adding more virtual methods to Group nor Wrapper.
From my point of view, it would also clarify a bit where & when the documentation is generated and needed.

wrapper->setApplyDefaultValue( 0 );
wrapper->setInputFlag( InputFlags::OPTIONAL );
}
m_logLevelsRegistry->addEntry( LOG_LEVEL_INFO::getMinLogLevel(),
LOG_LEVEL_INFO::getDescription() );
wrapper->setDescription( m_logLevelsRegistry->buildLogLevelDescription());
}

} /* end namespace dataRepository */
} /* end namespace geos */

Expand Down
90 changes: 90 additions & 0 deletions src/coreComponents/dataRepository/LogLevelsInfo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: LGPL-2.1-only
*
* Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
* Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2018-2020 TotalEnergies
* Copyright (c) 2019- GEOSX Contributors
* All rights reserved
*
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
* ------------------------------------------------------------------------------------------------------------
*/

/**
* @file LogLevelsInfo.hpp
* This file contains log level information infrastructure and the mecanism to ensure LOG_LEVEL_INFO structure is valid
*/
#ifndef GEOS_COMMON_LOGLEVELSINFO_HPP
#define GEOS_COMMON_LOGLEVELSINFO_HPP

#include "common/DataTypes.hpp"
#include "common/format/Format.hpp"

namespace geos
{

/**
* @brief Trait used to check whether a LOG_LEVEL_INFO structure is valid.
MelReyCG marked this conversation as resolved.
Show resolved Hide resolved
* @tparam LOG_LEVEL_INFO The log level structure to check.
*
* A log level structure must have this following
* struct LogName
* {
* static constexpr int getMinLogLevel() { return 1; }
* static constexpr std::string_view getDescription() { return "Log level description"; }
* };
*/
template< typename LOG_LEVEL_INFO >
static constexpr bool is_log_level_info =
std::is_same_v< integer, decltype(LOG_LEVEL_INFO::getMinLogLevel()) > &&
std::is_same_v< std::string_view, decltype(LOG_LEVEL_INFO::getDescription()) >;

/**
* @brief Verify if a log level is active
* @tparam LOG_LEVEL_INFO The structure containing log level information.
* @param level Log level to be checked.
* @return `true` if the log level is active, `false` otherwise.
* @pre `LOG_LEVEL_INFO` must satisfy `logInfo::is_log_level_info`.
*
*/
template< typename LOG_LEVEL_INFO >
std::enable_if_t< is_log_level_info< LOG_LEVEL_INFO >, bool >
isLogLevelActive( integer level )
{
return level >= LOG_LEVEL_INFO::getMinLogLevel();
}

/** ThOSE 3 macros would replace the ones in Logger.hpp */
/**
* @brief Output messages based on current Group's log level.
* @param[in] logInfoStruct Strut containing log level desscription
* @param[in] msg a message to log (any expression that can be stream inserted)
*/
#define GEOS_LOG_LEVEL_INFO( logInfoStruct, msg ) GEOS_LOG_IF( isLogLevelActive< logInfoStruct >( this->getLogLevel() ), msg );

/**
* @brief Output messages (only on rank 0) based on current Group's log level.
* @param[in] logInfoStruct Strut containing log level desscription
* @param[in] msg a message to log (any expression that can be stream inserted)
*/
#define GEOS_LOG_LEVEL_INFO_RANK_0( logInfoStruct, msg ) GEOS_LOG_RANK_0_IF( isLogLevelActive< logInfoStruct >( this->getLogLevel() ), msg );

/**
* @brief Output messages (with one line per rank) based on current Group's log level.
* @param[in] logInfoStruct Strut containing log level desscription
* @param[in] msg a message to log (any expression that can be stream inserted)
*/
#define GEOS_LOG_LEVEL_INFO_BY_RANK( logInfoStruct, msg ) GEOS_LOG_RANK_IF( isLogLevelActive< logInfoStruct >( this->getLogLevel() ), msg );

/**
* @brief Output messages (only on rank 0) based on current Group's log level without the line return.
* @param[in] logInfoStruct Strut containing log level desscription
* @param[in] msg a message to log (any expression that can be stream inserted)
*/
#define GEOS_LOG_LEVEL_INFO_RANK_0_NLR( logInfoStruct, msg ) GEOS_LOG_RANK_0_IF_NLR( isLogLevelActive< logInfoStruct >( this->getLogLevel() ), msg );

}

#endif // GEOS_COMMON_LOGLEVELSINFO_HPP
43 changes: 43 additions & 0 deletions src/coreComponents/dataRepository/LogLevelsRegistry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: LGPL-2.1-only
*
* Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
* Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2018-2020 TotalEnergies
* Copyright (c) 2019- GEOSX Contributors
* All rights reserved
*
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
* ------------------------------------------------------------------------------------------------------------
*/

#include "LogLevelsRegistry.hpp"

namespace geos
{

void LogLevelsRegistry::addEntry( integer condition, std::string_view description )
{
m_logLevelsDescriptions[condition].push_back( string( description ) );
}

string LogLevelsRegistry::buildLogLevelDescription() const
{
std::ostringstream description;
description << "Sets the level of information to write in the standard output (the console typically).\n"
"Level 0 outputs no specific information for this solver. Higher levels require more outputs.";
for( auto const & [logLevel, logDescriptions] : m_logLevelsDescriptions )
{
description << GEOS_FMT( "\n{}\n", logLevel );
for( size_t idxDesc = 0; idxDesc < logDescriptions.size(); idxDesc++ )
{
description << " - " << logDescriptions[idxDesc];
if( idxDesc != logDescriptions.size() - 1 )
description << '\n';
}
}
return description.str();
}

}
60 changes: 60 additions & 0 deletions src/coreComponents/dataRepository/LogLevelsRegistry.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: LGPL-2.1-only
*
* Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
* Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2018-2020 TotalEnergies
* Copyright (c) 2019- GEOSX Contributors
* All rights reserved
*
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
* ------------------------------------------------------------------------------------------------------------
*/

/**
* @file LogLevelsRegistry.hpp
*/

#ifndef GEOS_COMMON_LOGLEVELSREGISTRY_HPP
#define GEOS_COMMON_LOGLEVELSREGISTRY_HPP

#include "common/DataTypes.hpp"
#include "common/format/Format.hpp"

namespace geos
{

/**
* @brief Keep track of log level documention for a group
*/
class LogLevelsRegistry
{
public:

/**
* @brief Add a log description for a wrapper
* @param level The minimum log level
* @param description The description for the log level
*/
void addEntry( integer level, std::string_view description );

/**
* @brief Construct the log level string description for a wrapper
* @return The log level string description
*/
string buildLogLevelDescription() const;

private:

/**
* @brief Map for building the log level string for each wrapper.
* key : a logLevel condition, values : a set of description for a corresponding loglevel.
*/
std::map< integer, std::vector< std::string > > m_logLevelsDescriptions;

};

}

#endif
3 changes: 2 additions & 1 deletion src/coreComponents/physicsSolvers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ set( physicsSolvers_headers
SolverBase.hpp
SolverBaseKernels.hpp
SolverStatistics.hpp
FieldStatisticsBase.hpp )
FieldStatisticsBase.hpp
LogLevelsInfo.hpp )

# Specify solver sources
set( physicsSolvers_sources
Expand Down
Loading
Loading