# complex_step.py¶

Complex Step derivative approximations.

class`openmdao.approximation_schemes.complex_step.`

`ComplexStep`

[source]Bases:

`openmdao.approximation_schemes.approximation_scheme.ApproximationScheme`

Approximation scheme using complex step to calculate derivatives.

For example, using a step size of ‘h’ will approximate the derivative in the following way:

\[f'(x) = \Im{\frac{f(x+ih)}{h}}.\]

- Attributes

_fd<FiniteDifference>When nested complex step is detected, we switch to Finite Difference.

`DEFAULT_OPTIONS`

= {'directional': False, 'step': 1e-40}

`__init__`

()[source]Initialize the ApproximationScheme.

`add_approximation`

(abs_key,system,kwargs,vector=None)[source]Use this approximation scheme to approximate the derivative d(of)/d(wrt).

- Parameters

abs_keytuple(str,str)Absolute name pairing of (of, wrt) for the derivative.

systemSystemContaining System.

kwargsdictAdditional keyword arguments, to be interpreted by sub-classes.

vectorndarray or NoneDirection for difference when using directional derivatives.

`apply_directional`

(data,direction)[source]Apply stepsize to direction and embed into approximation data.

- Parameters

datafloatStep size for complex step.

directionndarrayVector containing derivative direction.

- Returns

- ndarray
New step direction.

`compute_approx_col_iter`

(system,under_cs=False)[source]Execute the system to compute the approximate sub-Jacobians.

- Parameters

systemSystemSystem on which the execution is run.

under_csboolTrue if we’re currently under complex step at a higher level.

- Yields

- int
column index

- ndarray
solution array corresponding to the jacobian column at the given column index

`compute_approximations`

(system,jac=None)Execute the system to compute the approximate sub-Jacobians.

- Parameters

systemSystemSystem on which the execution is run.

jacNone or dict-likeIf None, update system with the approximated sub-Jacobians. Otherwise, store the approximations in the given dict-like object.