From b5fe0089e9ddc5ce038c7395fa734aba963baa8d Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Mon, 13 Apr 2026 22:43:25 -0400 Subject: [PATCH 1/6] A placeholder for implementing Jacobian unit tests. --- .../objective/{OF_unittestx3.m => testx3.m} | 0 .../{OF_unittestx600.m => testx600.m} | 0 tests/unit/opflow/CMakeLists.txt | 1 + .../opflow/constraint_jacobian/CMakeLists.txt | 2 + .../equality/CMakeLists.txt | 66 +++++++ ...ints_jacobian_test_design.md => README.md} | 0 .../equality/jac_eq_acopf.cpp | 163 ++++++++++++++++++ .../inequality/CMakeLists.txt | 66 +++++++ ...ints_jacobian_test_design.md => README.md} | 0 .../inequality/jac_ineq_acopf.cpp | 163 ++++++++++++++++++ tests/unit/opflow/objective/CMakeLists.txt | 4 +- tests/unit/utils/test_base.h | 2 +- 12 files changed, 464 insertions(+), 3 deletions(-) rename datafiles/unit/opflow/objective/{OF_unittestx3.m => testx3.m} (100%) rename datafiles/unit/opflow/objective/{OF_unittestx600.m => testx600.m} (100%) create mode 100644 tests/unit/opflow/constraint_jacobian/CMakeLists.txt create mode 100644 tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt rename tests/unit/opflow/constraint_jacobian/equality/{compute_equality_constraints_jacobian_test_design.md => README.md} (100%) create mode 100644 tests/unit/opflow/constraint_jacobian/equality/jac_eq_acopf.cpp create mode 100644 tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt rename tests/unit/opflow/constraint_jacobian/inequality/{compute_inequality_constraints_jacobian_test_design.md => README.md} (100%) create mode 100644 tests/unit/opflow/constraint_jacobian/inequality/jac_ineq_acopf.cpp diff --git a/datafiles/unit/opflow/objective/OF_unittestx3.m b/datafiles/unit/opflow/objective/testx3.m similarity index 100% rename from datafiles/unit/opflow/objective/OF_unittestx3.m rename to datafiles/unit/opflow/objective/testx3.m diff --git a/datafiles/unit/opflow/objective/OF_unittestx600.m b/datafiles/unit/opflow/objective/testx600.m similarity index 100% rename from datafiles/unit/opflow/objective/OF_unittestx600.m rename to datafiles/unit/opflow/objective/testx600.m diff --git a/tests/unit/opflow/CMakeLists.txt b/tests/unit/opflow/CMakeLists.txt index 2f09e12f..a312cf31 100644 --- a/tests/unit/opflow/CMakeLists.txt +++ b/tests/unit/opflow/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(objective) +add_subdirectory(constraint_jacobian) diff --git a/tests/unit/opflow/constraint_jacobian/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/CMakeLists.txt new file mode 100644 index 00000000..5a69e533 --- /dev/null +++ b/tests/unit/opflow/constraint_jacobian/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(equality) +add_subdirectory(inequality) diff --git a/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt new file mode 100644 index 00000000..ae7034fa --- /dev/null +++ b/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt @@ -0,0 +1,66 @@ +if(EXAGO_ENABLE_RAJA AND EXAGO_ENABLE_CUDA) + set_source_files_properties(jac_eq_acopf.cpp PROPERTIES LANGUAGE CUDA) +endif() + +add_executable( + jac_eq_acopf jac_eq_acopf.cpp ${CMAKE_SOURCE_DIR}/tests/unit/utils/test_acopf_utils.cpp +) +target_link_libraries(jac_eq_acopf ExaGO::OPFLOW) +target_include_directories(jac_eq_acopf PRIVATE ${CMAKE_SOURCE_DIR}/tests/unit/utils) +target_include_directories(jac_eq_acopf PRIVATE ${CMAKE_SOURCE_DIR}/tests/unit/opflow) + +# Network files to run on - doing 3 and 600 bus examples. +set(prefix ${CMAKE_SOURCE_DIR}/datafiles/unit/opflow/objective/) +set(obj_network_files testx3.m testx600.m) +# Map num_copies to a specific netfile +set(num_copies 3 600) + +list(TRANSFORM obj_network_files PREPEND ${prefix}) + +set(solvers IPOPT HIOP HIOPSPARSE) +set(models POWER_BALANCE_POLAR POWER_BALANCE_HIOP POWER_BALANCE_POLAR) +set(dependencies IPOPT HIOP HIOP_SPARSE) +if(EXAGO_ENABLE_RAJA) + set(solvers ${solvers} HIOP) + set(models ${models} PBPOLRAJAHIOP) + set(dependencies ${dependencies} HIOP) +endif() + +if(EXAGO_RUN_TESTS) + foreach( + model + solver + dependency + IN + ZIP_LISTS + models + solvers + dependencies + ) + # Iterate over networks, matching network file to num_copies + foreach(network num IN ZIP_LISTS obj_network_files num_copies) + get_filename_component(net ${network} NAME) + set(testname "UNIT_TESTS_EQUALITY_CONSTRAINT_JACOBIAN_${net}_${solver}_${model}") + exago_add_test( + NAME + ${testname} + DEPENDS + ${dependency} + COMMAND + ${RUNCMD} + $ + -opflow_model + ${model} + -opflow_solver + ${solver} + -netfile + ${network} + -num_copies + ${num} + -validation + ${CMAKE_CURRENT_SOURCE_DIR}/of.csv + ) + set_tests_properties(${testname} PROPERTIES SKIP_RETURN_CODE 2) + endforeach() + endforeach() +endif() diff --git a/tests/unit/opflow/constraint_jacobian/equality/compute_equality_constraints_jacobian_test_design.md b/tests/unit/opflow/constraint_jacobian/equality/README.md similarity index 100% rename from tests/unit/opflow/constraint_jacobian/equality/compute_equality_constraints_jacobian_test_design.md rename to tests/unit/opflow/constraint_jacobian/equality/README.md diff --git a/tests/unit/opflow/constraint_jacobian/equality/jac_eq_acopf.cpp b/tests/unit/opflow/constraint_jacobian/equality/jac_eq_acopf.cpp new file mode 100644 index 00000000..200d9a05 --- /dev/null +++ b/tests/unit/opflow/constraint_jacobian/equality/jac_eq_acopf.cpp @@ -0,0 +1,163 @@ +#include +#include +#include + +#include +#include +#include + +#include "opflow_tests.h" +#include "test_acopf_utils.h" + +/** + * @brief Unit test driver for objective function + * @see opflow/OpflowTests.hpp for kernel tested by this driver + * + * You can pass two options to the objectiveAcopf executatable through the + * command line (implemented using PETSc options): + * + * ~ -netfile : Specifies the input data file to test against. + * Default value is `//datafiles/case9/case9mod.m`. See directory + * datafiles for other potential inputs. + * + * ~ -num_copies : Specifies the number of replications of the + * network given through `-netfile`. If this is not set properly, test may fail + * + */ +int main(int argc, char **argv) { + PetscErrorCode ierr; + PetscBool flg; + Vec X; + int fail = 0; + double obj_value; + char file_c_str[PETSC_MAX_PATH_LEN]; + char validation_c_str[PETSC_MAX_PATH_LEN]; + std::string file; + char appname[] = "opflow"; + MPI_Comm comm = MPI_COMM_WORLD; + int num_copies = 0; + + char help[] = "Unit tests for equality constraint Jacobians running opflow\n"; + + /** Use `ExaGOLogSetLoggingFileName("opflow-logfile");` to log the output. */ + ierr = ExaGOInitialize(comm, &argc, &argv, appname, help); + if (ierr) { + fprintf(stderr, "Could not initialize ExaGO application %s.\n", appname); + return ierr; + } + + /* Get network data file from command line */ + ierr = PetscOptionsGetString(NULL, NULL, "-netfile", file_c_str, + PETSC_MAX_PATH_LEN, &flg); + CHKERRQ(ierr); + + /* Get num_copies from command line */ + ierr = PetscOptionsGetInt(NULL, NULL, "-num_copies", &num_copies, &flg); + CHKERRQ(ierr); + + if (!flg) { + file = "../datafiles/case9/case9mod.m"; + } else { + file.assign(file_c_str); + } + + // Set obj_value as reference solution, and run as usual + /* Get validation data file from command line */ + ierr = PetscOptionsGetString(NULL, NULL, "-validation", validation_c_str, + PETSC_MAX_PATH_LEN, &flg); + CHKERRQ(ierr); + readFromFile(&obj_value, validation_c_str); + + obj_value = obj_value * num_copies; + + OPFLOW opflowtest; + exago::tests::TestOpflow test; + + /* Set up test opflow */ + ierr = OPFLOWCreate(PETSC_COMM_WORLD, &opflowtest); + CHKERRQ(ierr); + ierr = OPFLOWReadMatPowerData(opflowtest, file.c_str()); + CHKERRQ(ierr); + ierr = OPFLOWSetInitializationType(opflowtest, OPFLOWINIT_FROMFILE); + CHKERRQ(ierr); + ierr = OPFLOWSetUp(opflowtest); + CHKERRQ(ierr); + ierr = OPFLOWGetSolution(opflowtest, &X); + CHKERRQ(ierr); + + // If we are using HIOP, need to convert X + // The string lengths must be 65 + std::string modelname; + std::string solvername; + ierr = OPFLOWGetModel(opflowtest, &modelname); + ierr = OPFLOWGetSolver(opflowtest, &solvername); + + if (solvername == "HIOP") { +#if defined(EXAGO_ENABLE_HIOP) + double *x_ref; + ierr = VecGetArray(X, &x_ref); + + int nx, nconeq, nconineq; + ierr = OPFLOWGetSizes(opflowtest, &nx, &nconeq, &nconineq); + CHKERRQ(ierr); + + // If we are running using the CPU model, nothing needs to be done + if (modelname == "POWER_BALANCE_HIOP") { + fail += test.computeObjective(opflowtest, x_ref, obj_value); + } else // Using model PBPOLRAJAHIOP + { +#if defined(EXAGO_ENABLE_RAJA) + // Get resource manager instance + auto &resmgr = umpire::ResourceManager::getInstance(); + + // Get Allocator + umpire::Allocator h_allocator = resmgr.getAllocator("HOST"); + + // Register array xref with umpire + umpire::util::AllocationRecord record_x{ + x_ref, sizeof(double) * nx, h_allocator.getAllocationStrategy()}; + resmgr.registerAllocation(x_ref, record_x); + // Allocate and copy xref to device + double *x_ref_dev; + +#ifdef EXAGO_ENABLE_GPU + + ierr = OPFLOWSetHIOPComputeMode(opflowtest, "GPU"); + CHKERRQ(ierr); + + umpire::Allocator d_allocator = resmgr.getAllocator("DEVICE"); + x_ref_dev = + static_cast(d_allocator.allocate(nx * sizeof(double))); +#else + ierr = OPFLOWSetHIOPComputeMode(opflowtest, "CPU"); + CHKERRQ(ierr); + x_ref_dev = x_ref; +#endif + resmgr.copy(x_ref_dev, x_ref); + + fail += test.computeObjective(opflowtest, x_ref_dev, obj_value); + +#ifdef EXAGO_ENABLE_GPU + d_allocator.deallocate(x_ref_dev); +#endif +#endif + } + + ierr = VecRestoreArray(X, &x_ref); + CHKERRQ(ierr); + + ierr = PetscFree(x_ref); + CHKERRQ(ierr); +#endif // End #ifdefined(EXAGO_ENABLE_HIOP) + } else { + fail += test.computeObjective(opflowtest, X, obj_value); + } + ierr = OPFLOWDestroy(&opflowtest); + CHKERRQ(ierr); + + // Temporarily skip the test + fail = exago::tests::SKIP_TEST; + + ExaGOFinalize(); + return fail; +} diff --git a/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt new file mode 100644 index 00000000..0872f7ad --- /dev/null +++ b/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt @@ -0,0 +1,66 @@ +if(EXAGO_ENABLE_RAJA AND EXAGO_ENABLE_CUDA) + set_source_files_properties(jac_ineq_acopf.cpp PROPERTIES LANGUAGE CUDA) +endif() + +add_executable( + jac_ineq_acopf jac_ineq_acopf.cpp ${CMAKE_SOURCE_DIR}/tests/unit/utils/test_acopf_utils.cpp +) +target_link_libraries(jac_ineq_acopf ExaGO::OPFLOW) +target_include_directories(jac_ineq_acopf PRIVATE ${CMAKE_SOURCE_DIR}/tests/unit/utils) +target_include_directories(jac_ineq_acopf PRIVATE ${CMAKE_SOURCE_DIR}/tests/unit/opflow) + +# Network files to run on - doing 3 and 600 bus examples. +set(prefix ${CMAKE_SOURCE_DIR}/datafiles/unit/opflow/objective/) +set(obj_network_files testx3.m testx600.m) +# Map num_copies to a specific netfile +set(num_copies 3 600) + +list(TRANSFORM obj_network_files PREPEND ${prefix}) + +set(solvers IPOPT HIOP HIOPSPARSE) +set(models POWER_BALANCE_POLAR POWER_BALANCE_HIOP POWER_BALANCE_POLAR) +set(dependencies IPOPT HIOP HIOP_SPARSE) +if(EXAGO_ENABLE_RAJA) + set(solvers ${solvers} HIOP) + set(models ${models} PBPOLRAJAHIOP) + set(dependencies ${dependencies} HIOP) +endif() + +if(EXAGO_RUN_TESTS) + foreach( + model + solver + dependency + IN + ZIP_LISTS + models + solvers + dependencies + ) + # Iterate over networks, matching network file to num_copies + foreach(network num IN ZIP_LISTS obj_network_files num_copies) + get_filename_component(net ${network} NAME) + set(testname "UNIT_TESTS_INEQUALITY_CONSTRAINT_JACOBIAN_${net}_${solver}_${model}") + exago_add_test( + NAME + ${testname} + DEPENDS + ${dependency} + COMMAND + ${RUNCMD} + $ + -opflow_model + ${model} + -opflow_solver + ${solver} + -netfile + ${network} + -num_copies + ${num} + -validation + ${CMAKE_CURRENT_SOURCE_DIR}/of.csv + ) + set_tests_properties(${testname} PROPERTIES SKIP_RETURN_CODE 2) + endforeach() + endforeach() +endif() diff --git a/tests/unit/opflow/constraint_jacobian/inequality/compute_inequality_constraints_jacobian_test_design.md b/tests/unit/opflow/constraint_jacobian/inequality/README.md similarity index 100% rename from tests/unit/opflow/constraint_jacobian/inequality/compute_inequality_constraints_jacobian_test_design.md rename to tests/unit/opflow/constraint_jacobian/inequality/README.md diff --git a/tests/unit/opflow/constraint_jacobian/inequality/jac_ineq_acopf.cpp b/tests/unit/opflow/constraint_jacobian/inequality/jac_ineq_acopf.cpp new file mode 100644 index 00000000..c8acb27b --- /dev/null +++ b/tests/unit/opflow/constraint_jacobian/inequality/jac_ineq_acopf.cpp @@ -0,0 +1,163 @@ +#include +#include +#include + +#include +#include +#include + +#include "opflow_tests.h" +#include "test_acopf_utils.h" + +/** + * @brief Unit test driver for objective function + * @see opflow/OpflowTests.hpp for kernel tested by this driver + * + * You can pass two options to the objectiveAcopf executatable through the + * command line (implemented using PETSc options): + * + * ~ -netfile : Specifies the input data file to test against. + * Default value is `//datafiles/case9/case9mod.m`. See directory + * datafiles for other potential inputs. + * + * ~ -num_copies : Specifies the number of replications of the + * network given through `-netfile`. If this is not set properly, test may fail + * + */ +int main(int argc, char **argv) { + PetscErrorCode ierr; + PetscBool flg; + Vec X; + int fail = 0; + double obj_value; + char file_c_str[PETSC_MAX_PATH_LEN]; + char validation_c_str[PETSC_MAX_PATH_LEN]; + std::string file; + char appname[] = "opflow"; + MPI_Comm comm = MPI_COMM_WORLD; + int num_copies = 0; + + char help[] = "Unit tests for inequality constraint Jacobians running opflow\n"; + + /** Use `ExaGOLogSetLoggingFileName("opflow-logfile");` to log the output. */ + ierr = ExaGOInitialize(comm, &argc, &argv, appname, help); + if (ierr) { + fprintf(stderr, "Could not initialize ExaGO application %s.\n", appname); + return ierr; + } + + /* Get network data file from command line */ + ierr = PetscOptionsGetString(NULL, NULL, "-netfile", file_c_str, + PETSC_MAX_PATH_LEN, &flg); + CHKERRQ(ierr); + + /* Get num_copies from command line */ + ierr = PetscOptionsGetInt(NULL, NULL, "-num_copies", &num_copies, &flg); + CHKERRQ(ierr); + + if (!flg) { + file = "../datafiles/case9/case9mod.m"; + } else { + file.assign(file_c_str); + } + + // Set obj_value as reference solution, and run as usual + /* Get validation data file from command line */ + ierr = PetscOptionsGetString(NULL, NULL, "-validation", validation_c_str, + PETSC_MAX_PATH_LEN, &flg); + CHKERRQ(ierr); + readFromFile(&obj_value, validation_c_str); + + obj_value = obj_value * num_copies; + + OPFLOW opflowtest; + exago::tests::TestOpflow test; + + /* Set up test opflow */ + ierr = OPFLOWCreate(PETSC_COMM_WORLD, &opflowtest); + CHKERRQ(ierr); + ierr = OPFLOWReadMatPowerData(opflowtest, file.c_str()); + CHKERRQ(ierr); + ierr = OPFLOWSetInitializationType(opflowtest, OPFLOWINIT_FROMFILE); + CHKERRQ(ierr); + ierr = OPFLOWSetUp(opflowtest); + CHKERRQ(ierr); + ierr = OPFLOWGetSolution(opflowtest, &X); + CHKERRQ(ierr); + + // If we are using HIOP, need to convert X + // The string lengths must be 65 + std::string modelname; + std::string solvername; + ierr = OPFLOWGetModel(opflowtest, &modelname); + ierr = OPFLOWGetSolver(opflowtest, &solvername); + + if (solvername == "HIOP") { +#if defined(EXAGO_ENABLE_HIOP) + double *x_ref; + ierr = VecGetArray(X, &x_ref); + + int nx, nconeq, nconineq; + ierr = OPFLOWGetSizes(opflowtest, &nx, &nconeq, &nconineq); + CHKERRQ(ierr); + + // If we are running using the CPU model, nothing needs to be done + if (modelname == "POWER_BALANCE_HIOP") { + fail += test.computeObjective(opflowtest, x_ref, obj_value); + } else // Using model PBPOLRAJAHIOP + { +#if defined(EXAGO_ENABLE_RAJA) + // Get resource manager instance + auto &resmgr = umpire::ResourceManager::getInstance(); + + // Get Allocator + umpire::Allocator h_allocator = resmgr.getAllocator("HOST"); + + // Register array xref with umpire + umpire::util::AllocationRecord record_x{ + x_ref, sizeof(double) * nx, h_allocator.getAllocationStrategy()}; + resmgr.registerAllocation(x_ref, record_x); + // Allocate and copy xref to device + double *x_ref_dev; + +#ifdef EXAGO_ENABLE_GPU + + ierr = OPFLOWSetHIOPComputeMode(opflowtest, "GPU"); + CHKERRQ(ierr); + + umpire::Allocator d_allocator = resmgr.getAllocator("DEVICE"); + x_ref_dev = + static_cast(d_allocator.allocate(nx * sizeof(double))); +#else + ierr = OPFLOWSetHIOPComputeMode(opflowtest, "CPU"); + CHKERRQ(ierr); + x_ref_dev = x_ref; +#endif + resmgr.copy(x_ref_dev, x_ref); + + fail += test.computeObjective(opflowtest, x_ref_dev, obj_value); + +#ifdef EXAGO_ENABLE_GPU + d_allocator.deallocate(x_ref_dev); +#endif +#endif + } + + ierr = VecRestoreArray(X, &x_ref); + CHKERRQ(ierr); + + ierr = PetscFree(x_ref); + CHKERRQ(ierr); +#endif // End #ifdefined(EXAGO_ENABLE_HIOP) + } else { + fail += test.computeObjective(opflowtest, X, obj_value); + } + ierr = OPFLOWDestroy(&opflowtest); + CHKERRQ(ierr); + + // Temporarily skip the test + fail = exago::tests::SKIP_TEST; + + ExaGOFinalize(); + return fail; +} diff --git a/tests/unit/opflow/objective/CMakeLists.txt b/tests/unit/opflow/objective/CMakeLists.txt index 0b89bff6..07b52079 100644 --- a/tests/unit/opflow/objective/CMakeLists.txt +++ b/tests/unit/opflow/objective/CMakeLists.txt @@ -11,7 +11,7 @@ target_include_directories(objective_acopf PRIVATE ../) # Network files to run on - doing 3 and 600 bus examples. set(prefix ${CMAKE_SOURCE_DIR}/datafiles/unit/opflow/objective/) -set(obj_network_files OF_unittestx3.m OF_unittestx600.m) +set(obj_network_files testx3.m testx600.m) # Map num_copies to a specific netfile set(num_copies 3 600) @@ -40,7 +40,7 @@ if(EXAGO_RUN_TESTS) # Iterate over networks, matching network file to num_copies foreach(network num IN ZIP_LISTS obj_network_files num_copies) get_filename_component(net ${network} NAME) - set(testname "UNIT_TESTS_OBJECTIVE_SIZE_${net}_${solver}_${model}") + set(testname "UNIT_TESTS_OBJECTIVE_${net}_${solver}_${model}") exago_add_test( NAME ${testname} diff --git a/tests/unit/utils/test_base.h b/tests/unit/utils/test_base.h index f03dc5bf..0e2d018c 100644 --- a/tests/unit/utils/test_base.h +++ b/tests/unit/utils/test_base.h @@ -35,7 +35,7 @@ static const RealType three = 3.0; // static const RealType eps = 10*std::numeric_limits::epsilon(); static const RealType eps = 1e-8; -static const LocalOrdinalType SKIP_TEST = -1; +static const LocalOrdinalType SKIP_TEST = 2; /** @brief Base class for all testing classes. Each child class will call the From 64845fd6a5dc6b9c7a574407aad646de6a95a1ce Mon Sep 17 00:00:00 2001 From: pelesh Date: Tue, 14 Apr 2026 02:47:06 +0000 Subject: [PATCH 2/6] Apply pre-commmit fixes --- .../constraint_jacobian/equality/CMakeLists.txt | 15 +++++++++++---- .../constraint_jacobian/inequality/CMakeLists.txt | 15 +++++++++++---- .../inequality/jac_ineq_acopf.cpp | 3 ++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt index ae7034fa..66eebf9d 100644 --- a/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt +++ b/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt @@ -3,11 +3,16 @@ if(EXAGO_ENABLE_RAJA AND EXAGO_ENABLE_CUDA) endif() add_executable( - jac_eq_acopf jac_eq_acopf.cpp ${CMAKE_SOURCE_DIR}/tests/unit/utils/test_acopf_utils.cpp + jac_eq_acopf jac_eq_acopf.cpp + ${CMAKE_SOURCE_DIR}/tests/unit/utils/test_acopf_utils.cpp ) target_link_libraries(jac_eq_acopf ExaGO::OPFLOW) -target_include_directories(jac_eq_acopf PRIVATE ${CMAKE_SOURCE_DIR}/tests/unit/utils) -target_include_directories(jac_eq_acopf PRIVATE ${CMAKE_SOURCE_DIR}/tests/unit/opflow) +target_include_directories( + jac_eq_acopf PRIVATE ${CMAKE_SOURCE_DIR}/tests/unit/utils +) +target_include_directories( + jac_eq_acopf PRIVATE ${CMAKE_SOURCE_DIR}/tests/unit/opflow +) # Network files to run on - doing 3 and 600 bus examples. set(prefix ${CMAKE_SOURCE_DIR}/datafiles/unit/opflow/objective/) @@ -40,7 +45,9 @@ if(EXAGO_RUN_TESTS) # Iterate over networks, matching network file to num_copies foreach(network num IN ZIP_LISTS obj_network_files num_copies) get_filename_component(net ${network} NAME) - set(testname "UNIT_TESTS_EQUALITY_CONSTRAINT_JACOBIAN_${net}_${solver}_${model}") + set(testname + "UNIT_TESTS_EQUALITY_CONSTRAINT_JACOBIAN_${net}_${solver}_${model}" + ) exago_add_test( NAME ${testname} diff --git a/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt index 0872f7ad..bc7dcd75 100644 --- a/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt +++ b/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt @@ -3,11 +3,16 @@ if(EXAGO_ENABLE_RAJA AND EXAGO_ENABLE_CUDA) endif() add_executable( - jac_ineq_acopf jac_ineq_acopf.cpp ${CMAKE_SOURCE_DIR}/tests/unit/utils/test_acopf_utils.cpp + jac_ineq_acopf jac_ineq_acopf.cpp + ${CMAKE_SOURCE_DIR}/tests/unit/utils/test_acopf_utils.cpp ) target_link_libraries(jac_ineq_acopf ExaGO::OPFLOW) -target_include_directories(jac_ineq_acopf PRIVATE ${CMAKE_SOURCE_DIR}/tests/unit/utils) -target_include_directories(jac_ineq_acopf PRIVATE ${CMAKE_SOURCE_DIR}/tests/unit/opflow) +target_include_directories( + jac_ineq_acopf PRIVATE ${CMAKE_SOURCE_DIR}/tests/unit/utils +) +target_include_directories( + jac_ineq_acopf PRIVATE ${CMAKE_SOURCE_DIR}/tests/unit/opflow +) # Network files to run on - doing 3 and 600 bus examples. set(prefix ${CMAKE_SOURCE_DIR}/datafiles/unit/opflow/objective/) @@ -40,7 +45,9 @@ if(EXAGO_RUN_TESTS) # Iterate over networks, matching network file to num_copies foreach(network num IN ZIP_LISTS obj_network_files num_copies) get_filename_component(net ${network} NAME) - set(testname "UNIT_TESTS_INEQUALITY_CONSTRAINT_JACOBIAN_${net}_${solver}_${model}") + set(testname + "UNIT_TESTS_INEQUALITY_CONSTRAINT_JACOBIAN_${net}_${solver}_${model}" + ) exago_add_test( NAME ${testname} diff --git a/tests/unit/opflow/constraint_jacobian/inequality/jac_ineq_acopf.cpp b/tests/unit/opflow/constraint_jacobian/inequality/jac_ineq_acopf.cpp index c8acb27b..8de90576 100644 --- a/tests/unit/opflow/constraint_jacobian/inequality/jac_ineq_acopf.cpp +++ b/tests/unit/opflow/constraint_jacobian/inequality/jac_ineq_acopf.cpp @@ -37,7 +37,8 @@ int main(int argc, char **argv) { MPI_Comm comm = MPI_COMM_WORLD; int num_copies = 0; - char help[] = "Unit tests for inequality constraint Jacobians running opflow\n"; + char help[] = + "Unit tests for inequality constraint Jacobians running opflow\n"; /** Use `ExaGOLogSetLoggingFileName("opflow-logfile");` to log the output. */ ierr = ExaGOInitialize(comm, &argc, &argv, appname, help); From 4a27e8f4f2a2d31737a78862b7ccbfee8deb72c1 Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Mon, 13 Apr 2026 23:18:17 -0400 Subject: [PATCH 3/6] Enable unit tests only when matching solvers are enabled. --- .../equality/CMakeLists.txt | 28 +++++++++++++++---- .../inequality/CMakeLists.txt | 24 ++++++++++++---- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt index 66eebf9d..2bd19dd2 100644 --- a/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt +++ b/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt @@ -22,13 +22,29 @@ set(num_copies 3 600) list(TRANSFORM obj_network_files PREPEND ${prefix}) -set(solvers IPOPT HIOP HIOPSPARSE) -set(models POWER_BALANCE_POLAR POWER_BALANCE_HIOP POWER_BALANCE_POLAR) -set(dependencies IPOPT HIOP HIOP_SPARSE) +set(solvers "") +set(models "") +set(dependencies "") + +# Set up Ipopt solver tests if enabled +if(EXAGO_ENABLE_IPOPT) + list(APPEND solvers IPOPT) + list(APPEND models POWER_BALANCE_POLAR) + list(APPEND dependencies IPOPT) +endif() + +# Set up HIOP solver tests if enabled +if(EXAGO_ENABLE_HIOP) + list(APPEND solvers HIOP HIOPSPARSE) + list(APPEND models POWER_BALANCE_HIOP POWER_BALANCE_POLAR) + list(APPEND dependencies HIOP HIOP_SPARSE) +endif() + +# Set up RAJA support tests if enabled if(EXAGO_ENABLE_RAJA) - set(solvers ${solvers} HIOP) - set(models ${models} PBPOLRAJAHIOP) - set(dependencies ${dependencies} HIOP) + list(APPEND solvers HIOP) + list(APPEND models PBPOLRAJAHIOP) + list(APPEND dependencies HIOP) endif() if(EXAGO_RUN_TESTS) diff --git a/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt index bc7dcd75..f28d87f0 100644 --- a/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt +++ b/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt @@ -22,13 +22,25 @@ set(num_copies 3 600) list(TRANSFORM obj_network_files PREPEND ${prefix}) -set(solvers IPOPT HIOP HIOPSPARSE) -set(models POWER_BALANCE_POLAR POWER_BALANCE_HIOP POWER_BALANCE_POLAR) -set(dependencies IPOPT HIOP HIOP_SPARSE) +# Set up Ipopt solver tests if enabled +if(EXAGO_ENABLE_IPOPT) + list(APPEND solvers IPOPT) + list(APPEND models POWER_BALANCE_POLAR) + list(APPEND dependencies IPOPT) +endif() + +# Set up HIOP solver tests if enabled +if(EXAGO_ENABLE_HIOP) + list(APPEND solvers HIOP HIOPSPARSE) + list(APPEND models POWER_BALANCE_HIOP POWER_BALANCE_POLAR) + list(APPEND dependencies HIOP HIOP_SPARSE) +endif() + +# Set up RAJA support tests if enabled if(EXAGO_ENABLE_RAJA) - set(solvers ${solvers} HIOP) - set(models ${models} PBPOLRAJAHIOP) - set(dependencies ${dependencies} HIOP) + list(APPEND solvers HIOP) + list(APPEND models PBPOLRAJAHIOP) + list(APPEND dependencies HIOP) endif() if(EXAGO_RUN_TESTS) From ebb1671c543c1c3f4e0d5f7984c41166a3132775 Mon Sep 17 00:00:00 2001 From: pelesh Date: Tue, 14 Apr 2026 03:19:32 +0000 Subject: [PATCH 4/6] Apply pre-commmit fixes --- tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt | 2 +- tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt index 2bd19dd2..78862180 100644 --- a/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt +++ b/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt @@ -40,7 +40,7 @@ if(EXAGO_ENABLE_HIOP) list(APPEND dependencies HIOP HIOP_SPARSE) endif() -# Set up RAJA support tests if enabled +# Set up RAJA support tests if enabled if(EXAGO_ENABLE_RAJA) list(APPEND solvers HIOP) list(APPEND models PBPOLRAJAHIOP) diff --git a/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt index f28d87f0..c8740c51 100644 --- a/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt +++ b/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt @@ -36,7 +36,7 @@ if(EXAGO_ENABLE_HIOP) list(APPEND dependencies HIOP HIOP_SPARSE) endif() -# Set up RAJA support tests if enabled +# Set up RAJA support tests if enabled if(EXAGO_ENABLE_RAJA) list(APPEND solvers HIOP) list(APPEND models PBPOLRAJAHIOP) From 729760efa0f9c8651c854681327d7d01e08a2b29 Mon Sep 17 00:00:00 2001 From: pelesh Date: Tue, 14 Apr 2026 18:02:24 -0400 Subject: [PATCH 5/6] Comment out placeholder objective test function from Jacobian tests. --- .../opflow/constraint_jacobian/equality/CMakeLists.txt | 2 +- .../opflow/constraint_jacobian/equality/jac_eq_acopf.cpp | 9 ++++++--- .../opflow/constraint_jacobian/inequality/CMakeLists.txt | 2 +- .../constraint_jacobian/inequality/jac_ineq_acopf.cpp | 9 ++++++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt index 78862180..fffbafe2 100644 --- a/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt +++ b/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt @@ -81,7 +81,7 @@ if(EXAGO_RUN_TESTS) -num_copies ${num} -validation - ${CMAKE_CURRENT_SOURCE_DIR}/of.csv + ${CMAKE_CURRENT_SOURCE_DIR}/cecj.csv ) set_tests_properties(${testname} PROPERTIES SKIP_RETURN_CODE 2) endforeach() diff --git a/tests/unit/opflow/constraint_jacobian/equality/jac_eq_acopf.cpp b/tests/unit/opflow/constraint_jacobian/equality/jac_eq_acopf.cpp index 200d9a05..2b09eea4 100644 --- a/tests/unit/opflow/constraint_jacobian/equality/jac_eq_acopf.cpp +++ b/tests/unit/opflow/constraint_jacobian/equality/jac_eq_acopf.cpp @@ -103,7 +103,8 @@ int main(int argc, char **argv) { // If we are running using the CPU model, nothing needs to be done if (modelname == "POWER_BALANCE_HIOP") { - fail += test.computeObjective(opflowtest, x_ref, obj_value); + // TODO: Replace with inequality Jacobian test once implemented + // fail += test.computeObjective(opflowtest, x_ref, obj_value); } else // Using model PBPOLRAJAHIOP { #if defined(EXAGO_ENABLE_RAJA) @@ -135,7 +136,8 @@ int main(int argc, char **argv) { #endif resmgr.copy(x_ref_dev, x_ref); - fail += test.computeObjective(opflowtest, x_ref_dev, obj_value); + // TODO: Replace with inequality Jacobian test once implemented + // fail += test.computeObjective(opflowtest, x_ref_dev, obj_value); #ifdef EXAGO_ENABLE_GPU d_allocator.deallocate(x_ref_dev); @@ -150,7 +152,8 @@ int main(int argc, char **argv) { CHKERRQ(ierr); #endif // End #ifdefined(EXAGO_ENABLE_HIOP) } else { - fail += test.computeObjective(opflowtest, X, obj_value); + // TODO: Replace with inequality Jacobian test once implemented + // fail += test.computeObjective(opflowtest, X, obj_value); } ierr = OPFLOWDestroy(&opflowtest); CHKERRQ(ierr); diff --git a/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt index c8740c51..7ea4e9fd 100644 --- a/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt +++ b/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt @@ -77,7 +77,7 @@ if(EXAGO_RUN_TESTS) -num_copies ${num} -validation - ${CMAKE_CURRENT_SOURCE_DIR}/of.csv + ${CMAKE_CURRENT_SOURCE_DIR}/cicj.csv ) set_tests_properties(${testname} PROPERTIES SKIP_RETURN_CODE 2) endforeach() diff --git a/tests/unit/opflow/constraint_jacobian/inequality/jac_ineq_acopf.cpp b/tests/unit/opflow/constraint_jacobian/inequality/jac_ineq_acopf.cpp index 8de90576..4a6fc30c 100644 --- a/tests/unit/opflow/constraint_jacobian/inequality/jac_ineq_acopf.cpp +++ b/tests/unit/opflow/constraint_jacobian/inequality/jac_ineq_acopf.cpp @@ -104,7 +104,8 @@ int main(int argc, char **argv) { // If we are running using the CPU model, nothing needs to be done if (modelname == "POWER_BALANCE_HIOP") { - fail += test.computeObjective(opflowtest, x_ref, obj_value); + // TODO: Replace with inequality Jacobian test once implemented + // fail += test.computeObjective(opflowtest, x_ref, obj_value); } else // Using model PBPOLRAJAHIOP { #if defined(EXAGO_ENABLE_RAJA) @@ -136,7 +137,8 @@ int main(int argc, char **argv) { #endif resmgr.copy(x_ref_dev, x_ref); - fail += test.computeObjective(opflowtest, x_ref_dev, obj_value); + // TODO: Replace with inequality Jacobian test once implemented + // fail += test.computeObjective(opflowtest, x_ref_dev, obj_value); #ifdef EXAGO_ENABLE_GPU d_allocator.deallocate(x_ref_dev); @@ -151,7 +153,8 @@ int main(int argc, char **argv) { CHKERRQ(ierr); #endif // End #ifdefined(EXAGO_ENABLE_HIOP) } else { - fail += test.computeObjective(opflowtest, X, obj_value); + // TODO: Replace with inequality Jacobian test once implemented + // fail += test.computeObjective(opflowtest, X, obj_value); } ierr = OPFLOWDestroy(&opflowtest); CHKERRQ(ierr); From b8eac1c22873a0f679fa99d7a1b23e5b71c88eae Mon Sep 17 00:00:00 2001 From: Slaven Peles Date: Wed, 15 Apr 2026 11:20:39 -0400 Subject: [PATCH 6/6] Separate HIOP and HIOPSPARSE in cmake for Jacobian tests --- .../equality/CMakeLists.txt | 18 +++++++++++++----- .../inequality/CMakeLists.txt | 17 ++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt index fffbafe2..4c9e1630 100644 --- a/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt +++ b/tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt @@ -33,14 +33,21 @@ if(EXAGO_ENABLE_IPOPT) list(APPEND dependencies IPOPT) endif() -# Set up HIOP solver tests if enabled +# Set up HIOP solver tests if enabled (deprecated) if(EXAGO_ENABLE_HIOP) - list(APPEND solvers HIOP HIOPSPARSE) - list(APPEND models POWER_BALANCE_HIOP POWER_BALANCE_POLAR) - list(APPEND dependencies HIOP HIOP_SPARSE) + list(APPEND solvers HIOP) + list(APPEND models POWER_BALANCE_HIOP) + list(APPEND dependencies HIOP) +endif() + +# Set up HIOPSPARSE solver tests if enabled +if(TARGET HiOp::SPARSE) + list(APPEND solvers HIOPSPARSE) + list(APPEND models POWER_BALANCE_POLAR) + list(APPEND dependencies HIOP_SPARSE) endif() -# Set up RAJA support tests if enabled +# Set up RAJA support tests if enabled (deprecated) if(EXAGO_ENABLE_RAJA) list(APPEND solvers HIOP) list(APPEND models PBPOLRAJAHIOP) @@ -64,6 +71,7 @@ if(EXAGO_RUN_TESTS) set(testname "UNIT_TESTS_EQUALITY_CONSTRAINT_JACOBIAN_${net}_${solver}_${model}" ) + message(STATUS "Setting up test: ${testname}") exago_add_test( NAME ${testname} diff --git a/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt b/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt index 7ea4e9fd..18177699 100644 --- a/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt +++ b/tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt @@ -29,14 +29,21 @@ if(EXAGO_ENABLE_IPOPT) list(APPEND dependencies IPOPT) endif() -# Set up HIOP solver tests if enabled +# Set up HIOP solver tests if enabled (deprecated) if(EXAGO_ENABLE_HIOP) - list(APPEND solvers HIOP HIOPSPARSE) - list(APPEND models POWER_BALANCE_HIOP POWER_BALANCE_POLAR) - list(APPEND dependencies HIOP HIOP_SPARSE) + list(APPEND solvers HIOP) + list(APPEND models POWER_BALANCE_HIOP) + list(APPEND dependencies HIOP) +endif() + +# Set up HIOPSPARSE solver tests if enabled +if(TARGET HiOp::SPARSE) + list(APPEND solvers HIOPSPARSE) + list(APPEND models POWER_BALANCE_POLAR) + list(APPEND dependencies HIOP_SPARSE) endif() -# Set up RAJA support tests if enabled +# Set up RAJA support tests if enabled (deprecated) if(EXAGO_ENABLE_RAJA) list(APPEND solvers HIOP) list(APPEND models PBPOLRAJAHIOP)