API reference

This section documents the main zkit modules and classes. Use sphinx.ext.autodoc to render signatures and docstrings directly from the source.

zkit.io

zkit.analytic

Exact eigenstates and transition dipoles of reference systems.

Atomic units, hbar = 1. These are the references for TDSE-Z’s eigensolver and for the transition dipoles d_ij = <i|x_a|j> computed by dipoles.x (zkit.io.tdm.read_tdm()).

Harmonic oscillator, V = sum_a m w_a^2 x_a^2 / 2 (1D, 2D, 3D), product states |n_x n_y n_z> with E = sum_a w_a (n_a + 1/2) and

<n|x_a|n+1> = sqrt((n + 1) / (2 m w_a)) (all other quantum numbers equal),

zero otherwise. With distinct frequencies the low-lying levels are non-degenerate, so states can be matched by energy and |d_ij| compared independently of the arbitrary eigenvector phases.

Static Kramers-Henneberger frame (TDSE-Z Mode = kh): for an oscillator the cycle-averaged potential is V_KH = V + m w0^2 <|alpha|^2> / 2, so every level shifts by m w0^2 alpha0^2 / 4 for a linear field (alpha = alpha0 sin wt) and m w0^2 alpha0^2 / 2 for a circular one (|alpha| = alpha0), with the quiver amplitude alpha0 = |q| E0 / (m w^2) (kh_oscillator_shift()).

Particle in a box [a, a + L] (hard walls): E_n = pi^2 n^2 / (2 m L^2) and, for n != m,

<n|x|m> = -8 L n m / (pi^2 (n^2 - m^2)^2) if n + m is odd, else 0.

zkit.analytic.box_energies(length, n_states, mass=1.0)

E_n = pi^2 n^2 / (2 m L^2), n = 1 .. n_states.

Parameters:
  • length (float)

  • n_states (int)

  • mass (float)

Return type:

ndarray

zkit.analytic.kh_oscillator_shift(omega0, e0, omega, mass=1.0, charge=-1.0, circular=False)

Level shift of an oscillator (frequency omega0 along the field) in the static Kramers-Henneberger frame, for a field of amplitude e0 and frequency omega: m w0^2 alpha0^2 / 4 (linear) or / 2 (circular), alpha0 = |q| e0 / (m omega^2).

Parameters:
  • omega0 (float)

  • e0 (float)

  • omega (float)

  • mass (float)

  • charge (float)

  • circular (bool)

Return type:

float

zkit.analytic.box_tdm(length, n_states, start=None)

Exact <n|x|m> of a hard-wall box of width length (box [start, start + L], centred at 0 by default), for n, m = 1 .. n_states.

Returns {“energies”: (N,), “x”: (N, N)}.

Parameters:
  • length (float)

  • n_states (int)

  • start (float)

Return type:

dict

zkit.analytic.compare_tdm(numeric, numeric_energies, reference)

Compare numerical transition dipoles with a reference by matching states in energy order (both sets non-degenerate).

numeric maps an axis ("x", "tdm_x", …) to an (N, N) complex matrix; reference is the output of oscillator_tdm() or box_tdm(). Off-diagonal magnitudes |d_ij| are compared (eigenvector phases are arbitrary). Returns {axis: max |(|d| - |d_ref|)| / max |d_ref|}, plus "energies": the max relative energy error.

Parameters:
  • numeric (dict)

  • numeric_energies (ndarray)

  • reference (dict)

Return type:

dict

zkit.analytic.is_nondegenerate(reference, gap=1e-06)

Whether the reference levels, and the first level above them, are all separated by more than gap (a reference dict or an array of energies).

Parameters:

gap (float)

Return type:

bool

zkit.analytic.oscillator_states(omega, n_states)

The n_states lowest product states of an (anisotropic) oscillator.

Returns (quantum numbers, (n_states, dim) int array; energies, (n_states,)). Ties are broken by the quantum numbers, so check is_nondegenerate() before matching numerical states by energy.

Parameters:
  • omega (Sequence[float])

  • n_states (int)

Return type:

tuple

zkit.analytic.oscillator_tdm(omega, n_states, mass=1.0)

Exact dipole matrices <i|x_a|j> (real, phase convention of the ladder operators) between the n_states lowest oscillator states.

Returns {“energies”: (N,), “states”: (N, dim), “x”: (N, N), “y”: …, “z”: …} with one matrix per axis of omega.

Parameters:
  • omega (Sequence[float])

  • n_states (int)

  • mass (float)

Return type:

dict

zkit.viz

zkit.photoelectron, zkit.hhg, zkit.benchmark

Photoelectron spectra from t-SURFF amplitudes.

TDSE-Z writes |b(k)|^2 on a Cartesian momentum grid (or a list of momenta); SCID-TDSE writes A(k) on a spherical (|k|, theta, phi) grid. These helpers put both on the same spherical grid and reduce them to dP/dE, angular distributions and yields per energy window. Atomic units throughout, unit mass outside the surface (E = k^2 / 2).

zkit.photoelectron.angular_distribution(energy, density, at, normalise=True)

dP/d^3k versus theta at the grid energy closest to at.

Returns (E_used, values); with normalise the maximum is one.

Parameters:
  • energy (ndarray)

  • density (ndarray)

  • at (float)

  • normalise (bool)

Return type:

tuple

zkit.photoelectron.ati_peaks(omega, ip, e0, orders)

ATI peak energies n*omega - Ip - Up for a field of amplitude e0.

Parameters:
  • omega (float)

  • ip (float)

  • e0 (float)

  • orders (Iterable[int])

Return type:

list

zkit.photoelectron.compare_spectra(energy, test, reference, regions=None, peak_fraction=0.1, window=None)

Yield ratios test/reference per window and the point-wise ratio range where the reference exceeds peak_fraction of its maximum (inside the energy window (lo, hi) when given; pointwise_energy is the range used).

Parameters:
  • energy (ndarray)

  • test (ndarray)

  • reference (ndarray)

  • regions (Iterable[tuple] | None)

  • peak_fraction (float)

  • window (tuple | None)

Return type:

dict

zkit.photoelectron.energy_spectrum(k, theta, density)

dP/dE from dP/d^3k on a (|k|, theta) grid, assuming azimuthal symmetry.

dP/dE = k * 2 pi * int dP/d^3k sin(theta) dtheta. Returns (E, dP/dE).

Parameters:
  • k (ndarray)

  • theta (ndarray)

  • density (ndarray)

Return type:

tuple

zkit.photoelectron.region_yields(energy, dpde, regions)

Integral of dP/dE over each (lo, hi[, label]) window, keyed by label.

Parameters:
  • energy (ndarray)

  • dpde (ndarray)

  • regions (Iterable[tuple])

Return type:

dict

zkit.photoelectron.scid_energy_spectrum(spec)

(E, dP/dE) of a SCID-TDSE spectrum, averaged over its phi values.

Parameters:

spec (ScidSpectrum)

Return type:

tuple

zkit.photoelectron.to_spherical(spec, k, theta, phi=0.0)

|b(k)|^2 of a TDSE-Z grid spectrum at (|k|, theta) for the azimuth phi.

The polar axis is z (the last momentum axis). Axes of length one (a k_y = 0 plane, say) are dropped: the points are taken in that plane. Points outside the momentum grid get zero. Returns an array (n_k, n_theta).

Parameters:
  • spec (SurffSpectrum)

  • k (ndarray)

  • theta (ndarray)

  • phi (float)

Return type:

ndarray

High-harmonic spectra from the dipole, the dipole velocity or the acceleration.

zkit.hhg.harmonic_spectrum(time, signal, kind='dipole', omega0=None, window='hann', pad=8)

Emitted spectrum |omega^2 d(omega)|^2 of a uniformly sampled time series.

Parameters:
  • time (ndarray) – Uniform time grid and the dipole <d>(t), its velocity or its acceleration (kind). The dipole is multiplied by omega^2 and the velocity by omega, so all three give the same acceleration form.

  • signal (ndarray) – Uniform time grid and the dipole <d>(t), its velocity or its acceleration (kind). The dipole is multiplied by omega^2 and the velocity by omega, so all three give the same acceleration form.

  • omega0 (float | None) – Laser frequency; when given the frequency axis is returned in harmonic orders omega / omega0.

  • window (str) – "hann" (default) or "none".

  • pad (int) – Zero-padding factor of the FFT.

  • kind (str)

Return type:

(frequency or harmonic order, spectrum)

zkit.hhg.log_ratio(a, b, mask=None)

Median |log10(a / b)| (in decades) over mask and where b > 0.

Parameters:
  • a (ndarray)

  • b (ndarray)

  • mask (ndarray | None)

Return type:

float

One-to-one comparison of a TDSE-Z run with a SCID-TDSE run.

Both runs must describe the same physics: the same atom, a linearly polarised field along z, and t-SURF(F) amplitudes in the canonical momentum. SCID-TDSE outputs are read from its detail_output and sts_volkov_table (or sts_coulomb_table) files.

class zkit.benchmark.ScidComparison(time, field, dipole, acceleration, order, harmonics, k, theta, energy, density, dpde, peaks, metrics=<factory>, labels=('TDSE-Z', 'SCID-TDSE'))

Data and metrics of a TDSE-Z / SCID-TDSE comparison.

Parameters:
  • time (ndarray)

  • field (dict)

  • dipole (dict)

  • acceleration (dict)

  • order (ndarray)

  • harmonics (dict)

  • k (ndarray)

  • theta (ndarray)

  • energy (ndarray)

  • density (dict)

  • dpde (dict)

  • peaks (list)

  • metrics (dict)

  • labels (tuple)

zkit.benchmark.compare_with_scid(run_dir, basename, scid_detail, scid_pes, omega, e0, ip=0.5, orders=(2, 3), regions=None, max_order=5.5)

Compare a TDSE-Z run (run_dir, input basename) with SCID-TDSE tables.

The TDSE-Z run must have SaveDipoleAxes including z and a grid-mode t-SURFF file (TSurff = 1) holding the (k_x, k_z) plane or a cube. The TDSE-Z spectrum is interpolated onto SCID-TDSE’s (|k|, theta) grid.

Parameters:
  • run_dir (str | Path)

  • basename (str)

  • scid_detail (str | Path)

  • scid_pes (str | Path)

  • omega (float)

  • e0 (float)

  • ip (float)

  • orders (tuple)

  • regions (list | None)

  • max_order (float)

Return type:

ScidComparison

zkit.benchmark.plot_comparison(cmp, outdir, surff_file=None, scid_pes=None, prefix='scid', dpi=180)

Write the time-series, harmonic, dP/dE, angular and (with both files) momentum-map figures of a comparison; returns the written paths.

Parameters:
  • cmp (ScidComparison)

  • outdir (str | Path)

  • surff_file (str | Path | None)

  • scid_pes (str | Path | None)

  • prefix (str)

  • dpi (int)

Return type:

list

zkit.simulation

zkit.physics

zkit.mwigner