Skip to content

otf.optim.gradient.adjoint

Classes:

Name Description
AdjointGradient

Compute parameter gradients using adjoint-based methods.

UpdateOption

Enum for selecting parameter update methods.

AdjointGradient

AdjointGradient(
    system: BaseSystem,
    update_option: UpdateOption = UpdateOption.asymptotic,
    solver: tuple[type[SinglestepSolver | MultistepSolver]]
    | type[SinglestepSolver | MultistepSolver]
    | None = None,
    dt: float | None = None,
    interval_fraction: float = 1,
)

Bases: GradientComputer

Compute parameter gradients using adjoint-based methods.

Supports different update strategies controlled by UpdateOption.

Initialize an AdjointGradient.

Parameters:

Name Type Description Default
system BaseSystem

BaseSystem instance to analyze.

required
update_option UpdateOption

Which adjoint/update method to use (UpdateOption).

asymptotic
solver tuple[type[SinglestepSolver | MultistepSolver]] | type[SinglestepSolver | MultistepSolver] | None

Solver class or tuple of solver classes used when simulation-based adjoint computation is selected (complete or unobserved).

None
dt float | None

Time-step used with the solver (required when solver is used).

None
interval_fraction float

Fraction of the input time series to use for gradient computation (value in (0, 1]).

1
Source code in src/otf/optim/gradient/adjoint.py
def __init__(
    self,
    system: BaseSystem,
    update_option: UpdateOption = UpdateOption.asymptotic,
    solver: tuple[type[SinglestepSolver | MultistepSolver]]
    | type[SinglestepSolver | MultistepSolver]
    | None = None,
    dt: float | None = None,
    interval_fraction: float = 1,
):
    """Initialize an `AdjointGradient`.

    Parameters
    ----------
    system
        `BaseSystem` instance to analyze.
    update_option
        Which adjoint/update method to use (`UpdateOption`).
    solver
        Solver class or tuple of solver classes used when simulation-based
        adjoint computation is selected (`complete` or `unobserved`).
    dt
        Time-step used with the solver (required when `solver` is used).
    interval_fraction
        Fraction of the input time series to use for gradient computation
        (value in (0, 1]).
    """
    super().__init__(system)

    if not (0 < interval_fraction <= 1):
        raise ValueError(
            "`interval_fraction` should be in (0, 1]"
            f" (was {interval_fraction})"
        )
    self._interval_fraction = interval_fraction

    self._compute_adjoint = self._set_up_adjoint_method(update_option)

    if update_option is not UpdateOption.asymptotic:
        if dt is None:
            raise ValueError("`dt` must not be None for this update option")
        if solver is None:
            raise ValueError(
                "`solver` must not be None for the given update option"
            )

        adjoint_system = self._set_up_adjoint_system(system, update_option)

        self._dt = dt
        self._solver = self._set_up_solver(adjoint_system, solver)

UpdateOption

Bases: Enum

Enum for selecting parameter update methods.

Options include:

  • asymptotic: Uses the asymptotic approximation of the observed portion of the adjoint.
  • complete: Uses the complete adjoint via simulation.
  • unobserved: Uses the asymptotic approximation of the observed portion of the adjoint and simulates the unobserved portion.