diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4eb34133a..ea11aea0f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: # Standard hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: check-added-large-files - id: check-merge-conflict @@ -39,7 +39,7 @@ repos: # Clang format - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v20.1.8 + rev: v21.1.0 hooks: - id: clang-format types_or: [c++, c, cuda] @@ -55,7 +55,7 @@ repos: # Ruff, the Python auto-correcting linter/formatter written in Rust - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.12.5 + rev: v0.12.12 hooks: - id: ruff args: ["--fix", "--show-fixes"] diff --git a/xcsf/pybind_callback.h b/xcsf/pybind_callback.h index 6a67954df..e0d306e9b 100644 --- a/xcsf/pybind_callback.h +++ b/xcsf/pybind_callback.h @@ -38,12 +38,10 @@ extern "C" { */ class Callback { - public: +public: virtual ~Callback() {} - virtual bool - run(struct XCSF *xcsf, py::dict metrics) = 0; + virtual bool run(struct XCSF * xcsf, py::dict metrics) = 0; - virtual void - finish(struct XCSF *xcsf) = 0; + virtual void finish(struct XCSF * xcsf) = 0; }; diff --git a/xcsf/pybind_callback_checkpoint.h b/xcsf/pybind_callback_checkpoint.h index eea88a4c3..f2fee5f26 100644 --- a/xcsf/pybind_callback_checkpoint.h +++ b/xcsf/pybind_callback_checkpoint.h @@ -41,7 +41,7 @@ extern "C" { */ class CheckpointCallback : public Callback { - public: +public: /** * @brief Constructs a new checkpoint callback. * @param [in] monitor Name of the metric to monitor: {"train", "val"}. @@ -74,8 +74,7 @@ class CheckpointCallback : public Callback * @brief Saves the state of XCSF. * @param [in] xcsf The XCSF data structure. */ - void - save(struct XCSF *xcsf) + void save(struct XCSF * xcsf) { xcsf_save(xcsf, filename.c_str()); std::ostringstream status; @@ -90,8 +89,7 @@ class CheckpointCallback : public Callback * @param [in] metrics Dictionary of performance metrics. * @return Whether to terminate training. */ - bool - run(struct XCSF *xcsf, py::dict metrics) override + bool run(struct XCSF * xcsf, py::dict metrics) override { py::list data = metrics[monitor]; py::list trials = metrics["trials"]; @@ -113,15 +111,14 @@ class CheckpointCallback : public Callback * @brief Executes any tasks at the end of fitting. * @param [in] xcsf The XCSF data structure. */ - void - finish(struct XCSF *xcsf) override + void finish(struct XCSF * xcsf) override { if (!save_best_only) { save(xcsf); } } - private: +private: py::str monitor; //!< Name of the metric to monitor std::string filename; //!< Name of the file to save XCSF bool save_best_only; //!< Whether to only save the best population diff --git a/xcsf/pybind_callback_earlystop.h b/xcsf/pybind_callback_earlystop.h index 22da07164..e65d0bf78 100644 --- a/xcsf/pybind_callback_earlystop.h +++ b/xcsf/pybind_callback_earlystop.h @@ -41,7 +41,7 @@ extern "C" { */ class EarlyStoppingCallback : public Callback { - public: +public: /** * @brief Constructs a new early stopping callback. * @param [in] monitor Name of the metric to monitor: {"train", "val"}. @@ -82,8 +82,7 @@ class EarlyStoppingCallback : public Callback * @brief Stores best XCSF population in memory. * @param [in] xcsf The XCSF data structure. */ - void - store(struct XCSF *xcsf) + void store(struct XCSF * xcsf) { do_restore = true; xcsf_store_pset(xcsf); @@ -100,8 +99,7 @@ class EarlyStoppingCallback : public Callback * @brief Retrieves best XCSF population in memory. * @param [in] xcsf The XCSF data structure. */ - void - retrieve(struct XCSF *xcsf) + void retrieve(struct XCSF * xcsf) { do_restore = false; xcsf_retrieve_pset(xcsf); @@ -121,8 +119,7 @@ class EarlyStoppingCallback : public Callback * @param [in] metrics Dictionary of performance metrics. * @return whether early stopping criteria has been met. */ - bool - run(struct XCSF *xcsf, py::dict metrics) override + bool run(struct XCSF * xcsf, py::dict metrics) override { py::list data = metrics[monitor]; py::list trials = metrics["trials"]; @@ -156,15 +153,14 @@ class EarlyStoppingCallback : public Callback * @brief Executes any tasks at the end of fitting. * @param [in] xcsf The XCSF data structure. */ - void - finish(struct XCSF *xcsf) override + void finish(struct XCSF * xcsf) override { if (restore && do_restore) { retrieve(xcsf); } } - private: +private: py::str monitor; //!< Name of the metric to monitor int patience; //!< Stop training after this many trials with no improvement bool restore; //!< Whether to restore the best population