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,
)
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 an AC 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: |
transient | Run transient (time-domain) analysis. |
with_groups | Return a new Circuit with replaced component groups. |
Source code in circulax/circuit.py
ac ¤
ac(
*,
ports: str | Sequence[str],
freqs: Array,
z0: float = 50.0,
y_dc: Array | None = None,
params: dict[str, Any] | None = None,
**param_updates: Any
) -> Array
Run an AC 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 | Reference impedance (default 50 Ohm). | 50.0 |
y_dc | Array | None | DC operating point. If | None |
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 |
Raises:
| Type | Description |
|---|---|
ValueError | If the circuit is complex-valued (photonic). Use the low-level |
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 ¤
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
) -> Circuit
Compile a netlist into a callable :class:Circuit.
Accepts either a kfnetlist.Netlist or a SAX-format dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net_dict | dict | Netlist | Netlist (kfnetlist.Netlist or SAX-format dict). | required |
models_map | dict | Mapping from component type name strings to component classes. | 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 |
Returns:
| Name | Type | Description |
|---|---|---|
A | Circuit | class: |