Skip to content

Add Enzyme vs DependencyTracking system Jacobian test and benchmark over all PhasorDynamics cases - #621

Merged
pelesh merged 3 commits into
developfrom
nicholson/benchmark-Jacobians
Oct 14, 2026
Merged

pelesh merged 3 commits into
developfrom
nicholson/benchmark-Jacobians

Conversation

@nkoukpaizan

Copy link
Copy Markdown
Collaborator

Description

This adds an integration test for full-system Enzyme vs DependencyTracking Jacobians. The test loops over all files in cases/PhasorDynamics/ to compute and compare Jacobians via Enzyme and DependencyTracking. A benchmarking phase times the setup, residual evaluation and Jacobian assembly costs.

On my macOS, ctest --verbose -R PhasorDynamicsIntegrationSystemJacobian generates:

71: [SUMMARY] Times in us per call (setup once); ratio = DependencyTracking / Enzyme.
71: case                    method                 size     nnz      setup   ratio  residual   ratio  Jacobian   ratio
71: ThreeBusZipLoad         Enzyme                   16      60        9.3               0.1               0.4
71: ThreeBusZipLoad         DependencyTracking       16      60       29.6     3.2       7.5    97.0       1.2     3.2
71: ThreeBusClassical       Enzyme                   16      60        9.8               0.1               0.4
71: ThreeBusClassical       DependencyTracking       16      60       27.7     2.8       7.0    93.8       1.2     3.3
71: TwoBusBasic             Enzyme                   19      68       10.1               0.0               0.3
71: TwoBusBasic             DependencyTracking       19      68       33.5     3.3       7.1   246.3       1.4     4.2
71: TwoBusTgov1             Enzyme                   22      76        7.8               0.0               0.4
71: TwoBusTgov1             DependencyTracking       22      76       32.8     4.2       9.2   241.5       1.5     3.7
71: ThreeBusConstantSource  Enzyme                   23      88        8.7               0.1               0.5
71: ThreeBusConstantSource  DependencyTracking       23      88       29.1     3.3      10.0   151.0       1.8     3.6
71: TwoBusIeeet1            Enzyme                   31     100       10.1               0.1               0.6
71: TwoBusIeeet1            DependencyTracking       31     100       33.6     3.3      12.3   237.4       2.0     3.7
71: TwoBusGensal            Enzyme                   32     107       18.4               0.1               0.5
71: TwoBusGensal            DependencyTracking       32     107       63.1     3.4      13.0   173.3       2.2     4.1
71: ThreeBusBasic           Enzyme                   40     152       11.8               0.1               0.8
71: ThreeBusBasic           DependencyTracking       40     152       45.5     3.9      16.3   203.6       3.1     3.9
71: TwoArea                 Enzyme                  140     512       77.4               0.4               3.1
71: TwoArea                 DependencyTracking      140     512      198.0     2.6      66.8   164.2      10.6     3.4
71: IEEE39                  Enzyme                  518    2014      136.8               1.4              10.9
71: IEEE39                  DependencyTracking      518    2014      489.0     3.6     249.1   181.0      43.1     4.0
71: Hawaii                  Enzyme                 1652    5721      381.3               6.1              34.2
71: Hawaii                  DependencyTracking     1652    5721     1720.0     4.5    1111.1   181.1     125.9     3.7
71: ACTIVSg200              Enzyme                 1538    6880      518.1               9.1              39.9
71: ACTIVSg200              DependencyTracking     1538    6880     1656.3     3.2    1005.9   110.4     150.9     3.8
71: ACTIVSg500              Enzyme                 2804   13244      992.2              20.7              79.4
71: ACTIVSg500              DependencyTracking     2804   13244     3084.9     3.1    2192.7   106.1     297.6     3.7
71: WECC240                 Enzyme                 5668   20732     1611.2              27.0             123.6
71: WECC240                 DependencyTracking     5668   20732     6918.4     4.3    4728.5   175.2     452.2     3.7
71: ACTIVSg2000             Enzyme                20312   84627     7335.2             125.6             561.4
71: ACTIVSg2000             DependencyTracking    20312   84627    22021.7     3.0   16900.8   134.5    1972.1     3.5
71: ACTIVSg10k              Enzyme                92834  379712    48768.5            1315.2            5852.6
71: ACTIVSg10k              DependencyTracking    92834  379712   119509.7     2.5   67507.6    51.3    8263.9     1.4

The largest cost differences occur in evaluateResiduals, where DependencyTracking has the overhead of tracking. The std::map manipulations for Jacobian assembly are not as bad as I thought.

Checklist

  • All tests pass.
  • Code compiles cleanly with flags -Wall -Wpedantic -Wconversion -Wextra.
  • The new code follows GridKit™ style guidelines.
  • There are unit tests for the new code.
  • The new code is documented.
  • The feature branch is rebased with respect to the target branch.
  • The CHANGELOG.md has been updated to reflect the changes. If this is a minor PR that is part of a larger fix already included in the file, state so.

Further comments

The change to cases/PhasorDynamics/Toy/ThreeBusConstantSource.case.json is a bug fix we missed in previous PRs, and needed to make the case work here.
I'll update the CHANGELOG and rebase as this gets closer to ready-to-merge.

@nkoukpaizan
nkoukpaizan marked this pull request as ready for review October 14, 2026 15:51

@superwhiskers superwhiskers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. i ran it on my machine and achieved similar numbers to those you got

@pelesh

pelesh commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

How come ratio is getting smaller for larger systems? It looks as if there is a scaling issue with Enzyme.

@pelesh
pelesh merged commit a6f047a into develop Oct 14, 2026
6 checks passed
@lukelowry

Copy link
Copy Markdown
Collaborator

How come ratio is getting smaller for larger systems? It looks as if there is a scaling issue with Enzyme.

I believe most of that can be resolved by makin Branch have a manually defined Jacobian since it is linear. That brought down a lot of the Enzyme overhead on the large cases in my benchmarking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants