Quantum 3xplorer (Q3)
An AI-native quantum simulation engine
Loading...
Searching...
No Matches
q3::PlanewaveDavidsonDiagonalizer Class Reference

#include <davidson.hpp>

+ Inheritance diagram for q3::PlanewaveDavidsonDiagonalizer:

Public Member Functions

 PlanewaveDavidsonDiagonalizer (const execution::ExecutionPolicy &execution_policy, execution::gpu::blas::GPUBLAS &gpu_blas, gpu::GPUFFTGrid *gpu_fft_grid, execution::gpu::lapack::GPUEigensolver &gpu_eigensolver, std::shared_ptr< execution::gpu::device::GPUDeviceBackend > device_backend)
 
 PlanewaveDavidsonDiagonalizer (const execution::ExecutionPolicy &execution_policy=default_serial_execution_policy, PlanewaveHamiltonianApplicator *hamiltonian_applicator=nullptr, PlanewaveSubspaceManager *subspace_manager=nullptr)
 
void invalidate_smooth_potential_cache () override
 
std::string name () const override
 
int number_of_unconverged_bands () const override
 
void release_workspace () override
 
void set_basis_expansion_factor (int factor) override
 
void set_cached_hubbard_projectors (int kpoint_index, const q3::Matrix< Complex > *projectors) override
 
void set_cached_projectors (int kpoint_index, const q3::Matrix< Complex > *projectors) override
 
void set_hubbard_d_matrix (const std::vector< Complex > *dense_d_matrix_column_major) override
 
void set_maximum_iterations (int maximum_iterations) override
 
void set_tolerance (Real tolerance) override
 
void set_use_mixed_precision (bool use_mixed_precision)
 
void solve (int kpoint_index_state, int kpoint_index, int number_of_plane_waves, int number_of_bands, const std::vector< int > &g_vector_indices, const std::vector< Real > &kinetic_energy_squared, const std::vector< Real > &real_space_potential, const Crystal &crystal_structure, const KPointsGrid &kpoint_grid, const PlanewaveBasis &planewave_basis, const NormConservingPlanewaveKohnShamQuantumSystem &pseudopotential_quantum_system, PlanewaveKohnShamQuantumSystem &quantum_system) override
 
- Public Member Functions inherited from q3::PlanewaveDiagonalizer
 ~PlanewaveDiagonalizer () override=default
 
- Public Member Functions inherited from q3::Diagonalizer
virtual ~Diagonalizer ()=default
 
virtual void set_first_iteration (bool)
 

Static Public Attributes

static const execution::SerialExecutionPolicy default_serial_execution_policy {}
 

Detailed Description

Davidson iterative diagonalizer. Finds only the lowest number_of_bands eigenvalues in O(number_of_plane_waves * number_of_bands) per iteration, vs O(number_of_plane_waves³) for direct.

Definition at line 351 of file davidson.hpp.

Constructor & Destructor Documentation

◆ PlanewaveDavidsonDiagonalizer() [1/2]

q3::PlanewaveDavidsonDiagonalizer::PlanewaveDavidsonDiagonalizer ( const execution::ExecutionPolicy &  execution_policy = default_serial_execution_policy,
PlanewaveHamiltonianApplicator *  hamiltonian_applicator = nullptr,
PlanewaveSubspaceManager *  subspace_manager = nullptr 
)
inlineexplicit

Construct the Davidson diagonalizer with an execution policy for band-group vector operations (dot_product, norm). Defaults to a serial (BLAS-only) policy if none is provided, preserving compatibility with existing call sites.

Optionally accepts a PlanewaveHamiltonianApplicator and/or PlanewaveSubspaceManager for delegation. If not provided, internal serial implementations are created on first solve() call.

Definition at line 365 of file davidson.hpp.

◆ PlanewaveDavidsonDiagonalizer() [2/2]

q3::PlanewaveDavidsonDiagonalizer::PlanewaveDavidsonDiagonalizer ( const execution::ExecutionPolicy &  execution_policy,
execution::gpu::blas::GPUBLAS &  gpu_blas,
gpu::GPUFFTGrid *  gpu_fft_grid,
execution::gpu::lapack::GPUEigensolver &  gpu_eigensolver,
std::shared_ptr< execution::gpu::device::GPUDeviceBackend >  device_backend 
)
inline

Construct a GPU-accelerated Davidson diagonalizer.

Stores GPU context (BLAS, FFT, device backend) for lazy construction of GPUPlanewaveHamiltonianApplicator and GPUPlanewaveSubspaceManager on first solve() call, when the Crystal/PlanewaveBasis are available.

Parameters
execution_policyExecution policy for band-group operations.
gpu_blasGPU BLAS wrapper. Must outlive this object.
gpu_fft_gridGPU FFT grid. Must outlive this object.
gpu_eigensolverGPU eigensolver. Must outlive this object.
device_backendGPU device backend (shared ownership).

Definition at line 392 of file davidson.hpp.

Member Function Documentation

◆ invalidate_smooth_potential_cache()

void q3::PlanewaveDavidsonDiagonalizer::invalidate_smooth_potential_cache ( )
inlineoverridevirtual

Invalidate the cached smooth grid potential. No-op if the applicator has not been created yet (nothing cached).

Reimplemented from q3::PlanewaveDiagonalizer.

Definition at line 474 of file davidson.hpp.

References q3::PlanewaveHamiltonianApplicator::invalidate_smooth_potential_cache().

◆ name()

std::string q3::PlanewaveDavidsonDiagonalizer::name ( ) const
inlineoverridevirtual

Implements q3::Diagonalizer.

Definition at line 996 of file davidson.hpp.

◆ number_of_unconverged_bands()

int q3::PlanewaveDavidsonDiagonalizer::number_of_unconverged_bands ( ) const
inlineoverridevirtual

How many bands the last solve() returned without meeting its tolerance: zero when it converged, and always zero for a solver that is not iterative.

Reimplemented from q3::PlanewaveDiagonalizer.

Definition at line 432 of file davidson.hpp.

◆ release_workspace()

void q3::PlanewaveDavidsonDiagonalizer::release_workspace ( )
inlineoverridevirtual

Free the working arrays once nothing will call solve() again in this run: the eigenvectors live in the quantum system and survive, the working basis and its Hamiltonian image do not need to. A later solve() allocates afresh. No-op for solvers without a persistent workspace.

Reimplemented from q3::PlanewaveDiagonalizer.

Definition at line 436 of file davidson.hpp.

◆ set_basis_expansion_factor()

void q3::PlanewaveDavidsonDiagonalizer::set_basis_expansion_factor ( int  factor)
inlineoverridevirtual

Set pre-computed KB projectors for a specific k-point. No-op if the applicator has not been created yet (before first solve()).

Reimplemented from q3::PlanewaveDiagonalizer.

Definition at line 418 of file davidson.hpp.

◆ set_cached_hubbard_projectors()

void q3::PlanewaveDavidsonDiagonalizer::set_cached_hubbard_projectors ( int  kpoint_index,
const q3::Matrix< Complex > *  projectors 
)
inlineoverridevirtual

Set pre-computed DFT+U (Hubbard) atomic-orbital projectors for a specific k-point. No-op if the applicator has not been created yet (before first solve()).

Reimplemented from q3::PlanewaveDiagonalizer.

Definition at line 451 of file davidson.hpp.

References q3::PlanewaveHamiltonianApplicator::set_cached_hubbard_projectors().

◆ set_cached_projectors()

void q3::PlanewaveDavidsonDiagonalizer::set_cached_projectors ( int  ,
const q3::Matrix< Complex > *   
)
inlineoverridevirtual

Set pre-computed KB projectors for a specific k-point. If set, the solver may use these instead of recomputing them. No-op by default; overridden by solvers that support caching.

Reimplemented from q3::PlanewaveDiagonalizer.

Definition at line 440 of file davidson.hpp.

References q3::PlanewaveHamiltonianApplicator::set_cached_projectors().

◆ set_hubbard_d_matrix()

void q3::PlanewaveDavidsonDiagonalizer::set_hubbard_d_matrix ( const std::vector< Complex > *  dense_d_matrix_column_major)
inlineoverridevirtual

Set the dense block-diagonal Hubbard D-matrix (refreshed once per SCF iteration). No-op if the applicator has not been created yet (before first solve()).

Reimplemented from q3::PlanewaveDiagonalizer.

Definition at line 463 of file davidson.hpp.

References q3::PlanewaveHamiltonianApplicator::set_hubbard_d_matrix().

◆ set_maximum_iterations()

void q3::PlanewaveDavidsonDiagonalizer::set_maximum_iterations ( int  maximum_iterations)
inlineoverridevirtual

Drop the working basis, its Hamiltonian image and the subspace: the largest thing the solver owns, and dead once the SCF has converged.

Reimplemented from q3::PlanewaveDiagonalizer.

Definition at line 428 of file davidson.hpp.

◆ set_tolerance()

void q3::PlanewaveDavidsonDiagonalizer::set_tolerance ( Real  )
inlineoverridevirtual

Set the convergence tolerance for iterative eigensolvers. No-op for direct solvers; overridden by Davidson and similar.

Reimplemented from q3::Diagonalizer.

Definition at line 1000 of file davidson.hpp.

◆ set_use_mixed_precision()

void q3::PlanewaveDavidsonDiagonalizer::set_use_mixed_precision ( bool  use_mixed_precision)
inline

Enable mixed-precision mode for GPU Davidson.

When enabled, the local potential FFT section of H|ψ⟩ runs in FP32 while kinetic energy and nonlocal projectors remain FP64.

Definition at line 410 of file davidson.hpp.

◆ solve()

void q3::PlanewaveDavidsonDiagonalizer::solve ( int  kpoint_index_state,
int  kpoint_index,
int  number_of_plane_waves,
int  number_of_bands,
const std::vector< int > &  g_vector_indices,
const std::vector< Real > &  kinetic_energy_squared,
const std::vector< Real > &  real_space_potential,
const Crystal &  crystal_structure,
const KPointsGrid &  kpoint_grid,
const PlanewaveBasis &  planewave_basis,
const NormConservingPlanewaveKohnShamQuantumSystem &  pseudopotential_quantum_system,
PlanewaveKohnShamQuantumSystem &  quantum_system 
)
inlineoverridevirtual

Solve the KS eigenvalue problem at one k-point. For NC-PP: H·ψ = ε·ψ (standard eigenvalue problem) For US-PP: H·ψ = ε·S·ψ (generalized eigenvalue problem)

Which spin channel this call belongs to.

The caller flattens (spin, k-point) into kpoint_index_state, so the channel is the quotient. The applicator needs it because the nonlocal D is per channel for ultrasoft and PAW; real_space_potential below is already this channel's, and the two have to agree.

Under a reciprocal-space distribution one rank holds G = 0, and the manager's gamma corrections must know whether this is that rank.

Only the size needs agreeing here. The collapse itself now forms each band range on one rank and allgathers, so the collapsed basis is already identical everywhere; republishing it would move three full arrays for nothing.

No Ritz vectors are formed. Convergence is decided on the eigenvalues, and the correction vectors below are built straight from the subspace coefficients into the free basis columns.

Expand subspace with preconditioned residuals if not converged

  1. Compute residuals and apply preconditioner.

Build the preconditioned corrections directly into the columns the basis is about to grow into, compacted over the unconverged bands. Nothing is staged through a residual array on the way.

Only the size needs agreeing here. The collapse itself now forms each band range on one rank and allgathers, so the collapsed basis is already identical everywhere; republishing it would move three full arrays for nothing.

Implements q3::PlanewaveDiagonalizer.

Definition at line 480 of file davidson.hpp.

References q3::NormConservingPlanewaveBasis::beta_function_table(), q3::execution::ExecutionPolicy::broadcast_across_bands(), q3::ProfilingCounters::DavidsonTimingAccumulator::collapse_time_ms, q3::compute_kleinman_bylander_projectors(), q3::create_overlap_operator(), q3::ProfilingCounters::davidson_iteration_count, q3::ProfilingCounters::davidson_timing, q3::log::debug(), q3::ProfilingCounters::DavidsonTimingAccumulator::diagonalize_time_ms, q3::PlanewaveKohnShamQuantumSystem::eigenvalue(), q3::math::tolerances::empty_band_tolerance_floor, q3::math::tolerances::empty_band_tolerance_relaxation_factor, q3::execution::ExecutionPolicy::global_number_of_elements(), q3::ProfilingCounters::DavidsonTimingAccumulator::hamiltonian_application_time_ms, q3::ProfilingCounters::instance(), q3::KPointsGrid::number_of_kpoints(), q3::PlanewaveKohnShamQuantumSystem::number_of_occupied_bands_per_spin(), q3::ProfilingCounters::DavidsonTimingAccumulator::orthogonalize_time_ms, q3::NormConservingPlanewaveKohnShamQuantumSystem::pseudopotential_basis(), q3::NormConservingPlanewaveBasis::pseudopotential_set(), q3::ProfilingCounters::DavidsonTimingAccumulator::residual_time_ms, q3::ProfilingCounters::DavidsonTimingAccumulator::ritz_vector_time_ms, q3::ProfilingCounters::DavidsonTimingAccumulator::seed_time_ms, q3::ProfilingCounters::DavidsonTimingAccumulator::subspace_update_time_ms, q3::NormConservingPlanewaveBasis::total_number_of_projectors(), and q3::log::warn().

Member Data Documentation

◆ default_serial_execution_policy

const execution::SerialExecutionPolicy q3::PlanewaveDavidsonDiagonalizer::default_serial_execution_policy {}
inlinestatic

Definition at line 354 of file davidson.hpp.

Referenced by q3::cli::run_gpu_entry_point().


The documentation for this class was generated from the following file: