qrunch.chemistry.qrackle.scf.steppers.scf_queue

SCF queue for storing Fock matrices and their associated DIIS error vectors.

Functions

compute_scf_gradient(module, scf_queue, ...)

Measure the RMS gradient, retaining only accepted Fock/error pairs in history.

compute_transformed_diis_error(...)

Compute the Lowdin-transformed DIIS commutator error.

Classes

SCFQueue

FIFO queue of Fock matrices and their associated transformed error matrices.

SCFQueueProtocol

Read/update interface shared by SCF history stores.

class SCFQueue

Bases: SCFQueueProtocol[TSCFMatrix, TSCFVector_co, TMatrix_co, TVector_co]

FIFO queue of Fock matrices and their associated transformed error matrices.

At each SCF iteration the queue stores the current Fock matrix together with the orthogonally transformed commutator error:

\[e = F D S - S D F\]
\[\begin{split}\\tilde{e} = L^T e L\end{split}\]

where \(L\) is the Lowdin orthogonalizer \(S^{-1/2}\).

When the queue exceeds max_length, the oldest entry is removed and its matrices are freed from the underlying matrix module.

__init__(scf_matrix_module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector_co, TMatrix_co, TVector_co], max_length: int) → None

Initialise the SCF queue.

Parameters:
  • scf_matrix_module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector_co, TMatrix_co, TVector_co]) – SCF matrix module for algebraic operations and memory management.

  • max_length (int) – Maximum number of Fock/error pairs to retain.

Return type:

None

property error_matrices: list[TSCFMatrix]

The stored transformed error matrices (oldest first).

property fock_matrices: list[TSCFMatrix]

The stored Fock matrices (oldest first).

free_queue() → None

Free all matrices in the queue.

Return type:

None

property length: int

The current number of entries in the queue.

property max_length: int

The maximum number of entries the queue can hold.

remove_oldest() → None

Remove and free the oldest Fock/error pair from the queue.

Does nothing if the queue is empty.

Return type:

None

replace_newest(coefficients: list[float]) → None

Replace the newest Fock/error pair with an affine combination of all stored pairs.

The combined error is a first-order estimate, see SCFQueueProtocol.replace_newest().

Parameters:

coefficients (list[float]) – Coefficients \(c_i\) for the stored pairs (oldest first).

Return type:

None

update(fock_matrix: TSCFMatrix, density_matrix: TSCFMatrix, overlap_matrix: TSCFMatrix, lowdin_orthogonalizer: TSCFMatrix) → None

Compute the transformed error and store the Fock matrix and error.

The error is computed as:

\[e = F D S - S D F\]
\[\begin{split}\\tilde{e} = L^T e L\end{split}\]

If the queue is full, the oldest Fock and error matrices are removed and freed from the underlying matrix module.

Parameters:
  • fock_matrix (TSCFMatrix) – The current Fock (or Kohn-Sham) matrix \(F\).

  • density_matrix (TSCFMatrix) – The current AO density matrix \(D\).

  • overlap_matrix (TSCFMatrix) – The overlap matrix \(S\).

  • lowdin_orthogonalizer (TSCFMatrix) – The Lowdin orthogonalizer \(L = S^{-1/2}\).

Return type:

None

class SCFQueueProtocol

Bases: Protocol[TSCFMatrix, TSCFVector_co, TMatrix_co, TVector_co]

Read/update interface shared by SCF history stores.

Implementations retain a rolling collection of Fock matrices together with their Lowdin-transformed DIIS error matrices, so that later phases (such as DIIS extrapolation) can reuse them. Both the standard SCFQueue and the Augmented Roothaan-Hall history store implement this protocol. CROP with optimize="memory" also edits the stored entries through remove_oldest() and replace_newest().

__init__(*args, **kwargs)
property error_matrices: list[TSCFMatrix]

The stored transformed error matrices (oldest first).

property fock_matrices: list[TSCFMatrix]

The stored Fock matrices (oldest first).

free_queue() → None

Free all matrices in the queue.

Return type:

None

property length: int

The current number of entries in the queue.

remove_oldest() → None

Remove and free the oldest entry.

Return type:

None

replace_newest(coefficients: list[float]) → None

Replace the newest entry with an affine combination of all stored entries.

Every stored matrix (Fock, error and any implementation-specific matrices) is combined with the same coefficients \(c_i\), which should sum to one. The combined error \(\sum_i c_i \tilde{e}_i\) is a first-order estimate: the commutator is bilinear in the Fock and density matrices, so it is not the commutator of the combined Fock matrix with any density.

Parameters:

coefficients (list[float]) – Coefficients \(c_i\) for the stored entries (oldest first).

Return type:

None

update(fock_matrix: TSCFMatrix, density_matrix: TSCFMatrix, overlap_matrix: TSCFMatrix, lowdin_orthogonalizer: TSCFMatrix) → None

Compute the transformed error and store the Fock matrix and error.

Parameters:
  • fock_matrix (TSCFMatrix)

  • density_matrix (TSCFMatrix)

  • overlap_matrix (TSCFMatrix)

  • lowdin_orthogonalizer (TSCFMatrix)

Return type:

None

compute_scf_gradient(module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector_co, TMatrix_co, TVector_co], scf_queue: SCFQueueProtocol[TSCFMatrix, TSCFVector_co, TMatrix_co, TVector_co], fock_matrix: TSCFMatrix, density_matrix: TSCFMatrix, overlap_matrix: TSCFMatrix, lowdin_orthogonalizer: TSCFMatrix, *, trial_accepted: bool, gradient_scale: float) → float

Measure the RMS gradient, retaining only accepted Fock/error pairs in history.

Parameters:
  • module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector_co, TMatrix_co, TVector_co]) – SCF matrix module.

  • scf_queue (SCFQueueProtocol[TSCFMatrix, TSCFVector_co, TMatrix_co, TVector_co]) – History shared by the active global and local steppers.

  • fock_matrix (TSCFMatrix) – Evaluated Fock matrix.

  • density_matrix (TSCFMatrix) – Evaluated density.

  • overlap_matrix (TSCFMatrix) – AO overlap matrix.

  • lowdin_orthogonalizer (TSCFMatrix) – Lowdin orthogonalizer.

  • trial_accepted (bool) – Whether the proposing stepper accepted the evaluated trial.

  • gradient_scale (float) – Scale factor for the size-consistent RMS gradient.

Return type:

float

compute_transformed_diis_error(scf_matrix_module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector_co, TMatrix_co, TVector_co], fock_matrix: TSCFMatrix, density_matrix: TSCFMatrix, overlap_matrix: TSCFMatrix, lowdin_orthogonalizer: TSCFMatrix) → TSCFMatrix

Compute the Lowdin-transformed DIIS commutator error.

The error is computed as \(e = F D S - S D F\) and then transformed with the Lowdin orthogonalizer \(L = S^{-1/2}\) to \(\tilde{e} = L^T e L\).

Parameters:
  • scf_matrix_module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector_co, TMatrix_co, TVector_co]) – SCF matrix module for algebraic operations and memory management.

  • fock_matrix (TSCFMatrix) – The current Fock (or Kohn-Sham) matrix \(F\).

  • density_matrix (TSCFMatrix) – The current AO density matrix \(D\).

  • overlap_matrix (TSCFMatrix) – The overlap matrix \(S\).

  • lowdin_orthogonalizer (TSCFMatrix) – The Lowdin orthogonalizer \(L = S^{-1/2}\).

Return type:

TSCFMatrix