qimpy.grid.Grid

class Grid(*, lattice, symmetries, comm, checkpoint_in=(None, ''), ke_cutoff_wavefunction=None, ke_cutoff=None, shape=None)

Bases: TreeNode

Real and reciprocal space grids for a unit cell. The grid could either be local or distributed over an MPI communicator, and this class provides FFT routines to switch fields on these grids, and routines to convert fields between grids.

Parameters:
  • lattice (Lattice) –

  • symmetries (Symmetries) –

  • comm (Comm | None) –

  • checkpoint_in (CheckpointPath) –

  • ke_cutoff_wavefunction (Optional[float]) –

  • ke_cutoff (float) –

  • shape (tuple[int, ...]) –

__init__(*, lattice, symmetries, comm, checkpoint_in=(None, ''), ke_cutoff_wavefunction=None, ke_cutoff=None, shape=None)

Create local or distributed grid for lattice.

Parameters:
  • lattice (Lattice) – Lattice whose reciprocal lattice vectors define plane-wave basis

  • symmetries (Symmetries) – Symmetries with which grid dimensions will be made commensurate, checked if specified explicitly by shape below and used for symmetrization of Field’s associated with this grid.

  • comm (Comm | None) – Communicator to split grid (and its FFTs) over, if provided.

  • ke_cutoff_wavefunction (float | None) – Plane-wave kinetic-energy cutoff in \(E_h\) for any electronic wavefunctions to be used with this grid. This is an internally set parameter that effectively sets the default for ke_cutoff to 4 * ke_cutoff_wavefunction, and has no effect if either ke_cutoff or shape is specified explicitly.

  • ke_cutoff (float | None) – [Input file] Kinetic-energy cutoff for grid in Hartrees. If unspecified, this is taken to be its minimum value: 4x the wavefunction kinetic energy cutoff. This has no effect if shape is specified explicitly.

  • shape (Sequence[int] | None) – [Input file] Explicit grid dimensions [Nx, Ny, Nz]. Highest precedence, and if specified, will supercede ke_cutoff.

  • checkpoint_in (CheckpointPath) –

Return type:

None

Methods

__init__

Create local or distributed grid for lattice.

add_child

Construct child object self.`attr_name` of type cls.

add_child_one_of

Invoke add_child on one of several child options in args.

fft

Forward Fast Fourier Transform.

get_Gmax

Get maximum wave-vector magnitude of the FFT grid.

get_gradient_operator

Get gradient operator in reciprocal space.

get_mesh

Get mesh integer coordinates for real or reciprocal space

ifft

Inverse Fast Fourier Transform.

save_checkpoint

Save self and all children in hierarchy to cp_path.

Attributes

dV

Volume per grid point (real-space integration weight).

field_symmetrizer

Symmetrizer for fields on this grid (initialized on first use).

weight2H

Hermitian-symmetry weights for reduced reciprocal space.

lattice

symmetries

comm

Communicator to split grid and FFTs over

n_procs

Size of comm

i_proc

Rank within comm

is_split

Whether the grid is split over MPI

ke_cutoff

Kinetic energy of Nyquist-frequency plane-waves

shape

Global real-space grid dimensions

shapeH

Global half-reciprocal-space grid dimensions

shapeR_mine

Local real grid dimensions

shapeG_mine

Local reciprocal grid dimensions

shapeH_mine

Local half-reciprocal grid dimensions

split0

MPI split of real-space dimension 0

split2

MPI split of reciprocal dimension 2

split2H

MPI split of half-reciprocal dimension 2

child_names

Names of attributes with child objects.

fft(v)

Forward Fast Fourier Transform. This method dispatches to complex-to-complex or real-to-complex transforms depending on whether the input v is complex or real. Note that QimPy applies normalization in forward transforms, corresponding to norm=’forward’ in the torch.fft routines. This makes the G=0 components in reciprocal space correspond to the mean value of the real space version.

Parameters:

v (torch.Tensor (complex or real)) – Last 3 dimensions must match shapeR_mine, and any preceding dimensions are batched over.

Returns:

Last 3 dimensions will be shapeG_mine or shapeH_mine, depending on whether v is complex or real respectively, preceded by any batch dimensions in the input.

Return type:

torch.Tensor (complex)

get_Gmax()

Get maximum wave-vector magnitude of the FFT grid.

Return type:

float

get_gradient_operator(space)

Get gradient operator in reciprocal space.

Parameters:

space ({'G', 'H'}) – Which space to compute mesh coordinates for: ‘G’ = full reciprocal space and ‘H’ = half or Hermitian-symmetric recipocal space.

Returns:

Tensor with dimensions (3,) + shape_mine, where shape_mine is the relevant local dimensions of requested space

Return type:

Tensor

get_mesh(space, mine=True)

Get mesh integer coordinates for real or reciprocal space

Parameters:
  • space ({'R', 'G', 'H'}) – Which space to compute mesh coordinates for: ‘R’ = real space, ‘G’ = full reciprocal space and ‘H’ = half or Hermitian-symmetric recipocal space resulting from FFT of real functions on grid.

  • mine (bool) – Only get local portion of mesh if True (default). Otherwise, get the entire mesh, even if grid is split over MPI.

Returns:

Integer tensor with dimensions shape_mine + (3,), where shape_mine is the relevant local dimensions of requested space if mine is True (and with shape, instead if mine is False).

Return type:

Tensor

ifft(v)

Inverse Fast Fourier Transform. This method dispatches to complex-to-complex or complex-to-real transforms depending on whether the last three dimensions of v match shapeG_mine or shapeH_mine respectively. Note that QimPy applies normalization in forward transforms (see qimpy.grid.Grid.fft()).

Parameters:

v (torch.Tensor (complex)) – Last 3 dimensions must match shapeG_mine, and any preceding dimensions are batched over

Returns:

Last 3 dimensions will be shapeR_mine, preceded by any batch dimensions in the input. The result will be complex or real, depending on whether the last three dimensions of v match shapeG_mine or shapeH_mine.

Return type:

torch.Tensor (complex or real)

comm: Comm | None

Communicator to split grid and FFTs over

property dV: float

Volume per grid point (real-space integration weight).

property field_symmetrizer: FieldSymmetrizer

Symmetrizer for fields on this grid (initialized on first use).

i_proc: int

Rank within comm

is_split: bool

Whether the grid is split over MPI

ke_cutoff: float

Kinetic energy of Nyquist-frequency plane-waves

n_procs: int

Size of comm

shape: tuple[int, ...]

Global real-space grid dimensions

shapeG_mine: tuple[int, ...]

Local reciprocal grid dimensions

shapeH: tuple[int, ...]

Global half-reciprocal-space grid dimensions

shapeH_mine: tuple[int, ...]

Local half-reciprocal grid dimensions

shapeR_mine: tuple[int, ...]

Local real grid dimensions

split0: TaskDivision

MPI split of real-space dimension 0

split2: TaskDivision

MPI split of reciprocal dimension 2

split2H: TaskDivision

MPI split of half-reciprocal dimension 2

property weight2H: Tensor

Hermitian-symmetry weights for reduced reciprocal space.