From 1fdd7d6be30ae355d9e11bae9527c6859f1e2f5f Mon Sep 17 00:00:00 2001 From: akifcorduk Date: Wed, 23 Jul 2025 05:27:15 -0700 Subject: [PATCH 1/5] fix bug on initial solution size in the check --- .../utilities/problem_checking.cu | 13 +++++++++++++ cpp/src/mip/diversity/diversity_manager.cu | 6 +++--- cpp/src/mip/utils.cuh | 14 +++++++------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/cpp/src/linear_programming/utilities/problem_checking.cu b/cpp/src/linear_programming/utilities/problem_checking.cu index 57f10e55b..d0fc6811b 100644 --- a/cpp/src/linear_programming/utilities/problem_checking.cu +++ b/cpp/src/linear_programming/utilities/problem_checking.cu @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -73,6 +74,18 @@ void problem_checking_t::check_initial_primal_representation( "has size %zu, while objective vector has size %zu.", primal_initial_solution.size(), op_problem.get_objective_coefficients().size()); + cuopt_expects(!thrust::any_of(op_problem.get_handle_ptr()->get_thrust_policy(), + thrust::make_counting_iterator(0), + thrust::make_counting_iterator(0) + op_problem.get_n_variables(), + [lower_bounds = make_span(op_problem.get_variable_lower_bounds()), + upper_bounds = make_span(op_problem.get_variable_upper_bounds()), + assignment_span = make_span(primal_initial_solution), + int_tol = 1e-8] __device__(i_t idx) { + return assignment_span[idx] < lower_bounds[idx] - int_tol || + assignment_span[idx] > upper_bounds[idx] + int_tol; + }), + error_type_t::ValidationError, + "Initial solution violates variable bounds."); } } diff --git a/cpp/src/mip/diversity/diversity_manager.cu b/cpp/src/mip/diversity/diversity_manager.cu index a05a9063b..fb83f4c30 100644 --- a/cpp/src/mip/diversity/diversity_manager.cu +++ b/cpp/src/mip/diversity/diversity_manager.cu @@ -216,7 +216,7 @@ void diversity_manager_t::add_user_given_solutions( cuopt_func_call(sol.test_variable_bounds(true)); CUOPT_LOG_INFO("Adding initial solution success! feas %d objective %f excess %f", is_feasible, - sol.get_objective(), + sol.get_user_objective(), sol.get_total_excess()); population.run_solution_callbacks(sol); initial_sol_vector.emplace_back(std::move(sol)); @@ -226,7 +226,7 @@ void diversity_manager_t::add_user_given_solutions( Assignment size %lu \ initial solution size %lu", sol.assignment.size(), - init_sol->size()); + init_sol_assignment.size()); } } } @@ -796,12 +796,12 @@ void diversity_manager_t::set_simplex_solution(const std::vector& { CUOPT_LOG_DEBUG("Setting simplex solution with objective %f", objective); using sol_t = solution_t; + RAFT_CUDA_TRY(cudaSetDevice(context.handle_ptr->get_device())); cuopt_func_call(sol_t new_sol(*problem_ptr)); cuopt_func_call(new_sol.copy_new_assignment(solution)); cuopt_func_call(new_sol.compute_feasibility()); cuopt_assert(integer_equal(new_sol.get_user_objective(), objective, 1e-3), "Objective mismatch"); std::lock_guard lock(relaxed_solution_mutex); - RAFT_CUDA_TRY(cudaSetDevice(context.handle_ptr->get_device())); simplex_solution_exists = true; global_concurrent_halt.store(1, std::memory_order_release); // it is safe to use lp_optimal_solution while executing the copy operation diff --git a/cpp/src/mip/utils.cuh b/cpp/src/mip/utils.cuh index b48ad21b6..18759737d 100644 --- a/cpp/src/mip/utils.cuh +++ b/cpp/src/mip/utils.cuh @@ -346,13 +346,13 @@ bool has_variable_bounds_violation(const raft::handle_t* handle_ptr, problem_t* problem_ptr) { auto const assignment_span = make_span(assignment); - return thrust::any_of( - handle_ptr->get_thrust_policy(), - thrust::make_counting_iterator(0), - thrust::make_counting_iterator(0) + problem_ptr->original_problem_ptr->get_n_variables(), - [assignment_span, problem_view = problem_ptr->view()] __device__(i_t idx) { - return !problem_view.check_variable_within_bounds(idx, assignment_span[idx]); - }); + return thrust::any_of(handle_ptr->get_thrust_policy(), + thrust::make_counting_iterator(0), + thrust::make_counting_iterator(0) + problem_ptr->n_variables, + [assignment_span, problem_view = problem_ptr->view()] __device__(i_t idx) { + return !problem_view.check_variable_within_bounds(idx, + assignment_span[idx]); + }); } } // namespace cuopt::linear_programming::detail From 06a52e982f2d976589cd182f4a8bd6547c067bce Mon Sep 17 00:00:00 2001 From: akifcorduk Date: Thu, 24 Jul 2025 02:17:16 -0700 Subject: [PATCH 2/5] fix bug of resizing late --- cpp/src/mip/diversity/diversity_manager.cu | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cpp/src/mip/diversity/diversity_manager.cu b/cpp/src/mip/diversity/diversity_manager.cu index fb83f4c30..610d15bea 100644 --- a/cpp/src/mip/diversity/diversity_manager.cu +++ b/cpp/src/mip/diversity/diversity_manager.cu @@ -320,6 +320,13 @@ bool diversity_manager_t::run_presolve(f_t time_limit) if (!check_bounds_sanity(*problem_ptr)) { return false; } } stats.presolve_time = presolve_timer.elapsed_time(); + // after every change to the problem, we should resize all the relevant vars + // we need to encapsulate that to prevent repetitions + lp_optimal_solution.resize(problem_ptr->n_variables, problem_ptr->handle_ptr->get_stream()); + ls.resize_vectors(*problem_ptr, problem_ptr->handle_ptr); + ls.lb_constraint_prop.temp_problem.setup(*problem_ptr); + ls.lb_constraint_prop.bounds_update.setup(ls.lb_constraint_prop.temp_problem); + ls.constraint_prop.bounds_update.resize(*problem_ptr); return true; } @@ -390,13 +397,6 @@ solution_t diversity_manager_t::run_solver() // to automatically compute the solving time on scope exit auto timer_raii_guard = cuopt::scope_guard([&]() { stats.total_solve_time = timer.elapsed_time(); }); - // after every change to the problem, we should resize all the relevant vars - // we need to encapsulate that to prevent repetitions - lp_optimal_solution.resize(problem_ptr->n_variables, problem_ptr->handle_ptr->get_stream()); - ls.resize_vectors(*problem_ptr, problem_ptr->handle_ptr); - ls.lb_constraint_prop.temp_problem.setup(*problem_ptr); - ls.lb_constraint_prop.bounds_update.setup(ls.lb_constraint_prop.temp_problem); - ls.constraint_prop.bounds_update.resize(*problem_ptr); problem_ptr->check_problem_representation(true); // have the structure ready for reusing later problem_ptr->compute_integer_fixed_problem(); @@ -796,8 +796,10 @@ void diversity_manager_t::set_simplex_solution(const std::vector& { CUOPT_LOG_DEBUG("Setting simplex solution with objective %f", objective); using sol_t = solution_t; + context.handle_ptr->sync_stream(); RAFT_CUDA_TRY(cudaSetDevice(context.handle_ptr->get_device())); cuopt_func_call(sol_t new_sol(*problem_ptr)); + cuopt_assert(new_sol.assignment.size() == solution.size(), "Assignment size mismatch"); cuopt_func_call(new_sol.copy_new_assignment(solution)); cuopt_func_call(new_sol.compute_feasibility()); cuopt_assert(integer_equal(new_sol.get_user_objective(), objective, 1e-3), "Objective mismatch"); From 4f5f5ca385b3f2c39d835384a38dfa6a6bc90272 Mon Sep 17 00:00:00 2001 From: akifcorduk Date: Thu, 24 Jul 2025 04:43:26 -0700 Subject: [PATCH 3/5] add sync stream --- cpp/src/mip/diversity/diversity_manager.cu | 1 + 1 file changed, 1 insertion(+) diff --git a/cpp/src/mip/diversity/diversity_manager.cu b/cpp/src/mip/diversity/diversity_manager.cu index 610d15bea..2e050980f 100644 --- a/cpp/src/mip/diversity/diversity_manager.cu +++ b/cpp/src/mip/diversity/diversity_manager.cu @@ -327,6 +327,7 @@ bool diversity_manager_t::run_presolve(f_t time_limit) ls.lb_constraint_prop.temp_problem.setup(*problem_ptr); ls.lb_constraint_prop.bounds_update.setup(ls.lb_constraint_prop.temp_problem); ls.constraint_prop.bounds_update.resize(*problem_ptr); + problem_ptr->handle_ptr->sync_stream(); return true; } From addd6cffc8853db6d2327988bab9294b324907fa Mon Sep 17 00:00:00 2001 From: akifcorduk Date: Thu, 24 Jul 2025 05:13:55 -0700 Subject: [PATCH 4/5] only move the lp_opt resize in presolve --- cpp/src/mip/diversity/diversity_manager.cu | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cpp/src/mip/diversity/diversity_manager.cu b/cpp/src/mip/diversity/diversity_manager.cu index 2e050980f..f7476a5ed 100644 --- a/cpp/src/mip/diversity/diversity_manager.cu +++ b/cpp/src/mip/diversity/diversity_manager.cu @@ -320,14 +320,9 @@ bool diversity_manager_t::run_presolve(f_t time_limit) if (!check_bounds_sanity(*problem_ptr)) { return false; } } stats.presolve_time = presolve_timer.elapsed_time(); - // after every change to the problem, we should resize all the relevant vars - // we need to encapsulate that to prevent repetitions lp_optimal_solution.resize(problem_ptr->n_variables, problem_ptr->handle_ptr->get_stream()); - ls.resize_vectors(*problem_ptr, problem_ptr->handle_ptr); - ls.lb_constraint_prop.temp_problem.setup(*problem_ptr); - ls.lb_constraint_prop.bounds_update.setup(ls.lb_constraint_prop.temp_problem); - ls.constraint_prop.bounds_update.resize(*problem_ptr); problem_ptr->handle_ptr->sync_stream(); + cudaDeviceSynchronize(); return true; } @@ -398,6 +393,12 @@ solution_t diversity_manager_t::run_solver() // to automatically compute the solving time on scope exit auto timer_raii_guard = cuopt::scope_guard([&]() { stats.total_solve_time = timer.elapsed_time(); }); + // after every change to the problem, we should resize all the relevant vars + // we need to encapsulate that to prevent repetitions + ls.resize_vectors(*problem_ptr, problem_ptr->handle_ptr); + ls.lb_constraint_prop.temp_problem.setup(*problem_ptr); + ls.lb_constraint_prop.bounds_update.setup(ls.lb_constraint_prop.temp_problem); + ls.constraint_prop.bounds_update.resize(*problem_ptr); problem_ptr->check_problem_representation(true); // have the structure ready for reusing later problem_ptr->compute_integer_fixed_problem(); From f212909c7661e9b9c2dcf030441254a9185a6b92 Mon Sep 17 00:00:00 2001 From: akifcorduk Date: Fri, 25 Jul 2025 03:18:20 -0700 Subject: [PATCH 5/5] disable fj tests --- cpp/tests/mip/CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cpp/tests/mip/CMakeLists.txt b/cpp/tests/mip/CMakeLists.txt index 9fc2e3f88..b9fd249a5 100644 --- a/cpp/tests/mip/CMakeLists.txt +++ b/cpp/tests/mip/CMakeLists.txt @@ -43,9 +43,10 @@ ConfigureTest(UNIT_TEST ConfigureTest(EMPTY_FIXED_PROBLEMS_TEST ${CMAKE_CURRENT_SOURCE_DIR}/empty_fixed_problems_test.cu ) -ConfigureTest(FEASIBILITY_JUMP_TEST - ${CMAKE_CURRENT_SOURCE_DIR}/feasibility_jump_tests.cu -) +# Disable for now +# ConfigureTest(FEASIBILITY_JUMP_TEST +# ${CMAKE_CURRENT_SOURCE_DIR}/feasibility_jump_tests.cu +# ) ConfigureTest(MIP_TERMINATION_STATUS_TEST ${CMAKE_CURRENT_SOURCE_DIR}/termination_test.cu )