make objective_scaling_factor optional for gRPC - #1600
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughThe objective scaling factor now uses protobuf presence tracking across unary and chunked conversion paths, preserving the C++ default when omitted and validating explicit and absent values with round-trip tests. ChangesObjective scaling factor presence
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Checkov (3.3.8)cpp/src/grpc/codegen/field_registry.yamlTraceback (most recent call last): Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cpp/tests/linear_programming/grpc/grpc_client_test.cpp`:
- Around line 1860-1905: Extend UnaryProblemObjectiveScalingPresence and
ChunkedProblemObjectiveScalingPresence with explicit-zero cases: set
objective_scaling_factor to 0, verify the field is present, and assert mapping
follows the existing invalid-value behavior rather than defaulting to 1.0. Keep
the existing omission and 2.5 presence coverage unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: b780aed9-f610-4ec1-b85c-cf49e8faf5fb
⛔ Files ignored due to path filters (3)
cpp/src/grpc/codegen/generated/cuopt_remote_data.protois excluded by!**/generated/**cpp/src/grpc/codegen/generated/generated_chunked_header_to_problem.incis excluded by!**/generated/**cpp/src/grpc/codegen/generated/generated_proto_to_problem.incis excluded by!**/generated/**
📒 Files selected for processing (5)
cpp/src/grpc/codegen/FIELD_REGISTRY_REFERENCE.mdcpp/src/grpc/codegen/field_registry.yamlcpp/src/grpc/codegen/generate_conversions.pycpp/src/grpc/cuopt_remote_service.protocpp/tests/linear_programming/grpc/grpc_client_test.cpp
| TEST(MapperRoundtrip, UnaryProblemObjectiveScalingPresence) | ||
| { | ||
| cuopt::remote::OptimizationProblem omitted; | ||
| omitted.add_c(0.0); | ||
| omitted.add_variable_lower_bounds(0.0); | ||
| omitted.add_variable_upper_bounds(1.0); | ||
| ASSERT_FALSE(omitted.has_objective_scaling_factor()); | ||
|
|
||
| cpu_optimization_problem_t<int32_t, double> restored_default; | ||
| map_proto_to_problem(omitted, restored_default); | ||
| EXPECT_DOUBLE_EQ(restored_default.get_objective_scaling_factor(), 1.0); | ||
|
|
||
| cpu_optimization_problem_t<int32_t, double> orig; | ||
| const std::vector<double> objective{0.0}; | ||
| const std::vector<double> lower_bound{0.0}; | ||
| const std::vector<double> upper_bound{1.0}; | ||
| orig.set_objective_coefficients(objective.data(), objective.size()); | ||
| orig.set_variable_lower_bounds(lower_bound.data(), lower_bound.size()); | ||
| orig.set_variable_upper_bounds(upper_bound.data(), upper_bound.size()); | ||
| orig.set_objective_scaling_factor(2.5); | ||
| cuopt::remote::OptimizationProblem present; | ||
| map_problem_to_proto(orig, &present); | ||
| ASSERT_TRUE(present.has_objective_scaling_factor()); | ||
| EXPECT_DOUBLE_EQ(present.objective_scaling_factor(), 2.5); | ||
|
|
||
| cpu_optimization_problem_t<int32_t, double> restored_present; | ||
| map_proto_to_problem(present, restored_present); | ||
| EXPECT_DOUBLE_EQ(restored_present.get_objective_scaling_factor(), 2.5); | ||
| } | ||
|
|
||
| TEST(MapperRoundtrip, ChunkedProblemObjectiveScalingPresence) | ||
| { | ||
| cuopt::remote::ChunkedProblemHeader omitted; | ||
| ASSERT_FALSE(omitted.has_objective_scaling_factor()); | ||
|
|
||
| cpu_optimization_problem_t<int32_t, double> restored_default; | ||
| map_chunked_header_to_problem(omitted, restored_default); | ||
| EXPECT_DOUBLE_EQ(restored_default.get_objective_scaling_factor(), 1.0); | ||
|
|
||
| omitted.set_objective_scaling_factor(2.5); | ||
| ASSERT_TRUE(omitted.has_objective_scaling_factor()); | ||
|
|
||
| cpu_optimization_problem_t<int32_t, double> restored_present; | ||
| map_chunked_header_to_problem(omitted, restored_present); | ||
| EXPECT_DOUBLE_EQ(restored_present.get_objective_scaling_factor(), 2.5); | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Add regression coverage for an explicitly set zero.
These tests cover omission and 2.5, but not the required boundary case where objective_scaling_factor is explicitly set to 0; add unary and chunked assertions that this present value follows the existing invalid-value path rather than being treated as absent and defaulting to 1.0.
As per path instructions, mapper tests should cover negative cases and the specific bug-fix regression. The PR objective requires explicit 0 to remain invalid.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cpp/tests/linear_programming/grpc/grpc_client_test.cpp` around lines 1860 -
1905, Extend UnaryProblemObjectiveScalingPresence and
ChunkedProblemObjectiveScalingPresence with explicit-zero cases: set
objective_scaling_factor to 0, verify the field is present, and assert mapping
follows the existing invalid-value behavior rather than defaulting to 1.0. Keep
the existing omission and 2.5 presence coverage unchanged.
Source: Path instructions
CI Test Summary✅ All 31 test job(s) passed. |
This coupled with a presence check adjusts for the proto3 default 0 on omission of non-optional fields, which differs from the cuopt default of 1.
f3f25b4 to
b3790ef
Compare
|
/ok to test b3790ef |
|
/merge |
This coupled with a presence check adjusts for the proto3 default 0 on omission of non-optional fields, which differs from the cuopt default of 1.
Previously, omitted objective_scaling_factor fields would cause a remote solve to use objective_scaling_factor = 0, instead of the cuopt default "1". (If the field was not omitted, it would only be 0 if explicitly set. Zero is not a valid value in any case).
Found during a routine review of gRPC fields versus local solve.