slsqp_jax.inner.masking

Shared make_active_subproblem helper that masks (A, b, hvp_fn, g) down to the active rows / free variables — used identically by every inner solver.

slsqp_jax.inner.masking

Shared active-row masking + bound-fix helper for inner solvers.

The three projector-based inner solvers (ProjectedCGCholesky, ProjectedCGCraig, MinresQLPSolver) all start from the same five-line preamble: mask A and b to the active rows, optionally project away the bound-fixed columns, and build a working HVP and effective gradient that hide the fixed coordinates from the iteration.

Before this module that preamble was copy-pasted in three places. This module hosts the single shared implementation.

class slsqp_jax.inner.masking.ActiveSubproblem[source]

Bases: NamedTuple

Data carried by every projector-based inner solver after masking.

Attributes:
A_work: A with inactive rows zeroed and (when bound-fixing

is in effect) fixed columns zeroed.

b_work: b with inactive entries zeroed and the fixed-column

contribution A_masked @ d_fixed subtracted.

free_mask: Boolean mask of free variables (ones(n) when no

bound fixing).

d_fixed: Fixed-variable values on bound-active coordinates

(zeros elsewhere; zeros everywhere when no bound fixing).

has_fixed: True iff any coordinate is bound-fixed. hvp_work: Working-subspace HVP. Equals hvp_fn when no

bound-fixing; otherwise v -> _free * hvp_fn(_free * v) so the iteration only sees the free coordinates.

g_eff: Effective gradient. Equals g when no bound-fixing;

otherwise _free * (g + hvp_fn(d_fixed)) to absorb the fixed-column cross-coupling into the linear term.

A_work: Float[Array, 'm n']

Alias for field number 0

b_work: Float[Array, 'm']

Alias for field number 1

free_mask: Bool[Array, 'n']

Alias for field number 2

d_fixed: Float[Array, 'n']

Alias for field number 3

has_fixed: bool

Alias for field number 4

hvp_work: Callable[[Float[Array, 'n']], Float[Array, 'n']]

Alias for field number 5

g_eff: Float[Array, 'n']

Alias for field number 6

slsqp_jax.inner.masking.make_active_subproblem(hvp_fn, g, A, b, active_mask, free_mask=None, d_fixed=None)[source]

Build the masked subproblem consumed by every projector-based solver.

Implements the shared preamble:

  1. A_masked = A with inactive rows zeroed.

  2. b_masked = b with inactive entries zeroed.

  3. If bound-fixing is in effect (free_mask and d_fixed both provided), zero the fixed columns of A_masked and absorb the fixed-column contribution into b_work.

  4. Build hvp_work and g_eff so the iteration only sees the free coordinates.

See ActiveSubproblem for the field semantics.

Return type:

ActiveSubproblem

Parameters:
  • hvp_fn (Callable[[Float[Array, 'n']], Float[Array, 'n']])

  • g (Float[Array, 'n'])

  • A (Float[Array, 'm n'])

  • b (Float[Array, 'm'])

  • active_mask (Bool[Array, 'm'])

  • free_mask (Bool[Array, 'n'] | None)

  • d_fixed (Float[Array, 'n'] | None)