s_transforms ¤
Utilities for converting between S-parameters.
Utilities for converting between S-parameter and admittance representations, and for wrapping SAX model functions as circulax components.
Functions:
| Name | Description |
|---|---|
fdomain_component | Decorator for frequency-domain (admittance) circuit components. |
fdomain_model | Adapt a frequency-domain admittance function into a SAX-shaped S-parameter model. |
s_to_y | Convert an S-parameter matrix to an admittance (Y) matrix. |
sax_component | Decorator to convert a SAX model function into a circulax component. |
y_to_s | Convert an admittance (Y) matrix to an S-parameter matrix. |
fdomain_component ¤
Decorator for frequency-domain (admittance) circuit components.
Compiles the decorated admittance function into a :class:~circulax.components.base_component.CircuitComponent subclass that is evaluated in the frequency domain rather than the time domain. The component:
- DC analysis — evaluated at
f = 0Hz (e.g. skin-effect reduces toR₀at DC). - Harmonic Balance — evaluated at each harmonic frequency
k · f₀, contributingY(k · f₀) @ V_kdirectly to the frequency-domain residual. - Transient simulation — raises :exc:
RuntimeErrorat setup time (time-domain convolution not supported).
The decorated function must accept f as its first positional argument (frequency in Hz) followed by any number of keyword parameters with defaults. It must return a square Y-matrix of shape (n_ports, n_ports) with dtype=complex128.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ports | tuple[str, ...] | Ordered tuple of port names matching the netlist connection keys. | required |
Returns:
| Type | Description |
|---|---|
Any | A decorator that accepts an admittance function and returns a |
Any | class: |
Example::
@fdomain_component(ports=("p1", "p2"))
def SkinEffectResistor(f: float, R0: float = 1.0, a: float = 0.1):
"""Z(f) = R0 + a * sqrt(|f|)"""
Z = R0 + a * jnp.sqrt(jnp.abs(f) + 1e-30)
Y = 1.0 / Z
return jnp.array([[Y, -Y], [-Y, Y]], dtype=jnp.complex128)
Source code in circulax/s_transforms.py
fdomain_model ¤
Adapt a frequency-domain admittance function into a SAX-shaped S-parameter model.
Bridges :func:fdomain_component-style physics (fn(f, **params) -> Y-matrix) into an ordinary SAX model function ((**params) -> sax.SDict) via :func:y_to_s. The result is meant to be passed to :func:sax_component, e.g.::
@sax_component
def my_rf_model(f=1e9, R0=50.0): ... # returns a Y-matrix
RfComp = sax_component(fdomain_model(my_rf_model, ports=("p1", "p2")))
Once wrapped this way, the resulting component's frequency argument becomes an ordinary settable parameter (like wl on a photonic SAX model) rather than the circuit-level AC-sweep frequency: it is evaluated once per compile/param-update, not re-evaluated per point in a :meth:~circulax.circuit.Circuit.sp sweep. This makes it usable in the all-SAX, source-free :meth:~circulax.circuit.Circuit.dc S-parameter path (where the frequency becomes a batchable parameter, e.g. circuit.dc(f=jnp.linspace(...))), but it is not a drop-in replacement for @fdomain_component inside a circuit that also has reactive elements (capacitors/inductors) or sources: there, the component's own frequency dependence is frozen at whatever value its parameter was last set to, decoupled from the freqs sweep argument driving the rest of the circuit. To explicitly restore live sweep semantics, wrap it as sax_component(fdomain_model(...), frequency_param="f"); that creates a frequency-domain Circulax component and is consequently no longer eligible for SAX-circuit export.
Note
Compiling the result with is_complex=True may emit a spurious "uses non-holomorphic operations: conj" warning from :func:~circulax.circuit.compile_circuit. This is a known false positive: s_to_y/y_to_s are individually jax.jit-ed, so their default z0 argument is traced as an abstract value inside that nested call, which trips the checker's literal-vs-traced heuristic. It does not indicate an actual bug — fn never receives port signals (only f and parameters), so its contribution is provably linear in the port voltages regardless.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn | callable | Admittance function with signature | required |
ports | tuple[str, ...] | Ordered tuple of port names, matching the shape of | required |
z0 | complex | Reference impedance used for the Y-to-S conversion. Defaults to SAX's own convention so the wrapped model composes correctly with other SAX models under :func: | 1.0 + 1e-12j |
Returns:
| Type | Description |
|---|---|
callable | A callable with the same signature as |
callable |
|
Raises:
| Type | Description |
|---|---|
TypeError | If |
Source code in circulax/s_transforms.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
s_to_y ¤
Convert an S-parameter matrix to an admittance (Y) matrix.
Kurokawa power-wave form: Y = (I - S) (z0 S + z0* I)^-1. Reduces to (1/z0) (I - S) (I + S)^-1 for real z0. A small Im(z0) keeps the inverse well-conditioned when S has eigenvalues at -1 (e.g. an ideal lossless symmetric splitter).
Source code in circulax/s_transforms.py
sax_component ¤
sax_component(
fn: callable, *, name: str | None = None, frequency_param: str | None = None
) -> callable
Decorator to convert a SAX model function into a circulax component.
Inspects fn at decoration time to discover its port interface via a dry run, then wraps its S-matrix output in an admittance-based physics function compatible with the circulax nodal solver.
The conversion proceeds in three stages:
- Discovery —
fnis called once with its default (or dummy) parameter values and :func:sax.get_portsextracts the sorted port names from the resulting S-parameter dict. The same dry-run matrix is checked via :func:_needs_wave_stampto decide, once per wrapped model, which physics stamp this component type gets. - Physics wrapper — a closure is built that calls
fnat runtime and converts the S-dict to a dense matrix via :func:sax.sdense. Components that passed the dry-run conditioning check use :func:s_to_ydirectly and returnI = Y @ V. Components flagged as near-lossless instead get one auxiliary "incident wave" state per port (wave_<port>) and are stamped withb = S @ a,I = a - b,a + b - V = 0— algebraically equivalent to the Y-matrix form (for z0=1, solving the constraint recoversI = (I-S)(I+S)^-1 V) but never invertsSdirectly, so the ill-conditioning is resolved by the global sparse solve instead of a local matrix inverse. - Component registration — the wrapper is passed to :func:
~circulax.components.base_component.componentwith the discovered ports (and, for wave-stamped components, the auxiliary states), producing a :class:~circulax.components.base_component.CircuitComponentsubclass.
fn may be a plain function or a :class:functools.partial wrapping one (SAX PDKs typically use partials to bind fab-specific defaults). Partials are unwrapped to the innermost callable for __name__ / __doc__ recovery; :func:inspect.signature handles the parameter reduction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn | callable | A SAX model function whose keyword arguments are scalar parameters and whose return value is a SAX S-parameter dict. All parameters must have defaults, or will be substituted with | required |
name | str | None | Optional override for the resulting class name. Useful when wrapping :class: | None |
frequency_param | str | None | Optional SAX parameter that is driven by :meth: | None |
Returns:
| Name | Type | Description |
|---|---|---|
A | callable | class: |
callable | subclass named after | |
callable | function. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If the dry run fails for any reason. |
Source code in circulax/s_transforms.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
y_to_s ¤
Convert an admittance (Y) matrix to an S-parameter matrix.
Exact inverse of :func:s_to_y: S = (I - z0 Y) (I + z0* Y)^-1. Reduces to (I - z0 Y) (I + z0 Y)^-1 for real z0. (I + z0* Y) and (I - z0 Y) are both polynomials in Y and so commute, making this well-defined regardless of multiplication order.