circuit ¤
High-level callable circuit interface.
Classes:
| Name | Description |
|---|---|
Circuit | A compiled, callable circuit with SAX-like parameter API. |
Functions:
| Name | Description |
|---|---|
compile_circuit | Compile a netlist into a callable :class: |
Circuit ¤
Circuit(
solver: CircuitLinearSolver,
groups: dict,
sys_size: int,
port_map: dict[str, int],
rtol: float = 1e-06,
atol: float = 1e-06,
max_steps: int = 100,
_source_netlist: dict | None = None,
_source_models: dict | None = None,
)
A compiled, callable circuit with SAX-like parameter API.
Wraps the output of :func:compile_netlist and :func:analyze_circuit into a single callable. Global parameters (e.g. wavelength_nm) are forwarded to every component group that declares them. When array-valued parameters are passed, :meth:__call__ applies jax.vmap over the batch dimension automatically.
Attributes:
| Name | Type | Description |
|---|---|---|
solver | The configured linear solver strategy. | |
groups | Compiled component groups dict. | |
sys_size | Number of scalar unknowns in the real-valued system. | |
port_map | Maps |
Methods:
| Name | Description |
|---|---|
ac | Run a small-signal S-parameter sweep. |
dc | Solve the DC operating point for the given parameters. |
get_port_field | Extract the (possibly complex) field at a named port. |
hb | Run harmonic balance to find the periodic steady state. |
port | Alias for :meth: |
sp | Run a small-signal S-parameter sweep. |
transient | Run transient (time-domain) analysis. |
with_groups | Return a new Circuit with replaced component groups. |
Source code in circulax/circuit.py
source_models property ¤
source_models: dict | None
The leaf models used to compile this circuit, if available.
source_netlist property ¤
source_netlist: dict | None
The original netlist used to compile this circuit, if available.
ac ¤
ac(
*,
ports: str | Sequence[str],
freqs: Array,
z0: float | Array = 50.0,
y_dc: Array | None = None,
holomorphic: bool | str = "auto",
params: dict[str, Any] | None = None,
**param_updates: Any
) -> Array
Run a small-signal S-parameter sweep.
.. deprecated:: 0.2 Use :meth:sp instead. Will be removed in 0.3.
Source code in circulax/circuit.py
dc ¤
dc(
y_guess: Array | None = None,
*,
params: dict[str, Any] | None = None,
rtol: float | None = None,
atol: float | None = None,
max_steps: int | None = None,
**param_updates: Any
) -> Array
Solve the DC operating point for the given parameters.
Scalar params produce a single solve returning shape (n,). Array params trigger jax.vmap over the leading dimension, returning shape (batch, n). All array params must share the same leading dimension size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_guess | Array | None | Initial guess for the Newton solver. Defaults to zeros. | None |
rtol | float | None | Relative tolerance override. Defaults to value from :func: | None |
atol | float | None | Absolute tolerance override. Defaults to value from :func: | None |
max_steps | int | None | Max Newton iterations override. Defaults to value from :func: | None |
params | dict[str, Any] | None | Optional mapping of parameter updates. Keys without a dot are broadcast to every component group declaring that parameter. Keys like | None |
**param_updates | Any | Convenience form for global parameter values, e.g. | {} |
Returns:
| Type | Description |
|---|---|
Array | Flat solution vector of shape |
Raises:
| Type | Description |
|---|---|
ValueError | If multiple array params have different leading dims. |
Source code in circulax/circuit.py
get_port_field ¤
Extract the (possibly complex) field at a named port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y | Array | Solution array of shape | required |
port | str | Port key as | required |
Returns:
| Type | Description |
|---|---|
Array | Real or complex scalar/array. For complex circuits, reconstructs |
Array | the field from the unrolled block format. |
Source code in circulax/circuit.py
hb ¤
hb(
*,
freq: float,
harmonics: int = 5,
y0: Array | None = None,
params: dict[str, Any] | None = None,
y_flat_init: Array | None = None,
rtol: float | None = None,
atol: float | None = None,
max_steps: int | None = None,
osc_node: int | str | None = None,
amplitude_tries: Array | None = None,
g_leak: float | None = None,
**param_updates: Any
) -> tuple[Array, Array]
Run harmonic balance to find the periodic steady state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq | float | Fundamental frequency in Hz. | required |
harmonics | int | Number of harmonics (K = 2*harmonics + 1 time samples). | 5 |
y0 | Array | None | DC operating point. If | None |
params | dict[str, Any] | None | Parameter updates (same format as :meth: | None |
y_flat_init | Array | None | Flat initial waveform, shape | None |
rtol | float | None | Relative tolerance override. | None |
atol | float | None | Absolute tolerance override. | None |
max_steps | int | None | Max Newton iterations override. | None |
osc_node | int | str | None | Port name or state index for oscillator multi-start. | None |
amplitude_tries | Array | None | Amplitudes to try when | None |
g_leak | float | None | Override the solver's regularisation conductance. | None |
**param_updates | Any | Global parameter overrides. | {} |
Returns:
| Type | Description |
|---|---|
Array |
|
Array | Fourier coefficients |
Source code in circulax/circuit.py
port ¤
sp ¤
sp(
*,
ports: str | Sequence[str],
freqs: Array,
z0: float | Array = 50.0,
y_dc: Array | None = None,
holomorphic: bool | str = "auto",
params: dict[str, Any] | None = None,
**param_updates: Any
) -> Array
Run a small-signal S-parameter sweep.
Linearises at the DC operating point and sweeps over freqs, returning S-parameters for the given ports.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ports | str | Sequence[str] | Port name(s) to probe (e.g. | required |
freqs | Array | Frequency array in Hz. | required |
z0 | float | Array | Reference impedance in ohms. Scalar (uniform) or array of shape | 50.0 |
y_dc | Array | None | DC operating point. If | None |
holomorphic | bool | str | If | 'auto' |
params | dict[str, Any] | None | Parameter updates (same format as :meth: | None |
**param_updates | Any | Global parameter overrides. | {} |
Returns:
| Type | Description |
|---|---|
Array | Complex S-parameter array of shape |
Source code in circulax/circuit.py
transient ¤
transient(
*,
t0: float,
t1: float,
dt0: float,
y0: Array | None = None,
saveat: Any = None,
params: dict[str, Any] | None = None,
transient_solver: Any = None,
**kwargs: Any
) -> Any
Run transient (time-domain) analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t0 | float | Start time. | required |
t1 | float | End time. | required |
dt0 | float | Initial time step. | required |
y0 | Array | None | Initial state vector. If | None |
saveat | Any | Times at which to save the solution. Accepts an array of timestamps or a | None |
params | dict[str, Any] | None | Parameter updates (same format as :meth: | None |
transient_solver | Any | Override the Diffrax solver (default BDF2). | None |
**kwargs | Any | Forwarded to | {} |
Returns:
| Type | Description |
|---|---|
Any | A |
Source code in circulax/circuit.py
with_groups ¤
Return a new Circuit with replaced component groups.
Use together with :func:~circulax.utils.update_params_dict for instance-specific parameter changes before solving.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
groups | dict | New groups dict. | required |
Returns:
| Type | Description |
|---|---|
Circuit | A new :class: |
Source code in circulax/circuit.py
compile_circuit ¤
compile_circuit(
net_dict: dict | Netlist,
models_map: dict,
*,
backend: str = "default",
is_complex: bool | str = "auto",
g_leak: float = 1e-09,
rtol: float = 1e-06,
atol: float = 1e-06,
max_steps: int = 100,
params_map: dict[str, dict[str, str]] | None = None
) -> Circuit
Compile a netlist into a callable :class:Circuit.
Accepts a kfnetlist.Netlist, a SAX-format dict, or a RecursiveNetlist (dict[str, Netlist]). When a recursive netlist is given, subcircuit instances are flattened before compilation.
A compiled :class:Circuit may also appear as a value in models_map; its stored source netlist is inlined as a subcircuit automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net_dict | dict | Netlist | Netlist (kfnetlist.Netlist, SAX-format dict, or RecursiveNetlist). | required |
models_map | dict | Mapping from component type name strings to component classes, SAX model functions, or compiled :class: | required |
backend | str | Linear solver backend ( | 'default' |
is_complex | bool | str | If | 'auto' |
g_leak | float | Leakage conductance for regularisation. | 1e-09 |
rtol | float | Relative tolerance for the Newton solver. | 1e-06 |
atol | float | Absolute tolerance for the Newton solver. | 1e-06 |
max_steps | int | Max Newton iterations. | 100 |
params_map | dict[str, dict[str, str]] | None | Optional mapping from component type names to dicts that rename netlist setting keys to model field names, e.g. | None |
Returns:
| Name | Type | Description |
|---|---|---|
A | Circuit | class: |
Source code in circulax/circuit.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |