Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 6 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ repos:
- repo: https://github.com/rapidsai/pre-commit-hooks
rev: v1.2.1
hooks:
- id: verify-alpha-spec
args:
- --fix
- --mode
- release
- id: verify-copyright
args: [--fix, --spdx]
files: |
Expand Down Expand Up @@ -83,7 +88,5 @@ repos:
entry: python ci/utils/update_doc_versions.py
language: system
files: docs/cuopt/source/versions1.json


default_language_version:
python: python3
python: python3
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class pdlp_solver_settings_t {
method_t method{method_t::Concurrent};
bool inside_mip{false};
// For concurrent termination
volatile int* concurrent_halt{nullptr};
std::atomic<int>* concurrent_halt{nullptr};
static constexpr f_t minimal_absolute_tolerance = 1.0e-12;

private:
Expand Down
5 changes: 5 additions & 0 deletions cpp/src/dual_simplex/branch_and_bound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,7 @@ void branch_and_bound_t<i_t, f_t>::diving_thread(const csr_matrix_t<i_t, f_t>& A
if (get_upper_bound() < start_node->node.lower_bound) { continue; }

bool recompute_bounds_and_basis = true;
i_t nodes_explored = 0;
search_tree_t<i_t, f_t> subtree(std::move(start_node->node));
std::deque<mip_node_t<i_t, f_t>*> stack;
stack.push_front(&subtree.root);
Expand All @@ -1152,6 +1153,8 @@ void branch_and_bound_t<i_t, f_t>::diving_thread(const csr_matrix_t<i_t, f_t>& A

if (toc(exploration_stats_.start_time) > settings_.time_limit) { return; }

if (nodes_explored >= 1000) { break; }

node_solve_info_t status = solve_node(node_ptr,
subtree,
leaf_problem,
Expand All @@ -1165,6 +1168,8 @@ void branch_and_bound_t<i_t, f_t>::diving_thread(const csr_matrix_t<i_t, f_t>& A
start_node->upper,
log);

nodes_explored++;

recompute_bounds_and_basis = !has_children(status);

if (status == node_solve_info_t::TIME_LIMIT) {
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/dual_simplex/branch_and_bound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class branch_and_bound_t {
f_t get_lower_bound();
i_t get_heap_size();
bool enable_concurrent_lp_root_solve() const { return enable_concurrent_lp_root_solve_; }
volatile int* get_root_concurrent_halt() { return &root_concurrent_halt_; }
std::atomic<int>* get_root_concurrent_halt() { return &root_concurrent_halt_; }
void set_root_concurrent_halt(int value) { root_concurrent_halt_ = value; }
lp_status_t solve_root_relaxation(simplex_solver_settings_t<i_t, f_t> const& lp_settings);

Expand Down Expand Up @@ -170,7 +170,7 @@ class branch_and_bound_t {
std::vector<f_t> edge_norms_;
std::atomic<bool> root_crossover_solution_set_{false};
bool enable_concurrent_lp_root_solve_{false};
volatile int root_concurrent_halt_{0};
std::atomic<int> root_concurrent_halt_{0};

// Pseudocosts
pseudo_costs_t<i_t, f_t> pc_;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/dual_simplex/simplex_solver_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ struct simplex_solver_settings_t {
std::function<void()> heuristic_preemption_callback;
std::function<void(std::vector<f_t>&, std::vector<f_t>&, f_t)> set_simplex_solution_callback;
mutable logger_t log;
volatile int* concurrent_halt; // if nullptr ignored, if !nullptr, 0 if solver should
// continue, 1 if solver should halt
std::atomic<int>* concurrent_halt; // if nullptr ignored, if !nullptr, 0 if solver should
// continue, 1 if solver should halt
};

} // namespace cuopt::linear_programming::dual_simplex
2 changes: 1 addition & 1 deletion cpp/src/linear_programming/solve.cu
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void setup_device_symbols(rmm::cuda_stream_view stream_view)
detail::set_pdlp_hyper_parameters(stream_view);
}

volatile int global_concurrent_halt;
std::atomic<int> global_concurrent_halt{0};

template <typename i_t, typename f_t>
optimization_problem_solution_t<i_t, f_t> convert_dual_simplex_sol(
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/mip/diversity/diversity_manager.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class diversity_manager_t {
// mutex for the simplex solution update
std::mutex relaxed_solution_mutex;
// atomic for signalling pdlp to stop
volatile int global_concurrent_halt{0};
std::atomic<int> global_concurrent_halt{0};

rins_t<i_t, f_t> rins;

Expand Down
16 changes: 8 additions & 8 deletions cpp/src/mip/relaxed_lp/relaxed_lp.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
namespace cuopt::linear_programming::detail {

struct relaxed_lp_settings_t {
double tolerance = 1e-4;
double time_limit = 1.0;
bool check_infeasibility = true;
bool return_first_feasible = false;
bool save_state = true;
bool per_constraint_residual = true;
bool has_initial_primal = true;
volatile int* concurrent_halt = nullptr;
double tolerance = 1e-4;
double time_limit = 1.0;
bool check_infeasibility = true;
bool return_first_feasible = false;
bool save_state = true;
bool per_constraint_residual = true;
bool has_initial_primal = true;
std::atomic<int>* concurrent_halt = nullptr;
};

template <typename i_t, typename f_t>
Expand Down
26 changes: 23 additions & 3 deletions cpp/src/utilities/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,26 @@ void reset_default_logger()
default_logger().flush_on(rapids_logger::level_enum::debug);
}

// Guard object whose destructor resets the logger
struct logger_config_guard {
~logger_config_guard() { cuopt::reset_default_logger(); }
};

// Weak reference to detect if any init_logger_t instance is still alive
static std::weak_ptr<logger_config_guard> g_active_guard;
static std::mutex g_guard_mutex;

init_logger_t::init_logger_t(std::string log_file, bool log_to_console)
{
// until this function is called, the default sink is the buffer sink
std::lock_guard<std::mutex> lock(g_guard_mutex);

auto existing_guard = g_active_guard.lock();
if (existing_guard) {
// Reuse existing configuration, just hold a reference to keep it alive
guard_ = existing_guard;
return;
}

cuopt::default_logger().sinks().clear();

// re-initialize sinks
Expand All @@ -164,8 +181,11 @@ init_logger_t::init_logger_t(std::string log_file, bool log_to_console)
for (const auto& entry : buffered_messages) {
cuopt::default_logger().log(entry.level, entry.msg.c_str());
}
}

init_logger_t::~init_logger_t() { cuopt::reset_default_logger(); }
// Create guard and store weak reference for future instances to find
auto guard = std::make_shared<logger_config_guard>();
g_active_guard = guard;
guard_ = guard;
}

} // namespace cuopt
6 changes: 4 additions & 2 deletions cpp/src/utilities/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ rapids_logger::logger& default_logger();
*/
void reset_default_logger();

// Ref-counted logger initializer
class init_logger_t {
// Using shared_ptr for ref-counting
std::shared_ptr<void> guard_;

public:
init_logger_t(std::string log_file, bool log_to_console);

~init_logger_t();
};

} // namespace cuopt
6 changes: 3 additions & 3 deletions python/cuopt/cuopt/linear_programming/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ license = { text = "Apache-2.0" }
requires-python = ">=3.10"
dependencies = [
"numpy>=1.23.5,<3.0a0",
"rapids-logger==0.2.*,>=0.0.0a0",
"rapids-logger==0.2.*",
] # This list was generated by `rapids-dependency-file-generator`. To make changes, edit ../../../../dependencies.yaml and run `rapids-dependency-file-generator`.
classifiers = [
"Intended Audience :: Developers",
Expand All @@ -39,7 +39,7 @@ Source = "https://github.com/nvidia/cuopt"
test = [
"pytest-cov",
"pytest<8",
"rapids-logger==0.2.*,>=0.0.0a0",
"rapids-logger==0.2.*",
] # This list was generated by `rapids-dependency-file-generator`. To make changes, edit ../../../../dependencies.yaml and run `rapids-dependency-file-generator`.

[tool.setuptools]
Expand Down Expand Up @@ -83,5 +83,5 @@ requires = [
"cython>=3.0.3",
"ninja",
"numpy>=1.23.5,<3.0a0",
"rapids-logger==0.2.*,>=0.0.0a0",
"rapids-logger==0.2.*",
] # This list was generated by `rapids-dependency-file-generator`. To make changes, edit ../../../../dependencies.yaml and run `rapids-dependency-file-generator`.
Loading