maxwelllink.mxl_drivers.python.batch.sho_gpu module¶
GPU-batched simple-harmonic-oscillator (SHO) model built on the scalar SHOModel.
This driver runs one execution path on each backend:
CPU reference (
backend='cpu'): a vectorized velocity-Verlet step.GPU kernel (
xp=cupy): a fusednumba.cuda.jitkernel that gives one GPU thread to each oscillator.
- class maxwelllink.mxl_drivers.python.batch.sho_gpu.SHOGPUBatchModel[source]¶
Bases:
DummyBatchModelVectorized simple-harmonic-oscillator batch model.
- __init__(*, num, driver_kwargs, backend=None, driver_args=None, store_additional_data=False)[source]¶
Initialize a GPU-batched SHO model with a single template oscillator.
- Parameters:
num (int) – Number of oscillators in the batch; must be positive.
driver_kwargs (mapping) – Keyword arguments for the template
SHOModel.backend ({'cpu', 'gpu', None}, default: None) –
'gpu'runs the fused CUDA kernel through CuPy,'cpu'the same compiled physics through numba on the host;None(auto) picks the GPU when CuPy reaches a CUDA device.driver_args (sequence, optional) – Positional arguments for the template
SHOModel.store_additional_data (bool, default: False) – Reserved for the future columnar fast path.
- Raises:
ValueError – If
numis not positive, orcheckpoint/restart/verboseis enabled (unsupported for the batched GPU backend).
- append_additional_data()[source]¶
Return per-oscillator dicts matching
SHOModel.append_additional_data.- Returns:
One dictionary per oscillator with
time_au,energy_au, the half-step dipole (mux_au/muy_au/muz_au), the force-time dipole (mux_m_au/muy_m_au/muz_m_au), andp_au/q_au.- Return type:
list of dict
- Raises:
RuntimeError – If called before the first
step().
- append_additional_data_columns(keys)¶
Return the requested additional-data fields as one contiguous block.
This is the columnar form of
append_additional_data(), used when the hub asks for the"columnar"result format. The default builds it from the per-sub-system dictionaries, so every batch model works without changes; models that already hold the data in arrays should override this and skip the dictionaries entirely.- Parameters:
keys (sequence of str) – Field names to return, in column order.
- Returns:
The requested fields, one row per sub-system.
- Return type:
numpy.ndarray of float, shape (num, len(keys))
- close()[source]¶
Drop references to the oscillator state and output buffers.
Notes
CuPy frees the underlying device memory once these references are released.
- initialize(dt_au, molecule_ids)[source]¶
Allocate the contiguous oscillator state and output buffers.
On a CuPy backend this also compiles the fused CUDA kernel once.
- Parameters:
dt_au (float) – The shared time step in atomic units (a.u.).
molecule_ids (array-like of int) – Molecule IDs assigned by the hub; must number exactly
num.
- Raises:
ValueError – If the number of molecule IDs does not match
num.
- step(efield_au)[source]¶
Advance every oscillator by one velocity-Verlet step.
- Parameters:
efield_au (numpy.ndarray of float, shape (num, 3)) – Contiguous host array of effective electric field vectors in a.u.
- Returns:
Columnar amplitude (
dmu/dt), half-step dipole, force-time dipole, and energy for every oscillator.- Return type:
- Raises:
RuntimeError – If called before
initialize().ValueError – If
efield_audoes not have shape(num, 3).