From b6f452e74cfcc97aca196ddfec2c56bd9a5db363 Mon Sep 17 00:00:00 2001 From: Emily Boudreaux Date: Sat, 6 Dec 2025 11:41:57 -0500 Subject: [PATCH] feat(libconfig): new version of libconfig --- .gitignore | 3 ++ build-config/fourdst/meson.build | 1 - build-extra/pkg-config/meson.build | 1 - meson.build | 2 + meson_options.txt | 1 + src/include/gridfire/config/config.h | 35 ++++++++++++++ src/include/gridfire/engine/engine_graph.h | 3 +- .../gridfire/engine/views/engine_adaptive.h | 7 +-- .../gridfire/engine/views/engine_defined.h | 8 ++-- src/include/gridfire/io/network_file.h | 7 ++- .../solver/strategies/CVODE_solver_strategy.h | 3 +- src/lib/engine/views/engine_adaptive.cpp | 4 +- .../strategies/CVODE_solver_strategy.cpp | 8 ++-- subprojects/fourdst.wrap | 2 +- tests/graphnet_sandbox/meson.build | 2 +- tools/config/generate_config_files.cpp | 48 +++++++++++++++++++ tools/config/meson.build | 1 + tools/meson.build | 3 ++ 18 files changed, 118 insertions(+), 21 deletions(-) create mode 100644 src/include/gridfire/config/config.h create mode 100644 tools/config/generate_config_files.cpp create mode 100644 tools/config/meson.build create mode 100644 tools/meson.build diff --git a/.gitignore b/.gitignore index 3e455cda..ba8f29b2 100644 --- a/.gitignore +++ b/.gitignore @@ -82,6 +82,7 @@ subprojects/cvode-*/ subprojects/kinsol-*/ subprojects/CLI11-*/ subprojects/openssl-*/ +subprojects/tomlplusplus-*/ *.fbundle *.wraplock @@ -98,6 +99,8 @@ liblogging.wrap libplugin.wrap minizip-ng.wrap openssl.wrap +glaze.wrap +tomlplusplus.wrap .vscode/ diff --git a/build-config/fourdst/meson.build b/build-config/fourdst/meson.build index 98a2c9a5..d2b092a0 100644 --- a/build-config/fourdst/meson.build +++ b/build-config/fourdst/meson.build @@ -30,7 +30,6 @@ endif libcomposition = fourdst_sp.get_variable('libcomposition') libconst = fourdst_sp.get_variable('libconst') -libconfig = fourdst_sp.get_variable('libconfig') liblogging = fourdst_sp.get_variable('liblogging') if get_option('plugin_support') diff --git a/build-extra/pkg-config/meson.build b/build-extra/pkg-config/meson.build index 56f2f016..b95f8bd3 100644 --- a/build-extra/pkg-config/meson.build +++ b/build-extra/pkg-config/meson.build @@ -8,7 +8,6 @@ if get_option('pkg_config') libraries: [ libgridfire, libcomposition, - libconfig, libconst, liblogging ], diff --git a/meson.build b/meson.build index 59b34f7d..b7e88d36 100644 --- a/meson.build +++ b/meson.build @@ -38,6 +38,8 @@ subdir('build-python') # Buil the test suite subdir('tests') +subdir('tools') + # Build the pkg-config file subdir('build-extra/pkg-config') diff --git a/meson_options.txt b/meson_options.txt index f22e89ed..ffaaf308 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -8,3 +8,4 @@ option('unsafe_fortran', type: 'boolean', value: false, description: 'Allow unte option('plugin_support', type: 'boolean', value: false, description: 'Enable support for libplugin plugins') option('python_target_version', type: 'string', value: '3.13', description: 'Target version for python compilation, only used for cross compilation') option('build_c_api', type: 'boolean', value: true, description: 'compile the C API') +option('build_tools', type: 'boolean', value: true, description: 'build the GridFire command line tools') diff --git a/src/include/gridfire/config/config.h b/src/include/gridfire/config/config.h new file mode 100644 index 00000000..9c807503 --- /dev/null +++ b/src/include/gridfire/config/config.h @@ -0,0 +1,35 @@ +#pragma once + +#include "fourdst/config/config.h" + +namespace gridfire::config { + struct CVODESolverConfig { + double absTol = 1.0e-8; + double relTol = 1.0e-5; + }; + + struct SolverConfig { + CVODESolverConfig cvode; + }; + + struct AdaptiveEngineViewConfig { + double relativeCullingThreshold = 1.0e-75; + }; + + struct EngineViewConfig { + AdaptiveEngineViewConfig adaptiveEngineView; + }; + + struct EngineConfig { + EngineViewConfig views; + + }; + + struct GridFireConfig { + SolverConfig solver; + EngineConfig engine; + }; + + + +} \ No newline at end of file diff --git a/src/include/gridfire/engine/engine_graph.h b/src/include/gridfire/engine/engine_graph.h index 17652b1c..0e044f7d 100644 --- a/src/include/gridfire/engine/engine_graph.h +++ b/src/include/gridfire/engine/engine_graph.h @@ -12,6 +12,7 @@ #include "gridfire/screening/screening_types.h" #include "gridfire/partition/partition_abstract.h" #include "gridfire/engine/procedures/construction.h" +#include "gridfire/config/config.h" #include #include @@ -855,7 +856,7 @@ namespace gridfire::engine { const GraphEngine& m_engine; }; private: - Config& m_config = Config::getInstance(); + Config m_config; quill::Logger* m_logger = LogManager::getInstance().getLogger("log"); constants m_constants; diff --git a/src/include/gridfire/engine/views/engine_adaptive.h b/src/include/gridfire/engine/views/engine_adaptive.h index e0f14c16..59d461cc 100644 --- a/src/include/gridfire/engine/views/engine_adaptive.h +++ b/src/include/gridfire/engine/views/engine_adaptive.h @@ -4,6 +4,7 @@ #include "gridfire/screening/screening_abstract.h" #include "gridfire/screening/screening_types.h" #include "gridfire/types/types.h" +#include "gridfire/config/config.h" #include "fourdst/atomic/atomicSpecies.h" #include "fourdst/config/config.h" @@ -386,10 +387,10 @@ namespace gridfire::engine { */ [[nodiscard]] SpeciesStatus getSpeciesStatus(const fourdst::atomic::Species &species) const override; private: - using Config = fourdst::config::Config; using LogManager = fourdst::logging::LogManager; - /** @brief A reference to the singleton Config instance, used for retrieving configuration parameters. */ - Config& m_config = Config::getInstance(); + + fourdst::config::Config m_config; + /** @brief A pointer to the logger instance, used for logging messages. */ quill::Logger* m_logger = LogManager::getInstance().getLogger("log"); diff --git a/src/include/gridfire/engine/views/engine_defined.h b/src/include/gridfire/engine/views/engine_defined.h index c0f2f33b..16da8efd 100644 --- a/src/include/gridfire/engine/views/engine_defined.h +++ b/src/include/gridfire/engine/views/engine_defined.h @@ -6,6 +6,8 @@ #include "gridfire/io/network_file.h" #include "gridfire/types/types.h" +#include "gridfire/config/config.h" + #include "fourdst/config/config.h" #include "fourdst/logging/logging.h" @@ -365,9 +367,9 @@ namespace gridfire::engine { [[nodiscard]] std::string getNetworkFile() const { return m_fileName; } [[nodiscard]] const io::NetworkFileParser& getParser() const { return m_parser; } private: - using Config = fourdst::config::Config; - using LogManager = fourdst::logging::LogManager; - Config& m_config = Config::getInstance(); + using LogManager = LogManager; + Config m_config; + quill::Logger* m_logger = LogManager::getInstance().getLogger("log"); std::string m_fileName; ///< Parser for the network file. diff --git a/src/include/gridfire/io/network_file.h b/src/include/gridfire/io/network_file.h index 6f25e312..54a7f5b0 100644 --- a/src/include/gridfire/io/network_file.h +++ b/src/include/gridfire/io/network_file.h @@ -2,6 +2,7 @@ #include "fourdst/config/config.h" #include "fourdst/logging/logging.h" +#include "gridfire/config/config.h" #include "quill/Logger.h" @@ -101,9 +102,8 @@ namespace gridfire::io { */ [[nodiscard]] ParsedNetworkData parse(const std::string& filename) const override; private: - using Config = fourdst::config::Config; using LogManager = fourdst::logging::LogManager; - Config& m_config = Config::getInstance(); + fourdst::config::Config m_config; quill::Logger* m_logger = LogManager::getInstance().getLogger("log"); }; @@ -141,9 +141,8 @@ namespace gridfire::io { */ [[nodiscard]] ParsedNetworkData parse(const std::string& filename) const override; private: - using Config = fourdst::config::Config; using LogManager = fourdst::logging::LogManager; - Config& m_config = Config::getInstance(); + fourdst::config::Config m_config; quill::Logger* m_logger = LogManager::getInstance().getLogger("log"); std::string m_filename; diff --git a/src/include/gridfire/solver/strategies/CVODE_solver_strategy.h b/src/include/gridfire/solver/strategies/CVODE_solver_strategy.h index 1cc4f454..42c41580 100644 --- a/src/include/gridfire/solver/strategies/CVODE_solver_strategy.h +++ b/src/include/gridfire/solver/strategies/CVODE_solver_strategy.h @@ -4,6 +4,7 @@ #include "gridfire/engine/engine_abstract.h" #include "gridfire/types/types.h" #include "gridfire/exceptions/exceptions.h" +#include "gridfire/config/config.h" #include "fourdst/atomic/atomicSpecies.h" #include "fourdst/config/config.h" @@ -243,7 +244,7 @@ namespace gridfire::solver { }; private: - fourdst::config::Config& m_config = fourdst::config::Config::getInstance(); + fourdst::config::Config m_config; quill::Logger* m_logger = fourdst::logging::LogManager::getInstance().getLogger("log"); /** * @brief CVODE RHS C-wrapper that delegates to calculate_rhs and captures exceptions. diff --git a/src/lib/engine/views/engine_adaptive.cpp b/src/lib/engine/views/engine_adaptive.cpp index 9feee9da..a1956d3e 100644 --- a/src/lib/engine/views/engine_adaptive.cpp +++ b/src/lib/engine/views/engine_adaptive.cpp @@ -394,7 +394,9 @@ namespace gridfire::engine { const double maxFlow ) const { LOG_TRACE_L1(m_logger, "Culling reactions based on flow rates..."); - const auto relative_culling_threshold = m_config.get("gridfire:AdaptiveEngineView:RelativeCullingThreshold", 1e-75); + + const auto relative_culling_threshold = m_config->engine.views.adaptiveEngineView.relativeCullingThreshold; + double absoluteCullingThreshold = relative_culling_threshold * maxFlow; LOG_DEBUG(m_logger, "Relative culling threshold: {:7.3E} ({:7.3E})", relative_culling_threshold, absoluteCullingThreshold); std::vector culledReactions; diff --git a/src/lib/solver/strategies/CVODE_solver_strategy.cpp b/src/lib/solver/strategies/CVODE_solver_strategy.cpp index 7d430481..01e2727e 100644 --- a/src/lib/solver/strategies/CVODE_solver_strategy.cpp +++ b/src/lib/solver/strategies/CVODE_solver_strategy.cpp @@ -112,8 +112,8 @@ namespace gridfire::solver { // 2. If the user has set tolerances in code, those override the config // 3. If the user has not set tolerances in code and the config does not have them, use hardcoded defaults - auto absTol = m_config.get("gridfire:solver:CVODESolverStrategy:absTol", 1.0e-8); - auto relTol = m_config.get("gridfire:solver:CVODESolverStrategy:relTol", 1.0e-5); + auto absTol = m_config->solver.cvode.absTol; + auto relTol = m_config->solver.cvode.relTol; if (m_absTol) { absTol = *m_absTol; @@ -935,8 +935,8 @@ namespace gridfire::solver { sunrealtype *y_data = N_VGetArrayPointer(m_Y); sunrealtype *y_err_data = N_VGetArrayPointer(m_YErr); - const auto absTol = m_config.get("gridfire:solver:CVODESolverStrategy:absTol", 1.0e-8); - const auto relTol = m_config.get("gridfire:solver:CVODESolverStrategy:relTol", 1.0e-8); + const auto absTol = m_config->solver.cvode.absTol; + const auto relTol = m_config->solver.cvode.relTol; std::vector err_ratios; const size_t num_components = N_VGetLength(m_Y); diff --git a/subprojects/fourdst.wrap b/subprojects/fourdst.wrap index 3466edab..a805e371 100644 --- a/subprojects/fourdst.wrap +++ b/subprojects/fourdst.wrap @@ -1,4 +1,4 @@ [wrap-git] url = https://github.com/4D-STAR/fourdst -revision = v0.9.13 +revision = v0.9.14 depth = 1 diff --git a/tests/graphnet_sandbox/meson.build b/tests/graphnet_sandbox/meson.build index 41e4300c..ef538396 100644 --- a/tests/graphnet_sandbox/meson.build +++ b/tests/graphnet_sandbox/meson.build @@ -1,5 +1,5 @@ executable( 'graphnet_sandbox', 'main.cpp', - dependencies: [gridfire_dep, composition_dep, cli11_dep], + dependencies: [gridfire_dep, cli11_dep], ) diff --git a/tools/config/generate_config_files.cpp b/tools/config/generate_config_files.cpp new file mode 100644 index 00000000..122faa64 --- /dev/null +++ b/tools/config/generate_config_files.cpp @@ -0,0 +1,48 @@ +#include "fourdst/config/config.h" +#include "gridfire/config/config.h" +#include +#include + +#include "CLI/CLI.hpp" + +consteval std::string_view strip_namespaces(const std::string_view fullName) { + const size_t pos = fullName.rfind("::"); + if (pos == std::string_view::npos) { + return fullName; + } + return fullName.substr(pos + 2); +} + +template +consteval std::string_view get_type_name() { + constexpr std::string_view name = std::source_location::current().function_name(); + const auto pos = name.find("T = "); + if (pos == std::string_view::npos) return name; + const auto start = pos + 4; + const auto end = name.rfind(']'); + return name.substr(start, end - start); +} + +int main(int argc, char** argv) { + CLI::App app{"GridFire Sandbox Application."}; + + std::string outputPath = "."; + + app.add_option("-p,--path", outputPath, "path to save generated config files (default: current directory)"); + + CLI11_PARSE(app, argc, argv); + + const std::filesystem::path outPath(outputPath); + if (!std::filesystem::exists(outPath)) { + std::cerr << "Error: The specified path does not exist: " << outputPath << std::endl; + return 1; + } + + fourdst::config::Config configConfig; + const std::string_view name = strip_namespaces(get_type_name()); + + const std::string defaultConfigFilePath = (outPath / (std::string(name) + ".toml")).string(); + const std::string schemaFilePath = (outPath / (std::string(name) + ".schema.json")).string(); + configConfig.save(defaultConfigFilePath); + configConfig.save_schema(schemaFilePath); +} \ No newline at end of file diff --git a/tools/config/meson.build b/tools/config/meson.build new file mode 100644 index 00000000..f19f277b --- /dev/null +++ b/tools/config/meson.build @@ -0,0 +1 @@ +executable('gf_generate_config_file', 'generate_config_files.cpp', dependencies: [gridfire_dep, cli11_dep], install: true) \ No newline at end of file diff --git a/tools/meson.build b/tools/meson.build new file mode 100644 index 00000000..75f2745b --- /dev/null +++ b/tools/meson.build @@ -0,0 +1,3 @@ +if get_option('build_tools') + subdir('config') +endif \ No newline at end of file