qrunch.tools.minimizers.last_n_parameter_minimizer

Last-N parameter wrapper minimizer.

This module provides LastNParameterMinimizer, a lightweight adaptor that exposes an arbitrary fixed-k or multi-parameter Minimizer as a minimizer over a larger parameter vector while only re-optimizing the last ``N`` (most recently appended) parameters. Earlier parameters are held fixed to their supplied values in initial_guess. This pattern is useful in adaptive / growing ansatz strategies (e.g. ADAPT-VQE-style algorithms) where new parameters are appended over time and, at certain stages, only the freshly introduced subset should be relaxed without disturbing the previously converged portion of the state preparation circuit.

Key idea

Given a full parameter vector theta R^P and num_last_parameters = N:

  • Split theta = [theta_fixed, theta_var] with theta_var containing the

    final N entries (or all entries if P < N).

  • Wrap the user objective so that the underlying minimizer only sees and

    updates theta_var while the fixed prefix is transparently re-concatenated for every batch evaluation.

  • Invoke the inner minimizer (default: FftMinimizer)

    on the reduced N-dimensional problem.

  • Return the stitched full vector and the true objective value at that point.

Batch semantics

The wrapper preserves the batching contract of the base minimizer / objective: the user-supplied function always receives full parameter vectors—this module simply constructs them by concatenating the frozen prefix with each candidate tail vector proposed by the inner minimizer.

Classes

LastNParameterMinimizer

Minimizer that takes either a `Minimizer` minimizer and optimizes the last/latest/newest `self._options.num_last_parameters` variables.

LastNParameterMinimizerOptions

Options controlling LastNParameterMinimizer.

class LastNParameterMinimizer

Bases: Minimizer

Minimizer that takes either a `Minimizer` minimizer and optimizes the last/latest/newest `self._options.num_last_parameters` variables.

__init__(minimizer: Minimizer | None = None, options: LastNParameterMinimizerOptions | None = None) None

Initialize a LastNParameterMinimizer.

Parameters:
Return type:

None

minimize(function: Callable[[list[ndarray[Any, dtype[float64]]]], list[float]], initial_guess: ndarray[Any, dtype[float64]], iteration: int | None, bounds: tuple[float, float] | list[tuple[float, float]] | None = None, circuit: Circuit | None = None, operator: HermitianPauliSum | None = None) MinimizerResult

Minimize the objective varying only the last N parameters.

This method wraps the underlying minimizer (default FftMinimizer) so that only the final num_last_parameters entries of the full parameter vector are optimized while the leading prefix is held fixed at the values supplied in initial_guess. If the total number of parameters P is less than num_last_parameters, all available parameters are optimized.

Batching semantics are preserved: the user-supplied function always receives full length-P vectors. Internally we slice out the tail block passed to the inner minimizer and re-concatenate the fixed prefix for each candidate evaluation in the batch.

Parameters:
  • function (Callable[[list[ndarray[Any, dtype[float64]]]], list[float]]) – Callable[[list[NDArray[float64]]], list[float]] Batch objective: maps a list of full parameter vectors (shape (P,)) to a list of scalar objective values of equal length.

  • initial_guess (ndarray[Any, dtype[float64]]) – ndarray(float64) Full starting parameter vector (shape (P,)). Must be provided.

  • iteration (int | None) – int | None If applicable, the current adaptive iteration. If not applicable, set to None. This can be used by some minimizers.

  • bounds (tuple[float, float] | list[tuple[float, float]] | None) – (float, float) | list[tuple[float, float]] | None, optional Global bounds specification (see above). Only the tail slice is used.

  • circuit (Circuit | None) – The parameterized circuit to be minimized.

  • operator (HermitianPauliSum | None) – The operator used in the expectation value.

Return type:

MinimizerResult

class LastNParameterMinimizerOptions

Bases: DataclassPublicAPI

Options controlling LastNParameterMinimizer.

All fields are immutable (frozen=True) so an instance can be safely reused.

Parameters:

num_last_parameters – int, default=1 Number of trailing (most recently added / last in ordering) parameters to optimize while keeping all earlier parameters fixed. If the total number of available parameters is smaller, all available parameters are optimized.

__init__(*, num_last_parameters: int = 1) None
Parameters:

num_last_parameters (int)

Return type:

None

static __new__(cls, *args: Any, **kwargs: Any) Any
Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

num_last_parameters: int = 1