STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
engine.accel.stability Namespace Reference

Functions

 _unwrap (p)
 chug_margin_kernel (omega, tau, inert, res, invG, Zhf, wc, K_c, theta_c)
 chug_margin_fast (streams, chamber, *, bool with_regulator=True, float f_lo=2.0, float f_hi=2000.0)

Variables

float _TWO_PI = 2.0 * np.pi

Detailed Description

Numba kernel for the chug gain/phase-margin scan.

This is the dominant per-evaluation stability cost: a 200-point complex frequency
sweep run on every candidate. Vectorising the pure-Python version in numpy took it
from 1537 us to 112 us (and that speed-up stands on its own -- it is what every
pintle and coaxial config runs today, since no accelerated injector path covers
them). But an end-to-end Layer-1 measurement still put the remaining gap at ~8.8%
of wall time versus the C kernel, above the 3% we were willing to absorb, so the
scan itself is compiled here.

Mirrors engine/pipeline/stability/chug.py exactly, including numpy's unwrap
semantics, which numba does not provide.

Function Documentation

◆ _unwrap()

engine.accel.stability._unwrap ( p)
protected
np.unwrap(p) for a 1-D float64 array (numba has no np.unwrap).

Faithful to numpy: correct by the modulo-wrapped difference, zero the
correction where the raw step is below the discontinuity threshold, and
resolve the -pi boundary toward +pi when the raw step is positive.

Definition at line 23 of file stability.py.

Referenced by chug_margin_kernel().

◆ chug_margin_fast()

engine.accel.stability.chug_margin_fast ( streams,
chamber,
* ,
bool with_regulator = True,
float f_lo = 2.0,
float f_hi = 2000.0 )
Drop-in for chug.chug_margin_fast / native_injector.chug_margin_fast.

Resolves the s-independent per-stream primitives once here, in Python, then
hands the kernel nothing but arrays and floats.

Definition at line 139 of file stability.py.

References chug_margin_kernel(), and max.

◆ chug_margin_kernel()

engine.accel.stability.chug_margin_kernel ( omega,
tau,
inert,
res,
invG,
Zhf,
wc,
K_c,
theta_c )
Returns (gain_margin, f_chug_hz, phase_margin_deg, stable, crossings_omega).

Per-stream inputs are the s-independent primitives already resolved by the
Python wrapper: transport lag, feed inertance, linearised resistance, 1/G_inj
(inf when G<=0), and the regulator high-frequency impedance and corner.

Mirrors chug.chug_margin_fast: the gain margin is 1/max|L| over EVERY crossing of
the negative real axis (Im L changes sign with interpolated Re L < 0 -- phases
-pi, -3pi, ...), not only the unwrapped -pi one; the chug frequency is the worst
crossing's; the phase margin is the wrapped distance to the negative axis at the
gain crossover nearest to it.

Definition at line 50 of file stability.py.

References _unwrap(), and max.

Referenced by chug_margin_fast().

Variable Documentation

◆ _TWO_PI

float engine.accel.stability._TWO_PI = 2.0 * np.pi
protected

Definition at line 19 of file stability.py.