qrunch.chemistry.qrackle.scf.steppers.scf_stepper_protocol

Protocol for SCF steppers that produce a new density matrix.

Functions

assess_scf_trial(stepper, current_density, ...)

Assess an evaluated trial before adding it to SCF history or switching steppers.

same_scf_stepper(stepper_a, stepper_b)

Compare stepper types, options and any nested fallback configurations.

Classes

DeactivatedSCFStepper

SCF stepper that is deactivated and does nothing.

SCFFallbackStepperProtocol

Optional interface exposing the fallback as part of a stepper's configuration.

SCFStepperBuilderProtocol

Protocol for SCF stepper builders.

SCFStepperProtocol

Protocol for SCF steppers.

SCFTrialAssessmentProtocol

Optional feedback interface for steppers that can reject an evaluated trial.

class DeactivatedSCFStepper

Bases: object

SCF stepper that is deactivated and does nothing.

property can_update_scf_queue: bool

Deactivated stepper does not update the SCF queue.

create_new_density(scf_queue: SCFQueueProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], current_density: TSCFMatrix, current_fock: TSCFMatrix, core_hamiltonian: TSCFMatrix, overlap_matrix: TSCFMatrix, lowdin_orthogonalizer: TSCFMatrix, molecular_configuration: MolecularConfiguration, roothaan_hall_solver: RoothaanHallSolver[TSCFMatrix, TSCFVector, TMatrix, TVector], orbital_occupation: OrbitalOccupation) → TSCFMatrix

Perform an SCF step, which should never be called for the deactivated stepper.

Parameters:
  • scf_queue (SCFQueueProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector])

  • current_density (TSCFMatrix)

  • current_fock (TSCFMatrix)

  • core_hamiltonian (TSCFMatrix)

  • overlap_matrix (TSCFMatrix)

  • lowdin_orthogonalizer (TSCFMatrix)

  • molecular_configuration (MolecularConfiguration)

  • roothaan_hall_solver (RoothaanHallSolver[TSCFMatrix, TSCFVector, TMatrix, TVector])

  • orbital_occupation (OrbitalOccupation)

Return type:

TSCFMatrix

create_stepper(scf_matrix_module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], fock_builder: FockBuilderProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], fallback_scf_stepper_builder: SCFStepperBuilderProtocol | None = None) → DeactivatedSCFStepper

Create a new deactivated SCF stepper.

Parameters:
Return type:

DeactivatedSCFStepper

free() → None

Free any retained matrices.

Return type:

None

init_scf_queue(max_length: int) → SCFQueueProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]

Create an SCF queue.

Parameters:

max_length (int)

Return type:

SCFQueueProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]

property is_local_region_indicated: bool

Whether the SCF trajectory is in its local region.

property options: None

Absence of configurable stepping options.

reset() → None

Reset.

Return type:

None

class SCFFallbackStepperProtocol

Bases: Protocol[TSCFMatrix, TSCFVector, TMatrix, TVector]

Optional interface exposing the fallback as part of a stepper’s configuration.

__init__(*args, **kwargs)
property fallback_scf_stepper: SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]

Fallback used when the primary stepping method cannot propose a density.

class SCFStepperBuilderProtocol

Bases: Protocol

Protocol for SCF stepper builders.

The protocol itself is not generic: a single builder instance is able to construct steppers for any concrete matrix/vector types (for example the same builder is reused for the restricted and unrestricted spin channels). The type variables are therefore bound at the create_stepper() method level rather than at the class level.

__init__(*args, **kwargs)
create_stepper(scf_matrix_module: SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], fock_builder: FockBuilderProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], fallback_scf_stepper_builder: SCFStepperBuilderProtocol | None = None) → SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]

Create an SCF stepper for the supplied matrix module.

Parameters:
  • scf_matrix_module (SCFMatrixModuleProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – SCF matrix module (restricted or unrestricted).

  • fock_builder (FockBuilderProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – Builder for the Fock/Kohn-Sham matrix.

  • fallback_scf_stepper_builder (SCFStepperBuilderProtocol | None) – Optional builder for a fallback SCF stepper.

Return type:

SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]

class SCFStepperProtocol

Bases: Protocol[TSCFMatrix, TSCFVector, TMatrix, TVector]

Protocol for SCF steppers.

An SCF stepper takes the current state of the SCF calculation and produces a new AO density matrix for the next iteration. Steppers that reject trials also implement SCFTrialAssessmentProtocol. The driver assesses the evaluated density before recording history, declaring convergence or switching. A rejected trial is passed back to the same stepper to generate a retry.

__init__(*args, **kwargs)
property can_update_scf_queue: bool

Whether the stepper adds or modifies Fock/error entries in the SCF queue.

Some steppers (such as the Optimal Damping Algorithm) compute additional Fock information while producing the new density. When this property is True the stepper pushes those extra entries into the SCF queue inside create_new_density(), so that a later phase (for example DIIS) can reuse them. CROP with optimize="memory" instead replaces and removes existing entries.

create_new_density(scf_queue: SCFQueueProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], current_density: TSCFMatrix, current_fock: TSCFMatrix, core_hamiltonian: TSCFMatrix, overlap_matrix: TSCFMatrix, lowdin_orthogonalizer: TSCFMatrix, molecular_configuration: MolecularConfiguration, roothaan_hall_solver: RoothaanHallSolver[TSCFMatrix, TSCFVector, TMatrix, TVector], orbital_occupation: OrbitalOccupation) → TSCFMatrix

Produce a new AO density matrix from the current SCF state.

Parameters:
  • scf_queue (SCFQueueProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – The SCF queue containing Fock matrices and their associated error matrices.

  • current_density (TSCFMatrix) – The current density matrix.

  • current_fock (TSCFMatrix) – The current Fock (or Kohn-Sham) matrix.

  • core_hamiltonian (TSCFMatrix) – The core Hamiltonian \(h = T + V_{\mathrm{nuc}}\).

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

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

  • molecular_configuration (MolecularConfiguration) – The molecular configuration.

  • roothaan_hall_solver (RoothaanHallSolver[TSCFMatrix, TSCFVector, TMatrix, TVector]) – A Roothaan-Hall solver to solve the Roothaan-Hall equation.

  • orbital_occupation (OrbitalOccupation) – Electron occupation specifying how many orbitals are occupied.

Return type:

TSCFMatrix

free() → None

Free retained matrices without resetting optimization state.

Return type:

None

init_scf_queue(max_length: int) → SCFQueueProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]

Create a SCF queue.

Parameters:

max_length (int)

Return type:

SCFQueueProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]

property is_local_region_indicated: bool

Whether the stepper indicates that the SCF trajectory is in its local region.

property options: Any

Options used by the stepper.

reset() → None

Free retained matrices and reset the internal state of the SCF stepper.

Return type:

None

class SCFTrialAssessmentProtocol

Bases: Protocol[_TTrialMatrix_contra]

Optional feedback interface for steppers that can reject an evaluated trial.

__init__(*args, **kwargs)
assess_trial(current_density: _TTrialMatrix_contra, current_fock: _TTrialMatrix_contra, current_energy: float, overlap_matrix: _TTrialMatrix_contra, lowdin_orthogonalizer: _TTrialMatrix_contra) → bool

Assess a trial once; retain any rejected reference needed to propose a retry.

Parameters:
  • current_density (_TTrialMatrix_contra) – Evaluated AO trial density.

  • current_fock (_TTrialMatrix_contra) – Fock matrix at the trial density.

  • current_energy (float) – Electronic energy of the trial.

  • overlap_matrix (_TTrialMatrix_contra) – AO overlap matrix.

  • lowdin_orthogonalizer (_TTrialMatrix_contra) – Lowdin orthogonalizer.

Return type:

bool

assess_scf_trial(stepper: SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], current_density: TSCFMatrix, current_fock: TSCFMatrix, current_energy: float, overlap_matrix: TSCFMatrix, lowdin_orthogonalizer: TSCFMatrix) → bool

Assess an evaluated trial before adding it to SCF history or switching steppers.

Parameters:
  • stepper (SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – Stepper that proposed the evaluated density.

  • current_density (TSCFMatrix) – Evaluated AO density.

  • current_fock (TSCFMatrix) – Fock matrix at the evaluated density.

  • current_energy (float) – Electronic energy of the evaluated density.

  • overlap_matrix (TSCFMatrix) – AO overlap matrix.

  • lowdin_orthogonalizer (TSCFMatrix) – Lowdin orthogonalizer.

Return type:

bool

same_scf_stepper(stepper_a: SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector], stepper_b: SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) → bool

Compare stepper types, options and any nested fallback configurations.

Parameters:
  • stepper_a (SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – First stepper.

  • stepper_b (SCFStepperProtocol[TSCFMatrix, TSCFVector, TMatrix, TVector]) – Second stepper.

Return type:

bool