maxwelllink.mxl_drivers.python.batch package¶
Vectorized batch-model backends and their lazy registry.
- class maxwelllink.mxl_drivers.python.batch.BatchStepResult[source]¶
Bases:
objectColumnar physics outputs for one FDTD step (contiguous host arrays).
All arrays are host (NumPy) arrays in atomic units for a batch of
numsub-systems.- Variables:
amplitude_au (numpy.ndarray, shape (num, 3)) – Source amplitude
dmu/dtconsumed by the EM solver.dipole_half_au (numpy.ndarray, shape (num, 3)) – Dipole half a step after the force time (cavity coupling).
dipole_force_au (numpy.ndarray, shape (num, 3)) – Dipole at the force time (velocity-Verlet drift / dipole self-energy).
energy_au (numpy.ndarray, shape (num,)) – Per-sub-system energy (diagnostic).
- __init__(amplitude_au, dipole_half_au, dipole_force_au, energy_au)¶
- Parameters:
amplitude_au (ndarray)
dipole_half_au (ndarray)
dipole_force_au (ndarray)
energy_au (ndarray)
- Return type:
None
- amplitude_au: ndarray¶
- dipole_force_au: ndarray¶
- dipole_half_au: ndarray¶
- energy_au: ndarray¶
- class maxwelllink.mxl_drivers.python.batch.DummyBatchModel[source]¶
Bases:
objectA dummy vectorized batch model for demonstration purposes.
This class serves as a template for implementing GPU-batched moleular drivers. It advances
numsub-systems together with contiguous arrays and provides the interface consumed byGPUBatchBridge.Every batch model follows one constructor convention, so the bridge can build any of them the same way:
Model(num=..., driver_kwargs=..., backend=..., driver_args=..., store_additional_data=...)
with
backendone of'gpu'(CUDA through CuPy),'cpu'(the same vectorized model on the host) orNone(auto: GPU when CuPy reaches a CUDA device). The model resolves the array module frombackenditself; no array module ever crosses the interface.- append_additional_data()[source]¶
Append additional data for each sub-system to send back to MaxwellLink.
Notes
This method can be optionally overridden by subclasses to send additional data to MaxwellLink. We recommend including “time_au”, “energy_au”, and the dipole components at half-step time: “mux_au”, “muy_au”, “muz_au”, and the force-time dipole (
mux_m_au/muy_m_au/muz_m_au) in each dictionary, matching the scalar-driver format.- Returns:
One additional-data dictionary per sub-system (empty by default).
- Return type:
list of dict
- append_additional_data_columns(keys)[source]¶
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]¶
Release any device resources held by this batch model.
Notes
This method can be optionally overridden by subclasses to free device arrays (e.g. CuPy buffers). The default implementation does nothing.
- initialize(dt_au, molecule_ids)[source]¶
Set the shared time step and molecule IDs for this batch model.
This function is called by the GPU bridge once the group membership is known (the AGGINIT stage of aggregate socket communication).
Notes
This method should be overridden by subclasses to allocate their contiguous state. The base implementation only records the common bookkeeping shared by every batch model.
- Parameters:
dt_au (float) – The time step in atomic units (a.u.), shared by every sub-system.
molecule_ids (array-like of int) – Molecule IDs assigned by the hub, one per sub-system.
- step(efield_au)[source]¶
Advance every sub-system by one FDTD step given the effective E-field.
This method should be overridden by subclasses to implement specific vectorized propagation logic.
Notes
This method must be overridden by subclasses.
- Parameters:
efield_au (numpy.ndarray of float, shape (num, 3)) – Contiguous host array of effective electric field vectors in a.u., one
[E_x, E_y, E_z]row per sub-system.- Returns:
Columnar physics outputs (amplitude, dipoles, energy) for this step. This is the normative result contract: the bridge reads the four fields
amplitude_au,dipole_half_au,dipole_force_auandenergy_auby name, so any field-compatible object is accepted (the MD batch model returns the engine’sMDStepResultdirectly).- Return type:
- maxwelllink.mxl_drivers.python.batch.get_batch_model(backend, driver)[source]¶
Return the
DummyBatchModelsubclass for(backend, driver).The concrete model is imported lazily and imports no GPU library at module load, so this stays CUDA-free until a model is actually stepped.
- Parameters:
backend (str) – Batch backend name (currently only
"gpu").driver (str) – Batch driver name; see
supported_batch_drivers().
- Raises:
ValueError – If
(backend, driver)has no registered batch model.
- maxwelllink.mxl_drivers.python.batch.supported_batch_drivers(backend)[source]¶
Return the driver names supported for
backend(CUDA-free lookup).- Parameters:
backend (str)
- Return type:
tuple[str, …]