-
Notifications
You must be signed in to change notification settings - Fork 5
A placeholder for implementing Jacobian unit tests. #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pelesh
merged 6 commits into
olcf-hackathon-2026-dev
from
slaven/placeholder-for-jacobian-tests
Apr 15, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b5fe008
A placeholder for implementing Jacobian unit tests.
pelesh 64845fd
Apply pre-commmit fixes
pelesh 4a27e8f
Enable unit tests only when matching solvers are enabled.
pelesh ebb1671
Apply pre-commmit fixes
pelesh 729760e
Comment out placeholder objective test function from Jacobian tests.
pelesh b8eac1c
Separate HIOP and HIOPSPARSE in cmake for Jacobian tests
pelesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| add_subdirectory(objective) | ||
| add_subdirectory(constraint_jacobian) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| add_subdirectory(equality) | ||
| add_subdirectory(inequality) |
97 changes: 97 additions & 0 deletions
97
tests/unit/opflow/constraint_jacobian/equality/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| 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 "") | ||
| 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 (deprecated) | ||
| if(EXAGO_ENABLE_HIOP) | ||
| 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 (deprecated) | ||
| if(EXAGO_ENABLE_RAJA) | ||
| list(APPEND solvers HIOP) | ||
| list(APPEND models PBPOLRAJAHIOP) | ||
| list(APPEND 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}" | ||
| ) | ||
| message(STATUS "Setting up test: ${testname}") | ||
| exago_add_test( | ||
| NAME | ||
| ${testname} | ||
| DEPENDS | ||
| ${dependency} | ||
| COMMAND | ||
| ${RUNCMD} | ||
| $<TARGET_FILE:jac_eq_acopf> | ||
| -opflow_model | ||
| ${model} | ||
| -opflow_solver | ||
| ${solver} | ||
| -netfile | ||
| ${network} | ||
| -num_copies | ||
| ${num} | ||
| -validation | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/cecj.csv | ||
| ) | ||
| set_tests_properties(${testname} PROPERTIES SKIP_RETURN_CODE 2) | ||
| endforeach() | ||
| endforeach() | ||
| endif() | ||
File renamed without changes.
166 changes: 166 additions & 0 deletions
166
tests/unit/opflow/constraint_jacobian/equality/jac_eq_acopf.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| #include <iostream> | ||
| #include <cstdio> | ||
| #include <string> | ||
|
|
||
| #include <private/opflowimpl.h> | ||
| #include <exago_config.h> | ||
| #include <utils.h> | ||
|
|
||
| #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 <data_file> : Specifies the input data file to test against. | ||
| * Default value is `/<exago_dir>/datafiles/case9/case9mod.m`. See directory | ||
| * datafiles for other potential inputs. | ||
| * | ||
| * ~ -num_copies <number> : 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") { | ||
| // 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) | ||
| // 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<double *>(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); | ||
|
|
||
| // 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); | ||
| #endif | ||
| #endif | ||
| } | ||
|
|
||
| ierr = VecRestoreArray(X, &x_ref); | ||
| CHKERRQ(ierr); | ||
|
|
||
| ierr = PetscFree(x_ref); | ||
| CHKERRQ(ierr); | ||
| #endif // End #ifdefined(EXAGO_ENABLE_HIOP) | ||
| } else { | ||
| // TODO: Replace with inequality Jacobian test once implemented | ||
| // fail += test.computeObjective(opflowtest, X, obj_value); | ||
| } | ||
| ierr = OPFLOWDestroy(&opflowtest); | ||
| CHKERRQ(ierr); | ||
|
|
||
| // Temporarily skip the test | ||
| fail = exago::tests::SKIP_TEST; | ||
|
|
||
| ExaGOFinalize(); | ||
| return fail; | ||
| } |
92 changes: 92 additions & 0 deletions
92
tests/unit/opflow/constraint_jacobian/inequality/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| 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 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 (deprecated) | ||
| if(EXAGO_ENABLE_HIOP) | ||
| 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 (deprecated) | ||
| if(EXAGO_ENABLE_RAJA) | ||
| list(APPEND solvers HIOP) | ||
| list(APPEND models PBPOLRAJAHIOP) | ||
| list(APPEND 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} | ||
| $<TARGET_FILE:jac_ineq_acopf> | ||
| -opflow_model | ||
| ${model} | ||
| -opflow_solver | ||
| ${solver} | ||
| -netfile | ||
| ${network} | ||
| -num_copies | ||
| ${num} | ||
| -validation | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/cicj.csv | ||
| ) | ||
| set_tests_properties(${testname} PROPERTIES SKIP_RETURN_CODE 2) | ||
| endforeach() | ||
| endforeach() | ||
| endif() |
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.