Skip to content

Core

Generated from the docstrings in the source code.

grid

wavefunction

WaveFunction3D(grid: Grid3D, psi: np.ndarray = None)

Source code in quantumlab/core/wavefunction.py
def __init__(self, grid: Grid3D, psi: np.ndarray=None):
    self.grid = grid
    if psi is None:
        self.psi = np.zeros(grid.shape, dtype=complex)
    else:
        if psi.shape != grid.shape:
            raise ValueError(f'psi shape {psi.shape} does not match grid shape {grid.shape}')
        self.psi = np.array(psi, dtype=complex)

slice_xy(z_idx: int = None) -> np.ndarray

Return the probability density slice |ψ|² in the XY plane at z index z_idx.

Source code in quantumlab/core/wavefunction.py
def slice_xy(self, z_idx: int=None) -> np.ndarray:
    """Return the probability density slice |ψ|² in the XY plane at z index z_idx."""
    if z_idx is None:
        z_idx = self.grid.N_z // 2
    return self.probability_density[:, :, z_idx]

slice_xz(y_idx: int = None) -> np.ndarray

Return the probability density slice |ψ|² in the XZ plane at y index y_idx.

Source code in quantumlab/core/wavefunction.py
def slice_xz(self, y_idx: int=None) -> np.ndarray:
    """Return the probability density slice |ψ|² in the XZ plane at y index y_idx."""
    if y_idx is None:
        y_idx = self.grid.N_y // 2
    return self.probability_density[:, y_idx, :]

slice_yz(x_idx: int = None) -> np.ndarray

Return the probability density slice |ψ|² in the YZ plane at x index x_idx.

Source code in quantumlab/core/wavefunction.py
def slice_yz(self, x_idx: int=None) -> np.ndarray:
    """Return the probability density slice |ψ|² in the YZ plane at x index x_idx."""
    if x_idx is None:
        x_idx = self.grid.N_x // 2
    return self.probability_density[x_idx, :, :]

absorbing_boundary

AbsorbingBoundaryLayer(grid, boundary_width: float, order: int = 3)

Polynomial absorbing boundary layer (ABL) for split-step Fourier simulations.

Applies a smooth mask to the wavefunction near the grid edges to prevent FFT wraparound artifacts from unphysical periodic boundary conditions.

The mask is 1.0 in the interior and transitions to 0.0 over a boundary region of width boundary_width using a polynomial profile of order order.

Parameters:

Name Type Description Default
grid Grid1D, Grid2D, or Grid3D

The spatial grid.

required
boundary_width float

Physical width of the absorbing layer at each edge.

required
order int

Polynomial order of the mask transition. Use 3 (smoothstep) for well-behaved transitions; higher orders give sharper roll-offs but may introduce reflections. Minimum effective order is 3.

3
Source code in quantumlab/core/absorbing_boundary.py
def __init__(self, grid, boundary_width: float, order: int = 3):
    self.grid = grid
    self.boundary_width = boundary_width
    self.order = order
    self.mask = self._build_mask()

apply(wavefunction)

Apply the absorbing mask to a wavefunction in-place.

Source code in quantumlab/core/absorbing_boundary.py
def apply(self, wavefunction):
    """Apply the absorbing mask to a wavefunction in-place."""
    wavefunction.psi *= self.mask
    return wavefunction

spectral

Dimension-agnostic helpers for spectral (FFT-based) operations on Grid1D / Grid2D / Grid3D. Used by the generic split-operator solver, the eigensolvers and the current/angular-momentum observables.

wavefunction_class(grid)

Return the WaveFunction class matching the grid dimensionality.

Source code in quantumlab/core/spectral.py
def wavefunction_class(grid):
    """Return the WaveFunction class matching the grid dimensionality."""
    return {1: WaveFunction1D, 2: WaveFunction2D, 3: WaveFunction3D}[ndim(grid)]

coordinates(grid)

Position meshes (X, Y, Z) truncated to the grid dimension.

Source code in quantumlab/core/spectral.py
def coordinates(grid):
    """Position meshes (X, Y, Z) truncated to the grid dimension."""
    d = ndim(grid)
    if d == 1:
        return (grid.x,)
    elif d == 2:
        return (grid.X, grid.Y)
    return (grid.X, grid.Y, grid.Z)

wavevectors(grid)

Angular wavenumber meshes (K_x, K_y, K_z) in FFT ordering.

Source code in quantumlab/core/spectral.py
def wavevectors(grid):
    """Angular wavenumber meshes (K_x, K_y, K_z) in FFT ordering."""
    d = ndim(grid)
    if d == 1:
        return (grid.k,)
    elif d == 2:
        return (grid.K_x, grid.K_y)
    return (grid.K_x, grid.K_y, grid.K_z)