neuralqx.experimental.vqs.mc.mc_state.expect_grad_biadjoint module

Experimental bi-covariance gradient for non-Hermitian operators.

For a generic (not necessarily Hermitian) operator A, define

\[E_A(\theta) = \frac{\langle \psi_\theta | A | \psi_\theta \rangle} {\langle \psi_\theta | \psi_\theta \rangle}.\]

For a real coordinate \(\eta\), the exact gradient can be written as

\[\partial_\eta E_A = \operatorname{Cov}_{p_\theta}(\overline{O_\eta}, L_A) + \operatorname{Cov}_{p_\theta}(O_\eta, \overline{L_{A^\dagger}}),\]

where

\[\begin{split}O_\eta(x) &= \partial_\eta \log \psi_\theta(x), \\ L_A(x) &= \frac{(A\psi_\theta)(x)}{\psi_\theta(x)}, \\ L_{A^\dagger}(x) &= \frac{(A^\dagger\psi_\theta)(x)}{\psi_\theta(x)}.\end{split}\]

In force notation:

\[F_A = \operatorname{Cov}(\overline{O_j}, L_A), \quad F_{A^\dagger} = \operatorname{Cov}(\overline{O_j}, L_{A^\dagger}).\]

For real parameters, \(g_j = F_{A,j} + \overline{F_{A^\dagger,j}}\).

This implementation reuses neuralqx.vqs.expect_and_forces() for both A and A†. For sequences we pass the full list at once, which preserves existing fused/unfused sequence behavior from the public forces API.

For complex holomorphic models, this module supports complex parameters through the same force/Wirtinger branch used by neuralqx.vqs.expect_and_forces(). For non-holomorphic models, it emits a warning and defers to the existing generic non-Hermitian VJP path by returning None to the dispatcher.

When all parameter leaves are complex and holomorphicity is satisfied, the implementation uses only the forward force term F_A and skips the adjoint-force evaluation as an optimization.

If an operator does not expose adjoint, this module emits a warning and returns None so callers can fall back to the generic non-Hermitian VJP path.

expect_and_grad_biadjoint(vstate, Ô, chunk_size, *, mutable=False)

Compute expectation and exact bi-covariance gradient for one operator.

Parameters:
Return type:

Optional[tuple[Stats, Any]]

Returns:

A (stats, grad) tuple when the operator exposes an adjoint, otherwise None to signal fallback to the generic non-Hermitian VJP path. This function also returns None when cfg.EXPERIMENTAL_GRAD is disabled, for non-holomorphic models, and for complex-typed operator objectives (except Squared which is real-valued by construction).

Notes

For holomorphic models with all-complex parameter leaves, this function uses only F_A (Wirtinger branch) and skips the adjoint-force pass.

expect_and_grad_biadjoint_sequence(vstate, Ô_list, chunk_size, *, mutable=False)

Compute expectation and exact bi-covariance gradient for a sequence.

Parameters:
Return type:

Optional[tuple[Stats, Any]]

Returns:

A (stats, grad) tuple when every operator exposes an adjoint, otherwise None to signal fallback to the generic non-Hermitian VJP path. This function also returns None when cfg.EXPERIMENTAL_GRAD is disabled, for non-holomorphic models, and for sequences that contain complex-typed operator terms (except Squared terms).

Notes

For holomorphic models with all-complex parameter leaves, this function uses only forward sequence forces F_A (Wirtinger branch) and skips the adjoint-force sequence pass.