Search code examples
openmdao

Is there a way to specify partials for an Exec Comp?


Looking into the class, I'm seeing that by default it looks like they're complex stepped. Is there a way to specify an analytical partial?

I've got some code that has a lot of essentially one liner explicit comps with analytical partials specified. Is there any real performance benefit to that over an ExecComp? Or with simple functions does work out to roughly the same?


Solution

  • There's currently no way to specify analytic partials for ExecComps and you're right that they're complex-stepped.

    The short answer to your next question is that for simple functions there's no meaningful performance benefit using explicit components over ExecComp. This is because complex-step computes derivatives within machine precision when using an adequately small step size, which OpenMDAO does. The actual computational cost of performing the complex-step, for one-liners, is generally trivial.

    The longer answer involves a few considerations, such as the sizes of the component's input and output arrays, the sparsity pattern of the Jacobian, and the cost of the actual compute function. If you want, I can go into more detail about these considerations and suggest which method to use for your problems.

    [Edit: I've updated the figure with results for this compute: y=sum(log(x)/x**2+3*log(x)]

    I've added a figure below showing the cost for computing derivatives of a component as we change the size of the input array to that component. The analytic component is slightly faster across the board, but requires more lines of code.

    Basically, whichever method is easier to implement is probably advantageous as there's not a huge cost difference. For this extremely simple compute function, because it's so inexpensive, the framework overhead probably has a larger impact on cost than the actual derivative computation. Of course these trends are also problem dependent.

    Computational cost comparison for exec and analytic comps