Skip to content

Commit

Permalink
feat: Add Python 3.11 support to macOS workflow
Browse files Browse the repository at this point in the history
The macOS workflow now installs Python 3.11 using Homebrew and links it as the default version.

fix: Update logging statements in Ergodic_moves_3.hpp

Replaced `fmt::print` with `spdlog::info` for logging the number of cells in the triangulation after adding new cells. Also added a warning log if the triangulation is not valid.

refactor: Include Move_command.hpp in Metropolis.hpp and Move_always.hpp

Added an include statement for Move_command.hpp in both Metropolis.hpp and Move_always.hpp.

refactor: Improve comments and documentation in MoveCommand class

Updated comments and documentation for various member functions of the MoveCommand class to provide more clarity on their purpose and usage.

refactor: Improve comments and documentation in MoveStrategy class

Improved comments and documentation for the MoveStrategy class, specifying that it selects a move algorithm based on the chosen strategy enum value.

fix: Handle invalid results in cdt-opt.cpp and cdt.cpp

Added error handling code to throw runtime_error if the result is invalid. Updated catch blocks to handle runtime_error exceptions separately, printing an appropriate error message.
  • Loading branch information
acgetchell committed Nov 25, 2023
1 parent 6930537 commit 947ec03
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 30 deletions.
1 change: 1 addition & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- name: Setup
run: |
brew install automake autoconf autoconf-archive libtool texinfo yasm ninja python ccache pkg-config
brew link --overwrite [email protected]
- name: Restore artifacts or setup vcpkg
uses: lukka/run-vcpkg@v11
Expand Down
9 changes: 6 additions & 3 deletions include/Ergodic_moves_3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,15 +725,18 @@ namespace ergodic_moves
// get the n_x's right

#ifndef NDEBUG
fmt::print("Cells in the triangulation after adding new cells: {}\n",
triangulation.number_of_cells());
spdlog::info("Cells in the triangulation after adding new cells: {}\n",
triangulation.number_of_cells());
#endif

// Fix any cell orientation issues
if (!triangulation.is_valid()) { triangulation.tds().reorient(); }

#ifndef NDEBUG
triangulation.tds().is_valid(true, 1);
if (!triangulation.tds().is_valid(true, 1))
{
spdlog::warn("Triangulation is not valid.\n");
}
#endif

// Check validity of cells
Expand Down
1 change: 1 addition & 0 deletions include/Metropolis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define INCLUDE_METROPOLIS_HPP_

// CDT headers
#include "Move_command.hpp"
#include "Move_strategy.hpp"
#include "S3Action.hpp"

Expand Down
1 change: 1 addition & 0 deletions include/Move_always.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef INCLUDE_MOVE_ALWAYS_HPP_
#define INCLUDE_MOVE_ALWAYS_HPP_

#include "Move_command.hpp"
#include "Move_strategy.hpp"

/// @brief The Move Always algorithm
Expand Down
73 changes: 54 additions & 19 deletions include/Move_command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,63 +41,86 @@ class MoveCommand
Counter m_failed;

public:
/// @brief No default ctor
/**
* \brief Remove default ctor
*/
MoveCommand() = delete;

/// @brief MoveCommand ctor
/// @details The manifold to be moved should be copied by value into the
/// MoveCommand to ensure moves are done atomically and either succeed
/// or fail and can be discarded without affecting the original.
/// @param t_manifold The manifold to perform moves upon
/**
* \brief MoveCommand ctor
* \param t_manifold The manifold to perform moves on
* \details The manifold to perform moves upon should be copied by value into
* the MoveCommand to ensure moves are executed atomically and either succeed
* or fail and can be discarded without affecting the original manifold.
*/
explicit MoveCommand(ManifoldType t_manifold)
: m_manifold{std::move(t_manifold)}
{}

/// @returns A read-only reference to the manifold
/**
* \return A read-only reference to the manifold
*/
auto get_const_results() const -> ManifoldType const&
{
return std::cref(m_manifold);
} // get_const_results

/// @returns The results of the moves invoked by MoveCommand
/**
* \return Results of the moves invoked by MoveCommand
*/
[[nodiscard]] auto get_results() -> ManifoldType& { return m_manifold; }

/// @returns Attempted moves by MoveCommand
/**
* \return Attempted moves by MoveCommand
*/
[[nodiscard]] auto get_attempted() const -> Counter const&
{
return m_attempted;
} // get_attempts

/// @returns Successful moves by MoveCommand
/**
* \return Successful moves by MoveCommand
*/
[[nodiscard]] auto get_succeeded() const
{
return m_succeeded;
} // get_succeeded

/// @returns Failed moves by MoveCommand
/**
* \return Failed moves by MoveCommand
*/
[[nodiscard]] auto get_failed() const -> Counter const&
{
return m_failed;
} // get_errors

/// @brief Reset the counters
/**
* \brief Reset counters
*/
void reset_counters()
{
m_attempted.reset();
m_succeeded.reset();
m_failed.reset();
}

/// @brief Push a Pachner move onto the move queue
/// @param t_move The move function object to do on the manifold
/**
* \brief Push a Pachner move onto the move queue
* \param t_move The move to add
*/
void enqueue(move_tracker::move_type const t_move)
{
m_moves.push_front(t_move);
}

/**
* \return The number of moves on the queue
*/
auto size() const { return m_moves.size(); }

/// Execute all moves in the queue on the manifold
/**
* \brief Execute all moves in the queue on the manifold
*/
void execute()
{
#ifndef NDEBUG
Expand Down Expand Up @@ -139,7 +162,13 @@ class MoveCommand
#endif
} // execute

auto as_move_function(move_tracker::move_type const move) -> FunctionType
/**
* \brief Execute a move function on a manifold
* \param move The move to execute
* \return The move function to execute
*/
static auto as_move_function(move_tracker::move_type const move)
-> FunctionType
{
switch (move)
{
Expand All @@ -151,7 +180,9 @@ class MoveCommand
}
} // move_function

/// @brief Print attempted moves
/**
* \brief Print attempted moves
*/
void print_attempts() const
{
if (ManifoldType::dimension == 3)
Expand Down Expand Up @@ -182,7 +213,9 @@ class MoveCommand
}
}

/// @brief Print successful moves
/**
* \brief Print successful moves
*/
void print_successful() const
{
if (ManifoldType::dimension == 3)
Expand Down Expand Up @@ -216,7 +249,9 @@ class MoveCommand
}
}

/// @brief Print Move errors
/**
* \brief Print move errors
*/
void print_errors() const
{
if (std::all_of(m_failed.moves_view().begin(), m_failed.moves_view().end(),
Expand Down
13 changes: 8 additions & 5 deletions include/Move_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
#ifndef INCLUDE_MOVE_ALGORITHM_HPP_
#define INCLUDE_MOVE_ALGORITHM_HPP_

#include "Move_command.hpp"

/// @brief The algorithms available to make ergodic moves
/**
* \brief The algorithms available to make ergodic moves on triangulations
*/
enum class Strategies
{
MOVE_ALWAYS,
METROPOLIS
};

/// @brief Select an algorithm to make ergodic moves upon triangulations
/// @tparam strategies The algorithm that chooses ergodic moves
/**
* \brief Select a move algorithm
* \tparam strategies The move algorithm to use
* \tparam ManifoldType The manifold to perform moves on
*/
template <Strategies strategies, typename ManifoldType>
class MoveStrategy
{};
Expand Down
7 changes: 6 additions & 1 deletion src/cdt-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ try
max_timevalue);
}

assert(result.is_valid());
if (!result.is_valid()) { throw runtime_error("Result is invalid!\n"); }

// Print results
fmt::print("=== Run Results ===\n");
Expand All @@ -67,6 +67,11 @@ try

return EXIT_SUCCESS;
}
catch (runtime_error const& RuntimeError)
{
spdlog::critical("{}\n", RuntimeError.what());
return EXIT_FAILURE;
}
catch (...)
{
spdlog::critical("Something went wrong ... Exiting.\n");
Expand Down
9 changes: 7 additions & 2 deletions src/cdt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ try
max_timevalue);
}

assert(result.is_valid());
if (!result.is_valid()) { throw runtime_error("Result is invalid!\n"); }

// Output results
// Print results
timer.stop(); // End running time counter
fmt::print("=== Run Results ===\n");
fmt::print("Running time is {} seconds.\n", timer.time());
Expand Down Expand Up @@ -197,6 +197,11 @@ catch (logic_error const& LogicError)
spdlog::critical("Simulation startup failed ... Exiting.\n");
return EXIT_FAILURE;
}
catch (runtime_error const& RuntimeError)
{
spdlog::critical("{}\n", RuntimeError.what());
return EXIT_FAILURE;
}
catch (...)
{
spdlog::critical("Something went wrong ... Exiting.\n");
Expand Down

0 comments on commit 947ec03

Please sign in to comment.