maxwelllink.sockets.susceptibility module¶
SocketHub for Meep MXLSocketSusceptibility connections.
This module bridges Meep’s C-level MXLSocketSusceptibility to MaxwellLink
socket molecule drivers. A single TCP listener accepts two kinds of clients
and tells them apart by what they send first:
Ordinary
mxl_driverclients stay silent at connect time and are handed to the inheritedSocketHubbinding/stepping machinery (see_SusceptibilitySocketHubServer._register_driver_socket()).Meep rank clients send an
MXLINITheader immediately and are served by a dedicated per-rank handler (see_SusceptibilitySocketHubServer._serve_meep_rank()).
The user-facing entry point is SusceptibilitySocketHub, which launches
the server in a child process (so Meep holding the GIL cannot deadlock the
handshake) and exposes the host/port consumed by
mp.MXLSocketSusceptibility(hub=hub).
- class maxwelllink.sockets.susceptibility.SusceptibilitySocketHub[source]¶
Bases:
objectProcess-backed hub for Meep
MXLSocketSusceptibilityconnections.The public object starts immediately during construction and exposes the endpoint fields consumed by
mp.MXLSocketSusceptibility(hub=hub). The actual server runs in a child process because Meep’s long C-level time-step loop can hold Python’s GIL while waiting on the socket; an in-process Python thread would therefore deadlock at the firstMXLINIT/MXLREADYhandshake. The child server is_SusceptibilitySocketHubServer, which is theSocketHub-derived implementation that reuses MaxwellLink’s optimized driver binding and stepping path.Under MPI only the master rank launches the child server; every rank then learns the resolved endpoint through
mpi_bcast_from_master(), so all ranks agree on thehost/portto connect to.- Parameters:
host (str or None, optional) – Bind host for the server.
Noneuses the server default.port (int or None, default: 31415) – Bind port.
0requests an OS-chosen ephemeral port.timeout (float, default: 60000.0) – Socket timeout in seconds passed to the server.
latency (float, default: 0.05) – Polling interval in seconds passed to the server.
unixsocket (str or None, optional) – Reserved; must be falsy (TCP only).
- host¶
Resolved bind host of the running server.
- Type:
str
- port¶
Resolved bind port of the running server.
- Type:
int
- address¶
Alias of
host.- Type:
str
- rank_stats¶
Latest per-Meep-rank statistics drained from the child process.
- Type:
dict[int, dict]
- Raises:
ValueError – If
unixsocketis given.RuntimeError – If the child server fails to start.
- __init__(host=None, port=31415, timeout=60000.0, latency=0.05, unixsocket=None)[source]¶
- Parameters:
host (str | None)
port (int | None)
timeout (float)
latency (float)
unixsocket (str | None)
- lorentzian_conversion(frequency, sigma, resolution, *, gamma=0.0, dimensions=1, time_units_fs=0.1, mu0_au=187.0819866, orientation=0)[source]¶
Convert a Meep Lorentzian susceptibility to SHO driver parameters.
Maps the standard Meep Lorentzian dielectric parameters (resonance
frequency, oscillator strengthsigma) onto the simple-harmonic oscillator (SHO) molecular driver: a resonanceomegain atomic units, the fixed transition dipolemu0_au, and therescaling_factorthat the MeepMXLSocketSusceptibilityapplies so one socket molecule reproduces the per-cell Lorentzian response.- Parameters:
frequency (float) – Lorentzian resonance frequency in Meep units (must be > 0).
sigma (float) – Lorentzian oscillator strength (must be >= 0).
resolution (float) – Meep grid resolution in pixels per unit length (must be > 0); sets the grid-cell measure
(1 / resolution) ** dimensions.gamma (float, default: 0.0) – Lorentzian damping rate. Accepted for API symmetry but ignored: the current SHO driver is lossless (a warning is printed if nonzero).
dimensions (int, default: 1) – Simulation dimensionality, used to form the cell measure (>= 1).
time_units_fs (float, default: 0.1) – Meep time unit in femtoseconds; sets the Meep<->a.u. conversions.
mu0_au (float, default: 187.0819866) – SHO transition dipole moment in atomic units (must be nonzero).
orientation (int, default: 0) – Dipole axis:
0(x),1(y), or2(z).
- Returns:
Dictionary with two keys:
"rescaling_factor": float Value to pass tomp.MXLSocketSusceptibility(rescaling_factor=...)."driver_command": str Ready-to-run shell command that launches one matchingmxl_driver --model shoclient against this hub.
- Return type:
dict
- Raises:
ValueError – If any argument is outside its documented valid range.
- property rank_stats: dict[int, dict]¶
Latest per-Meep-rank statistics from the running server.
- Returns:
Mapping from rank to its stats row (
molecule_count,steps,requests,peer). Empty on non-master ranks.- Return type:
dict[int, dict]