Algorithm Search⌘K

Algorithmadvanced

Iterated timing analysis

Also called ITA, SPLICE relaxation.

Saleh, Kleckner and Newton's event-driven Gauss-Seidel-Newton relaxation that solves the backward Euler node equations of a circuit node by node at each time point.

Time
O(s K (N + T)) worstO(s N + T) best
Space
O(N + T) extra
Where
K = the largest number of relaxation sweeps at one time point; N = the number of unknown nodes; T = the number of circuit elements; s = the number of time steps
Properties
deterministicnot exactiterative
Origin
Resve A. Saleh, James E. Kleckner, A. Richard Newton, 1983

Iterated timing analysis (ITA) computes the transient response of a large MOS circuit by solving the backward Euler node equations at each time point with nonlinear Gauss-Seidel relaxation: it updates one node at a time by one Newton step on that node's own equation, and repeats the updates that events trigger until no node moves by more than a tolerance. It belongs to the circuit simulation half of the logic and circuit simulation sub-area. It is timing simulation iterated to convergence: MOTIS makes one sweep per time point, and ITA keeps sweeping, so it gets the backward Euler solution of transient circuit analysis without building or factoring a circuit matrix. Saleh, Kleckner and Newton introduced it in the SPLICE1 simulator in 1983.

In plain words

A circuit simulator moves time forward in small steps. At each step it must find voltages that make the currents at every node add up to zero. The usual way solves for all nodes at once with a large matrix, which costs a lot for a big chip.

Iterated timing analysis takes the nodes one at a time. For one node it holds its neighbours still and moves the node to make its own currents balance, as well as one quick correction allows. Then it goes to the next node. A node that moves wakes up its neighbours, because their currents changed; a node that does not move lets them sleep. When nothing is awake, the time step is done.

In a digital chip most nodes are quiet most of the time. Those nodes cost nothing, and that is where the speed comes from.

The problem

The circuit has nodes, some fixed (ground, supplies and inputs, with given waveforms) and NN unknown. Its elements are capacitors, resistors, voltage-controlled current sources and MOSFETs with the square-law Shichman-Hodges model, whose transconductance kk, threshold VTV_T and channel-length modulation λ\lambda are fitted to measured device curves. With step hh and previous voltages vnv^n, the backward Euler companion model turns each capacitor CC between nodes ii and jj into a current C(Δvi−Δvj)/hC(\Delta v_i - \Delta v_j)/h with Δv=v−vn\Delta v = v - v^n. The node equation of unknown node ii is

Fi(v)=∑capacitors at iCh(Δvi−Δvj)+∑other elements at iIout(v)=0,F_i(v) = \sum_{\text{capacitors at } i} \frac{C}{h} (\Delta v_i - \Delta v_j) + \sum_{\text{other elements at } i} I_{\text{out}}(v) = 0,

the sum of the currents that leave node ii. This is the nodal part of modified nodal analysis, with voltage sources only at fixed nodes, so no branch currents appear. The fanout of node ii is the set of unknown nodes jj whose FjF_j depends on viv_i: the nodes that share an element with ii through which current flows at jj. It includes ii and, for a transistor, the drain and source nodes of every transistor whose gate is ii.

Input: the circuit, the initial voltages v0v^0 (consistent, for example a DC operating point), the step hh, the number of steps ss and the tolerance τ\tau. Output: the voltages at the times h,2h,…,shh, 2h, \ldots, sh.

The algorithm

  1. ITA(circuit, v0, h, s, τ)
  2. 1v ← v0 with the fixed nodes at time 0; A ← all unknown nodes
  3. 2for k = 1, 2, ..., s
  4. 3vⁿ ← v; set the fixed nodes to their values at t = kh; add to A the fanout of each fixed node that changed
  5. 4Q ← a first-in first-out queue holding the nodes of A
  6. 5while Q is not empty
  7. 6i ← remove the first node of Q
  8. 7(F, D) ← F_i(v) and ∂F_i/∂v_i, at the newest voltages
  9. 8δ ← −F / D; v_i ← v_i + δ
  10. 9if |δ| > τ: append to Q each node of fanout(i) that is not in Q
  11. 10A ← the fanout of each node with |v_i − vⁿ_i| > τ; record v at t = kh
  12. 11return the recorded waveforms

Line L8 is one Newton step on the equation of node ii alone, with every other voltage at its newest value: a Gauss-Seidel-Newton update. Line L9 is the selective trace of event-driven logic simulation moved to the analog level: a node that changed by more than τ\tau schedules the nodes whose equations read it, itself included, since one Newton step does not solve a nonlinear equation. A node is evaluated again only when something it reads has moved. Lines L5 to L9 end when every node has settled.

Line L10 exploits latency. A node that did not move by more than τ\tau in this step, and whose neighbours did not either, is not evaluated in the next step; it keeps its voltage. A guard on the number of evaluations at one time point (here 200N200N) stops the loop if the relaxation does not converge.

Example

One time point by hand. Two nodes, each with a capacitor of 1 F and a conductance of 1 S to ground, joined by a conductance of 1 S; h=1h = 1 s, vn=(1,0)v^n = (1, 0) V and τ=0.01\tau = 0.01 V. The node equations are F1=3v1−v2−1F_1 = 3v_1 - v_2 - 1 and F2=3v2−v1F_2 = 3v_2 - v_1, linear, so each update solves its node exactly. The backward Euler solution is (3/8,1/8)(3/8, 1/8).

update node new value δ\delta queue after
1 1 1/31/3 −2/3-2/3 2, 1
2 2 1/91/9 1/91/9 1, 2
3 1 10/2710/27 1/271/27 2, 1
4 2 10/8110/81 1/811/81 1, 2
5 1 91/24391/243 1/2431/243 2
6 2 91/72991/729 1/7291/729 empty

After update 2 the errors are 1/241/24 and 1/721/72; after update 4 they are 1/2161/216 and 1/6481/648, nine times smaller. This is Gauss-Seidel on (3−1−13)\begin{pmatrix} 3 & -1 \\ -1 & 3 \end{pmatrix}, whose rate is (1/3)2(1/3)^2. The loop stops after six evaluations, when both moves are below τ\tau, with errors 5.1×10−45.1 \times 10^{-4} and 1.7×10−41.7 \times 10^{-4} V.

An inverter chain. Four CMOS inverters with VDD=1.8V_{DD} = 1.8 V, k=200 μA/V2k = 200\ \mu\mathrm{A/V^2}, VT=0.5V_T = 0.5 V and λ=0.05 V−1\lambda = 0.05\ \mathrm{V^{-1}} for both device types (typical fitted values), a load of 10 fF on each output and a gate-drain capacitance of 2 fF from each output to its input, which couples neighbouring nodes in both directions. The input rises from 0 to 1.8 V between 100 and 150 ps, and h=1h = 1 ps for 600 steps. The 0.9 V crossings of the first three outputs, measured by linear interpolation of the waveforms:

method output 1 (ps) output 2 (ps) output 3 (ps) largest difference from full Newton (V) work
backward Euler, full Newton 225.45 381.95 544.15 0 1600 Newton iterations, each with a 4 by 4 LU
ITA, τ=10−4\tau = 10^{-4} 225.45 381.95 544.13 3.9×10−43.9 \times 10^{-4} 4588 node evaluations
ITA, τ=10−6\tau = 10^{-6} 225.45 381.95 544.15 2.9×10−62.9 \times 10^{-6} 7712 node evaluations
ITA, τ=10−8\tau = 10^{-8} 225.45 381.95 544.15 2.7×10−82.7 \times 10^{-8} 10797 node evaluations
one sweep per step (MOTIS) 226.37 377.78 531.32 0.129 2400 node evaluations

ITA reproduces the backward Euler waveforms to within about 3τ3\tau. The single sweep does not: the gate-drain capacitances couple each output back to its input, and one sweep takes that coupling one step late, which moves the third crossing by 12.8 ps.

Correctness

The proof in proofs/correctness.md shows the following.

  1. On a linear node equation, one Newton node update solves it exactly, so on a linear circuit ITA is linear Gauss-Seidel.
  2. If the node Jacobian C/h+G(v)C/h + G(v) is strictly diagonally dominant by rows with ratio ρ<1\rho < 1, a sweep of exact node solves reduces the maximum-norm error by the factor ρ\rho, and a sweep that moves no node by more than τ\tau is within ρτ/(1−ρ)\rho\tau/(1 - \rho) of the backward Euler solution.
  3. With one Newton step per node, the sweeps converge locally at an asymptotic rate of at most ρ\rho (by Ostrowski's theorem, cited).
  4. If every node has a capacitance to ground, small enough steps make the Jacobian dominant: ρ→max⁡iκi/Cii\rho \to \max_i \kappa_i / C_{ii} as h→0h \to 0, where κi\kappa_i is the capacitance from node ii to other unknown nodes.
  5. The event-driven loop performs only Newton node updates and stops only when every node's last update, and every later update of a node it reads, is at most τ\tau.

The distance between the event-driven result and the backward Euler solution is not bounded by the proof. The tests measure it. They compare with backward Euler solved by full Newton on all nodes (∥Δx∥∞≤10−12\|\Delta x\|_\infty \le 10^{-12} V), on the chain above, on a victim node coupled by 20 fF to an aggressor, and on random linear RC networks (seed 63), where each measured sweep ratio stays below the computed ρ\rho.

Proof: Iterated timing analysis converges to the backward Euler solution when the node Jacobian is diagonally dominantfull

We use the notation of the page. Fix one time point tt with step hh and previous voltages vnv^n. The unknown node voltages v∈RNv \in \mathbb{R}^N must satisfy the backward Euler node equations F(v)=0F(v) = 0, where Fi(v)F_i(v) is the sum of the currents that leave node ii: the capacitor currents C(Δvi−Δvj)/hC(\Delta v_i - \Delta v_j)/h with Δv=v−vn\Delta v = v - v^n, and the resistive currents of resistors, controlled sources and transistor channels. The fixed nodes (ground, supplies, inputs) have known values at tt. The Jacobian is

J(v)=1hC+G(v),J(v) = \frac{1}{h} C + G(v),

where CC is the nodal capacitance matrix and G(v)G(v) the Jacobian of the resistive currents. We assume FF is continuously differentiable; the level-1 MOSFET model is, since its current and first derivatives agree at the boundaries of its three regions. Let v∗v^\ast be a solution of F(v)=0F(v) = 0.

A node update of node ii changes only viv_i. An exact node update sets viv_i to a root of FiF_i with the other voltages fixed. A Newton node update, line L8 of the page, sets vi←vi−Fi(v)/Jii(v)v_i \leftarrow v_i - F_i(v)/J_{ii}(v). A sweep updates every unknown node once, in a fixed order, each with the newest values of the others: this is nonlinear Gauss-Seidel iteration. We use the maximum norm ∥e∥=max⁡i∣ei∣\|e\| = \max_i |e_i|.

Dominance assumption. On a convex set Ω\Omega that contains v∗v^\ast and the iterates, Jii(v)>0J_{ii}(v) > 0 and

∑j≠i∣Jij(v)∣≤ρ Jii(v)for all i and all v∈Ω,\sum_{j \ne i} |J_{ij}(v)| \le \rho\, J_{ii}(v) \quad \text{for all } i \text{ and all } v \in \Omega,

for a constant ρ<1\rho < 1, the sum taken over unknown nodes jj. That is, JJ is strictly diagonally dominant by rows, uniformly on Ω\Omega.

Lemma 1 (a Newton node update is exact on a linear node equation). If FiF_i is affine in viv_i, one Newton node update sets Fi=0F_i = 0.

Proof. If Fi(v)=a+JiiviF_i(v) = a + J_{ii} v_i with aa and JiiJ_{ii} independent of viv_i, then vi−Fi(v)/Jii=−a/Jiiv_i - F_i(v)/J_{ii} = -a/J_{ii}, the root. □\square

So on a linear circuit (resistors, capacitors, linear controlled sources), the iteration of the page is exactly linear Gauss-Seidel on Jv=bJ v = b.

Theorem 1 (contraction of a sweep). Under the dominance assumption, a sweep of exact node updates maps vv to v′v' with

∥v′−v∗∥≤ρ ∥v−v∗∥.\|v' - v^\ast\| \le \rho\, \|v - v^\ast\|.

Proof. Let node ii be updated when the current vector is ww, which has the new values vj′v'_j for nodes earlier in the order and the old values vjv_j for the others, and let w′w' be ww with wiw_i replaced by vi′v'_i. Then Fi(w′)=0=Fi(v∗)F_i(w') = 0 = F_i(v^\ast). Along the segment from v∗v^\ast to w′w', which lies in Ω\Omega,

0=Fi(w′)−Fi(v∗)=∑jJˉij(wj′−vj∗),Jˉij=∫01Jij(v∗+s(w′−v∗)) ds.0 = F_i(w') - F_i(v^\ast) = \sum_j \bar J_{ij} (w'_j - v^\ast_j), \qquad \bar J_{ij} = \int_0^1 J_{ij}\big(v^\ast + s(w' - v^\ast)\big)\, ds.

Integration keeps the dominance: ∑j≠i∣Jˉij∣≤∫01∑j≠i∣Jij∣ ds≤ρ∫01Jii ds=ρ Jˉii\sum_{j \ne i} |\bar J_{ij}| \le \int_0^1 \sum_{j \ne i} |J_{ij}|\, ds \le \rho \int_0^1 J_{ii}\, ds = \rho\, \bar J_{ii}, and Jˉii>0\bar J_{ii} > 0. So

∣vi′−vi∗∣≤1Jˉii∑j≠i∣Jˉij∣ ∣wj−vj∗∣≤ρmax⁡j≠i∣wj−vj∗∣.|v'_i - v^\ast_i| \le \frac{1}{\bar J_{ii}} \sum_{j \ne i} |\bar J_{ij}|\, |w_j - v^\ast_j| \le \rho \max_{j \ne i} |w_j - v^\ast_j|.

By induction on the order, every new value satisfies ∣vj′−vj∗∣≤ρ∥v−v∗∥≤∥v−v∗∥|v'_j - v^\ast_j| \le \rho \|v - v^\ast\| \le \|v - v^\ast\|, so every entry of ww is within ∥v−v∗∥\|v - v^\ast\| of v∗v^\ast, and the bound for node ii is ρ∥v−v∗∥\rho \|v - v^\ast\|. □\square

With ρ<1\rho < 1 the sweeps converge to v∗v^\ast, and v∗v^\ast is the only solution in Ω\Omega: a second solution would be a fixed point of the sweep, and the contraction gives distance 0. For a linear circuit Theorem 1 is the classical convergence of Gauss-Seidel for a strictly diagonally dominant matrix.

Corollary 1 (stopping test). If a sweep moves no node by more than τ\tau, that is ∥v′−v∥≤τ\|v' - v\| \le \tau, then ∥v′−v∗∥≤ρ1−ρτ\|v' - v^\ast\| \le \frac{\rho}{1 - \rho} \tau.

Proof. ∥v−v∗∥≤∥v−v′∥+∥v′−v∗∥≤τ+ρ∥v−v∗∥\|v - v^\ast\| \le \|v - v'\| + \|v' - v^\ast\| \le \tau + \rho \|v - v^\ast\|, so ∥v−v∗∥≤τ/(1−ρ)\|v - v^\ast\| \le \tau/(1 - \rho) and ∥v′−v∗∥≤ρτ/(1−ρ)\|v' - v^\ast\| \le \rho \tau/(1 - \rho). □\square

Theorem 2 (one Newton step per node converges locally). Under the dominance assumption at v∗v^\ast (that is, for J(v∗)J(v^\ast)), sweeps of Newton node updates converge to v∗v^\ast from every start close enough to v∗v^\ast, at a rate of at most ρ\rho per sweep in the limit.

Proof. Let Φ\Phi be the sweep map. Update ii computes ϕi(w)=wi−Fi(w)/Jii(w)\phi_i(w) = w_i - F_i(w)/J_{ii}(w). Since Fi(v∗)=0F_i(v^\ast) = 0 and 1/Jii1/J_{ii} is continuous with Jii(v∗)>0J_{ii}(v^\ast) > 0,

ϕi(w)−vi∗=(wi−vi∗)−1Jii(w)(Fi(w)−Fi(v∗))=−1Jii(v∗)∑j≠iJij(v∗)(wj−vj∗)+o(∥w−v∗∥).\phi_i(w) - v^\ast_i = (w_i - v^\ast_i) - \frac{1}{J_{ii}(w)}\big(F_i(w) - F_i(v^\ast)\big) = -\frac{1}{J_{ii}(v^\ast)} \sum_{j \ne i} J_{ij}(v^\ast) (w_j - v^\ast_j) + o(\|w - v^\ast\|).

So Φ\Phi is differentiable at its fixed point v∗v^\ast, and Φ′(v∗)\Phi'(v^\ast) is the sweep map of linear Gauss-Seidel on J(v∗)J(v^\ast), the matrix −(D+L)−1U-(D + L)^{-1} U for the splitting J(v∗)=D+L+UJ(v^\ast) = D + L + U. Theorem 1, applied to the linear map v↦J(v∗)vv \mapsto J(v^\ast) v (dominance holds everywhere for a constant matrix), gives ∥Φ′(v∗)e∥≤ρ∥e∥\|\Phi'(v^\ast) e\| \le \rho \|e\| for every ee, so the spectral radius of Φ′(v∗)\Phi'(v^\ast) is at most ρ<1\rho < 1. By Ostrowski's theorem on points of attraction (Ortega and Rheinboldt, Chapter 10), v∗v^\ast attracts all starts in a neighbourhood, with asymptotic rate at most ρ\rho. □\square

Theorem 3 (small steps give dominance). Suppose every unknown node ii has a capacitance ci>0c_i > 0 to ground or to a fixed node, let κi≥0\kappa_i \ge 0 be the total capacitance from ii to other unknown nodes, so that Cii≥ci+κiC_{ii} \ge c_i + \kappa_i and ∑j≠i∣Cij∣=κi\sum_{j \ne i} |C_{ij}| = \kappa_i, and suppose that on Ω\Omega, ∑j≠i∣Gij(v)∣≤ai\sum_{j \ne i} |G_{ij}(v)| \le a_i and Gii(v)≥−biG_{ii}(v) \ge -b_i with ai,bi≥0a_i, b_i \ge 0. Then for h>0h > 0 with h(ai+bi)<cih(a_i + b_i) < c_i for all ii, the dominance assumption holds with

ρ=max⁡iκi+haiCii−hbi<1,\rho = \max_i \frac{\kappa_i + h a_i}{C_{ii} - h b_i} < 1,

and ρ→max⁡iκi/Cii\rho \to \max_i \kappa_i / C_{ii} as h→0h \to 0.

Proof. In row ii of hJhJ, the diagonal is Cii+hGii≥Cii−hbi>0C_{ii} + h G_{ii} \ge C_{ii} - h b_i > 0 and the off-diagonal sum is at most κi+hai\kappa_i + h a_i. The ratio is below 1 exactly when κi+hai<Cii−hbi\kappa_i + h a_i < C_{ii} - h b_i, which follows from Cii≥ci+κiC_{ii} \ge c_i + \kappa_i and h(ai+bi)<cih(a_i + b_i) < c_i. □\square

For a node at the drain or source of a MOSFET, the channel current contributes ∂I/∂vi≥0\partial I/\partial v_i \ge 0 to GiiG_{ii} (the output conductance, plus the transconductance at the source), so bi=0b_i = 0 unless a controlled source or a transistor gate on the node itself makes GiiG_{ii} negative. The off-diagonal terms aia_i include the transconductances of the transistors whose gates are driven by other nodes. So the bound says: ITA converges when the time step is small against ci/aic_i / a_i, the time constant of the grounded capacitance with the transconductances that couple the node to its neighbours. This is why relaxation-based simulators couple the time step and the relaxation.

Theorem 4 (the event-driven loop is Gauss-Seidel in a data-driven order). Every node update in lines L5 to L9 is a Newton node update with the newest voltages. When the queue becomes empty, the last update of every node moved it by at most τ\tau, and every later update of a node it reads also moved that node by at most τ\tau.

Proof. Line L7 evaluates FiF_i and JiiJ_{ii} at the current vector, which holds the newest value of every node, and line L8 is the Newton node update. A node jj that reads viv_i, which means that FjF_j depends on viv_i, is in the fanout of ii, so any update of ii by more than τ\tau puts jj back in the queue (line L9), and ii is in its own fanout. If the queue is empty, no update after the last update of jj was larger than τ\tau on any node that jj reads, and the last update of jj was not larger than τ\tau either, otherwise jj would be in the queue. □\square

Theorem 4 is weaker than Corollary 1: many small updates of a neighbour, each below τ\tau, can add up, and nodes that did not move by more than τ\tau in the previous step are not evaluated at all (latency). The distance between the result and the backward Euler solution is not bounded here; the tests measure it against a full Newton solve, and it grows linearly with τ\tau (about 3τ3 \tau on the four-stage inverter chain).

Together, Lemma 1 and Theorems 1 to 3 show that, for steps small enough to make the node Jacobian dominant, iterating the node updates to convergence computes the backward Euler solution of transient circuit analysis at each time point; Theorem 4 shows that the event-driven loop performs only such updates and stops only when all of them are below τ\tau.

Complexity

One node evaluation reads the elements at the node. A sweep costs O(N+T)O(N + T), and with at most KK sweeps' worth of evaluations per time point, ss steps cost O(sK(N+T))O(s K (N + T)). No matrix is formed or factored, and the memory is O(N+T)O(N + T) beyond the waveforms. When all nodes are latent, a step costs only the copy of the voltages, O(N)O(N).

On a chain of eight inverters, the node evaluations with τ=10−6\tau = 10^{-6} V were 23394 in the first 1000 steps, 25157 in the next 1000 and 0 in the 1000 after that, once the edge had passed the last stage (measured). A method without latency spends at least NN evaluations in every step.

Properties

  • Matrix-free. Only diagonal derivatives ∂Fi/∂vi\partial F_i/\partial v_i are needed; the off-diagonal derivatives never appear.
  • Converges to backward Euler. Unlike one-sweep timing simulation, the result does not depend on the node order once the relaxation has converged.
  • Conditional convergence. It needs a diagonally dominant node Jacobian, which small steps and grounded capacitances give. Full Newton does not need it.
  • Event-driven. Work follows activity, both within a time point (selective trace) and across time points (latency).
  • First order in time. The accuracy in time is that of backward Euler. The relaxation tolerance τ\tau adds an error of about the same order as τ\tau.

Variants and improvements

  • Subcircuits instead of nodes. Group tightly coupled nodes, for example the channel-connected components of the transistor network, and solve each group by Newton's method with a small matrix, then relax between groups. This keeps strong two-way coupling inside a group.
  • Gauss-Jacobi and SOR. Updating all nodes from the old values allows parallel evaluation at a slower rate; over-relaxation can speed up the convergence of linear parts.
  • Variable and per-node time steps. SPLICE-style simulators choose the step from the activity of the nodes and schedule node evaluations as timed events.
  • Higher-order formulas. The trapezoidal rule or TR-BDF2 can replace backward Euler in the node equations; the relaxation is the same.
  • Waveform relaxation. Relax whole waveforms of subcircuits over a time window instead of values at one time point. It is the Picard iteration on subcircuits and lets each subcircuit take its own steps.
  • Mixed mode. ITA fits an event-driven mixed-mode simulator, since an analog node that is not active is not evaluated.

When to use it

Use ITA for large digital or mostly digital MOS circuits, where most nodes are idle at any time, couplings are mostly one-way through transistor gates, every node has a capacitance to ground, and a full sparse factorization at each Newton iteration is too costly. Use full Newton with a sparse solver, such as KLU, for analog blocks with strong feedback, for circuits with floating nodes or large coupling capacitances, and whenever the relaxation stops converging at the step size that accuracy needs.

Pitfalls

  • Strong two-way coupling. If off-diagonal terms outweigh the diagonal, the relaxation diverges where full Newton does not. Two nodes with 1 F and 1 S to ground, coupled by controlled sources of +2+2 and −2-2 S (a stable circuit), have a Gauss-Seidel rate of 4/(1/h+1)24/(1/h + 1)^2. ITA converged at h=0.25h = 0.25 and 0.50.5 s and exceeded the evaluation limit at h=1h = 1 and 22 s, while full Newton solved every step.
  • Steps too large for dominance. On the inverter chain the measured ρ\rho along the trajectory was 0.283 at h=1h = 1 ps, close to the limit 4/144/14 of the coupling capacitances, but above 1 at h=100h = 100 ps.
  • A loose tolerance freezes nodes. With τ=10−4\tau = 10^{-4} V on the eight-stage chain over 4 ns, nodes went latent while still settling, and the largest difference from full Newton was 5.6 mV.
  • Floating nodes. A node with no capacitance to ground has ci=0c_i = 0, so κi/Cii=1\kappa_i/C_{ii} = 1 and small steps do not help.
  • No error bound from the tolerance alone. The stop of the event-driven loop is local; many small moves of a neighbour can add up. Keep τ\tau well below the accuracy that is needed.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

iterated_timing_analysis.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iterated-timing-analysis/. The authors are listed in prov/8PGXDW.jsonl.
"""Iterated timing analysis: event-driven Gauss-Seidel-Newton relaxation of the
backward Euler node equations at each time point.

A circuit has nodes 0 .. n-1. Some nodes are fixed (ground, supplies, inputs)
and carry a waveform; the others are unknown. Elements are capacitors,
resistors, voltage-controlled current sources and level-1 MOSFETs. The node
equation of an unknown node i at time t, with step h and previous voltages vn,
is the sum of the currents leaving i:

    F_i(v) = sum_C C ((v_i - vn_i) - (v_j - vn_j)) / h + sum of resistive currents = 0.
"""

from collections import deque

import sim3dense


class NonConvergence(RuntimeError):
    """The relaxation did not settle at a time point within the work limit."""


def _mos_core(k, vt, lam, vgs, vds):
    """Square-law current from drain to source for vds >= 0, with gm and gds."""
    vov = vgs - vt
    if vov <= 0:
        return 0.0, 0.0, 0.0
    if vds < vov:
        a = vov * vds - vds * vds / 2
        return k * a * (1 + lam * vds), k * vds * (1 + lam * vds), k * (vov - vds) * (1 + lam * vds) + k * a * lam
    return k / 2 * vov * vov * (1 + lam * vds), k * vov * (1 + lam * vds), k / 2 * vov * vov * lam


def mos_current(kind, k, vt, lam, vd, vg, vs):
    """Channel current from terminal d to terminal s and its partials (in vd, vg, vs).

    Level-1 (Shichman-Hodges) model. k, vt and lam are fitted model
    parameters. The device is symmetric: if the voltages reverse, d and s
    swap roles. A p device is the n device on negated voltages, with vt the
    magnitude of its threshold.
    """
    if kind == "p":
        i, gd, gg, gs = mos_current("n", k, vt, lam, -vd, -vg, -vs)
        return -i, gd, gg, gs
    if vd >= vs:
        i, gm, gds = _mos_core(k, vt, lam, vg - vs, vd - vs)
        return i, gds, gm, -gds - gm
    i, gm, gds = _mos_core(k, vt, lam, vg - vd, vs - vd)
    return -i, gds + gm, -gm, -gds


class Circuit:
    def __init__(self, n, fixed):
        """n nodes; fixed maps each fixed node to a function of time."""
        self.n, self.fixed = n, dict(fixed)
        self.elements = []

    def cap(self, a, b, c):
        self.elements.append(("C", (a, b), (a, b), c))

    def res(self, a, b, g):
        """A conductance g between a and b."""
        self.elements.append(("G", (a, b), (a, b), g))

    def vccs(self, p, q, c, d, g):
        """A current g (v_c - v_d) that leaves p and enters q."""
        self.elements.append(("V", (p, q), (c, d), g))

    def mos(self, kind, d, g, s, k, vt, lam):
        self.elements.append(("M", (d, s), (d, g, s), (kind, k, vt, lam)))

    def build(self):
        """Index the elements by node and compute the fanout of every node."""
        self.unknown = [i for i in range(self.n) if i not in self.fixed]
        self.at = [[] for _ in range(self.n)]
        self.fanout = [set() for _ in range(self.n)]
        for e in self.elements:
            carry, ctrl = e[1], e[2]
            for i in set(carry):
                self.at[i].append(e)
            for i in set(carry) | set(ctrl):
                for j in carry:
                    if j not in self.fixed:
                        self.fanout[i].add(j)
        return self

    def apply_fixed(self, v, t):
        for i, w in self.fixed.items():
            v[i] = w(t)


def node_row(ckt, i, v, vn, h):
    """Residual F_i of the backward Euler equation of node i and its partials."""
    f, dv = 0.0, {}

    def add(j, x):
        dv[j] = dv.get(j, 0.0) + x

    for kind, carry, ctrl, p in ckt.at[i]:
        if kind in "CGV":
            a, b = carry
            sign = 1 if a == i else -1
            if kind == "C":
                f += sign * p * ((v[a] - vn[a]) - (v[b] - vn[b])) / h
                add(a, sign * p / h)
                add(b, -sign * p / h)
            elif kind == "G":
                f += sign * p * (v[a] - v[b])
                add(a, sign * p)
                add(b, -sign * p)
            else:
                c, d = ctrl
                f += sign * p * (v[c] - v[d])
                add(c, sign * p)
                add(d, -sign * p)
        else:
            d, g, s = ctrl
            ids, gd, gg, gs = mos_current(p[0], p[1], p[2], p[3], v[d], v[g], v[s])
            sign = (d == i) - (s == i)
            f += sign * ids
            add(d, sign * gd)
            add(g, sign * gg)
            add(s, sign * gs)
    return f, dv


def relax_time_point(ckt, v, vn, h, active, tau, max_evals):
    """Event-driven Gauss-Seidel-Newton at one time point. Changes v in place."""
    queue = deque(i for i in ckt.unknown if i in active)  # @line L4
    inq = set(queue)
    evals = 0
    while queue:  # @line L5
        i = queue.popleft()  # @line L6
        inq.discard(i)
        f, dv = node_row(ckt, i, v, vn, h)  # @line L7
        delta = -f / dv[i]  # @line L8
        v[i] += delta
        evals += 1
        if evals > max_evals:
            raise NonConvergence(f"more than {max_evals} node evaluations")
        if abs(delta) > tau:  # @line L9
            for j in ckt.fanout[i]:
                if j not in inq:
                    queue.append(j)
                    inq.add(j)
    return evals


def ita(ckt, v0, h, steps, tau, max_evals=None):
    """Iterated timing analysis with a fixed step h.

    Returns the list of (t, v) and the total number of node evaluations.
    """
    ckt.build()
    if max_evals is None:
        max_evals = 200 * max(1, len(ckt.unknown))
    v = list(v0)  # @line L1
    ckt.apply_fixed(v, 0.0)
    active = set(ckt.unknown)
    out, total = [(0.0, list(v))], 0
    for k in range(1, steps + 1):  # @line L2
        t = k * h
        vn = list(v)
        ckt.apply_fixed(v, t)  # @line L3
        for i in ckt.fixed:
            if v[i] != vn[i]:
                active |= ckt.fanout[i]
        total += relax_time_point(ckt, v, vn, h, active, tau, max_evals)
        moved = [i for i in ckt.unknown if abs(v[i] - vn[i]) > tau]  # @line L10
        active = set().union(*(ckt.fanout[i] for i in moved)) if moved else set()
        out.append((t, list(v)))
    return out, total  # @line L11


def sweep(ckt, v, vn, h, order=None):
    """One Gauss-Seidel-Newton sweep over all unknown nodes; returns the largest step."""
    big = 0.0
    for i in order or ckt.unknown:
        f, dv = node_row(ckt, i, v, vn, h)
        delta = -f / dv[i]
        v[i] += delta
        big = max(big, abs(delta))
    return big


def one_sweep_simulation(ckt, v0, h, steps):
    """The MOTIS scheme: one sweep per time point, with no iteration."""
    ckt.build()
    v = list(v0)
    ckt.apply_fixed(v, 0.0)
    out, evals = [(0.0, list(v))], 0
    for k in range(1, steps + 1):
        vn = list(v)
        ckt.apply_fixed(v, k * h)
        sweep(ckt, v, vn, h)
        evals += len(ckt.unknown)
        out.append((k * h, list(v)))
    return out, evals


def backward_euler_newton(ckt, v0, h, steps, tol=1e-12, max_iter=50):
    """Reference: backward Euler with full Newton on all unknown nodes at once."""
    ckt.build()
    idx = {i: r for r, i in enumerate(ckt.unknown)}
    v = list(v0)
    ckt.apply_fixed(v, 0.0)
    out = [(0.0, list(v))]
    for k in range(1, steps + 1):
        vn = list(v)
        ckt.apply_fixed(v, k * h)
        for _ in range(max_iter):
            m = len(idx)
            jac = [[0.0] * m for _ in range(m)]
            res = [0.0] * m
            for i, r in idx.items():
                f, dv = node_row(ckt, i, v, vn, h)
                res[r] = -f
                for j, x in dv.items():
                    if j in idx:
                        jac[r][idx[j]] += x
            dx = sim3dense.solve(jac, res)
            for i, r in idx.items():
                v[i] += dx[r]
            if max(abs(x) for x in dx) <= tol:
                break
        else:
            raise NonConvergence("full Newton did not converge")
        out.append((k * h, list(v)))
    return out


def jacobian_rho(ckt, v, vn, h):
    """max_i sum_{j != i} |J_ij| / J_ii over unknown nodes: the bound of the proof."""
    ckt.build()
    rho = 0.0
    for i in ckt.unknown:
        _, dv = node_row(ckt, i, v, vn, h)
        off = sum(abs(x) for j, x in dv.items() if j != i and j not in ckt.fixed)
        rho = max(rho, off / dv[i] if dv[i] > 0 else float("inf"))
    return rho
sim3dense.py 70 lines
# SPDX-License-Identifier: MIT
# Shared helper of the sim3 eda pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Small dense linear algebra for Fraction, float or complex entries.

The circuit pages of group sim3 use this module as a reference solver and for
the small dense systems inside their tests. It holds no sparse method and no
circuit method. Matrices are lists of rows.
"""

from fractions import Fraction


class SingularMatrixError(ValueError):
    """The matrix has no inverse (a zero pivot in exact arithmetic)."""


def _exact(x):
    return Fraction(x) if isinstance(x, int) else x


def solve(a, b, tol=0.0):
    """Solve a x = b by Gaussian elimination with partial pivoting.

    With Fraction entries the result is exact. b is a vector or a matrix
    (a list of rows); the result has the same shape.
    """
    n = len(a)
    m = [[_exact(x) for x in row] for row in a]
    vec = not (b and isinstance(b[0], list))
    rhs = [[_exact(x)] for x in b] if vec else [[_exact(x) for x in row] for row in b]
    for k in range(n):
        p = max(range(k, n), key=lambda i: abs(m[i][k]))
        if abs(m[p][k]) <= tol:
            raise SingularMatrixError(f"zero pivot in column {k}")
        m[k], m[p] = m[p], m[k]
        rhs[k], rhs[p] = rhs[p], rhs[k]
        for i in range(k + 1, n):
            if m[i][k] != 0:
                f = m[i][k] / m[k][k]
                for j in range(k, n):
                    m[i][j] -= f * m[k][j]
                for j in range(len(rhs[i])):
                    rhs[i][j] -= f * rhs[k][j]
    x = [[0] * len(rhs[0]) for _ in range(n)]
    for i in range(n - 1, -1, -1):
        for j in range(len(rhs[0])):
            s = rhs[i][j] - sum(m[i][k] * x[k][j] for k in range(i + 1, n))
            x[i][j] = s / m[i][i]
    return [r[0] for r in x] if vec else x


def transpose(a):
    return [list(r) for r in zip(*a)]


def matvec(a, x):
    return [sum(aij * xj for aij, xj in zip(row, x)) for row in a]


def matmul(a, b):
    bt = transpose(b)
    return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a]


def identity(n, one=1):
    return [[one if i == j else 0 * one for j in range(n)] for i in range(n)]


def inverse(a):
    return solve(a, identity(len(a)))
test_iterated_timing_analysis.py 221 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iterated-timing-analysis/. The authors are listed in prov/8PGXDW.jsonl.

import random

import pytest

from iterated_timing_analysis import (
    Circuit,
    NonConvergence,
    backward_euler_newton,
    ita,
    jacobian_rho,
    mos_current,
    node_row,
    one_sweep_simulation,
    relax_time_point,
    sweep,
)

# Level-1 parameters. K (transconductance), VT (threshold) and LAM (channel-length
# modulation) are fitted model parameters; these are typical teaching values.
VDD, K, VT, LAM = 1.8, 200e-6, 0.5, 0.05


def ramp(t0, t1):
    return lambda t: 0.0 if t <= t0 else (VDD if t >= t1 else VDD * (t - t0) / (t1 - t0))


def chain(stages, cl=10e-15, cm=2e-15):
    """Inverter chain: node 0 ground, 1 supply, 2 input ramp, 3.. outputs.

    Each output has a load cl to ground and a gate-drain (Miller) capacitance cm
    to its input, which couples neighbouring nodes in both directions.
    """
    n = 3 + stages
    ckt = Circuit(n, {0: lambda t: 0.0, 1: lambda t: VDD, 2: ramp(0.1e-9, 0.15e-9)})
    prev = 2
    for s in range(stages):
        out = 3 + s
        ckt.mos("n", out, prev, 0, K, VT, LAM)
        ckt.mos("p", out, prev, 1, K, VT, LAM)
        ckt.cap(out, 0, cl)
        ckt.cap(out, prev, cm)
        prev = out
    v0 = [0.0] * n
    for s in range(stages):
        v0[3 + s] = VDD if s % 2 == 0 else 0.0
    return ckt, v0


def maxdiff(a, b, nodes):
    return max(abs(x[i] - y[i]) for (_, x), (_, y) in zip(a, b) for i in nodes)


def crossing(w, i, level=0.9):
    for (ta, xa), (tb, xb) in zip(w, w[1:]):
        if (xa[i] - level) * (xb[i] - level) <= 0 and xa[i] != xb[i]:
            return ta + (level - xa[i]) / (xb[i] - xa[i]) * (tb - ta)
    return None


def test_mos_model_values_and_partials():
    # saturation by hand: vgs = 1.8, vds = 1.8
    i, gd, gg, gs = mos_current("n", K, VT, LAM, 1.8, 1.8, 0.0)
    assert abs(i - K / 2 * 1.3**2 * (1 + LAM * 1.8)) < 1e-18
    # linear region by hand: vgs = 1.8, vds = 0.3
    i, _, _, _ = mos_current("n", K, VT, LAM, 0.3, 1.8, 0.0)
    assert abs(i - K * (1.3 * 0.3 - 0.045) * (1 + LAM * 0.3)) < 1e-18
    # p device: source at VDD, gate at 0, drain at 0: current flows from s to d
    i, _, _, _ = mos_current("p", K, VT, LAM, 0.0, 0.0, 1.8)
    assert abs(i + K / 2 * 1.3**2 * (1 + LAM * 1.8)) < 1e-18
    rng = random.Random(61)
    eps = 1e-7
    for _ in range(300):
        kind = rng.choice("np")
        vd, vg, vs = (rng.uniform(-0.2, 2.0) for _ in range(3))
        i, gd, gg, gs = mos_current(kind, K, VT, LAM, vd, vg, vs)
        for k, g in enumerate((gd, gg, gs)):
            up = [vd, vg, vs]
            dn = [vd, vg, vs]
            up[k] += eps
            dn[k] -= eps
            fd = (mos_current(kind, K, VT, LAM, *up)[0] - mos_current(kind, K, VT, LAM, *dn)[0]) / (2 * eps)
            assert abs(fd - g) < 1e-6 * K + 1e-3 * abs(g)


def random_rc(rng, n):
    ckt = Circuit(n + 1, {0: lambda t: 0.0})
    for i in range(1, n + 1):
        ckt.cap(i, 0, rng.uniform(0.5, 1.5))
        ckt.res(i, 0, rng.uniform(0.1, 1.0))
    for _ in range(2 * n):
        a, b = rng.sample(range(1, n + 1), 2)
        ckt.res(a, b, rng.uniform(0.5, 3.0))
        ckt.cap(a, b, rng.uniform(0.1, 1.0))
    return ckt.build()


def test_hand_example_of_the_page():
    ckt = Circuit(3, {0: lambda t: 0.0})
    ckt.cap(1, 0, 1.0)
    ckt.cap(2, 0, 1.0)
    ckt.res(1, 0, 1.0)
    ckt.res(2, 0, 1.0)
    ckt.res(1, 2, 1.0)
    ckt.build()
    vn = [0.0, 1.0, 0.0]
    v = list(vn)
    evals = relax_time_point(ckt, v, vn, 1.0, {1, 2}, 0.01, 100)
    assert evals == 6
    assert abs(v[1] - 91 / 243) < 1e-15 and abs(v[2] - 91 / 729) < 1e-15


def test_linear_node_update_is_exact():
    rng = random.Random(62)
    ckt = random_rc(rng, 5)
    vn = [0.0] + [rng.uniform(-1, 1) for _ in range(5)]
    v = list(vn)
    for i in ckt.unknown:
        f, dv = node_row(ckt, i, v, vn, 0.3)
        v[i] -= f / dv[i]
        assert abs(node_row(ckt, i, v, vn, 0.3)[0]) < 1e-12


def test_gauss_seidel_contraction_and_stopping_bound():
    rng = random.Random(63)
    for _ in range(20):
        n = rng.randint(3, 8)
        ckt = random_rc(rng, n)
        h = rng.uniform(0.1, 2.0)
        vn = [0.0] + [rng.uniform(-1, 1) for _ in range(n)]
        exact = backward_euler_newton(ckt, vn, h, 1)[1][1]
        rho = jacobian_rho(ckt, vn, vn, h)
        assert rho < 1  # C/h + G is strictly diagonally dominant for these networks
        v = list(vn)
        err = max(abs(v[i] - exact[i]) for i in ckt.unknown)
        for _ in range(12):
            step = sweep(ckt, v, vn, h)
            new = max(abs(v[i] - exact[i]) for i in ckt.unknown)
            assert new <= rho * err + 1e-14
            assert new <= rho / (1 - rho) * step + 1e-14
            err = new


def test_ita_matches_full_newton_backward_euler():
    ckt, v0 = chain(4)
    ref = backward_euler_newton(ckt, v0, 1e-12, 600)
    out6, ev6 = ita(ckt, v0, 1e-12, 600, 1e-6)
    out8, ev8 = ita(ckt, v0, 1e-12, 600, 1e-8)
    assert maxdiff(out6, ref, ckt.unknown) < 2e-5
    assert maxdiff(out8, ref, ckt.unknown) < 2e-7
    assert ev6 < ev8
    for i in (3, 4, 5):
        assert abs(crossing(out6, i) - crossing(ref, i)) < 1e-14
    # one sweep per time point (no iteration) is visibly different
    one, _ = one_sweep_simulation(ckt, v0, 1e-12, 600)
    assert maxdiff(one, ref, ckt.unknown) > 0.05
    assert abs(crossing(one, 5) - crossing(ref, 5)) > 5e-12


def test_crosstalk_two_way_coupling():
    ckt, v0 = chain(2)
    ckt.n += 2
    vin, vic = ckt.n - 2, ckt.n - 1
    ckt.fixed[vin] = lambda t: 0.0
    ckt.mos("n", vic, vin, 0, K / 4, VT, LAM)
    ckt.mos("p", vic, vin, 1, K / 4, VT, LAM)
    ckt.cap(vic, 0, 5e-15)
    ckt.cap(vic, 3, 20e-15)  # strong coupling to the first output
    v0 = v0 + [0.0, VDD]
    ref = backward_euler_newton(ckt, v0, 1e-12, 500)
    out, _ = ita(ckt, v0, 1e-12, 500, 1e-6)
    one, _ = one_sweep_simulation(ckt, v0, 1e-12, 500)
    assert maxdiff(out, ref, ckt.unknown) < 5e-4
    dip_ref = min(x[vic] for _, x in ref)
    dip_ita = min(x[vic] for _, x in out)
    dip_one = min(x[vic] for _, x in one)
    assert abs(dip_ita - dip_ref) < 1e-4
    assert abs(dip_one - dip_ref) > 0.05


def test_latency_skips_quiet_nodes():
    ckt, v0 = chain(8)
    _, e1 = ita(ckt, v0, 1e-12, 1000, 1e-6)
    _, e2 = ita(ckt, v0, 1e-12, 2000, 1e-6)
    _, e3 = ita(ckt, v0, 1e-12, 3000, 1e-6)
    assert e1 > 0 and e2 > e1  # the edge travels down the chain in the first 2 ns
    assert e2 == e3  # after 2 ns no node moves by more than tau: no evaluation at all


def gyrator(h):
    c = Circuit(3, {0: lambda t: 0.0})
    c.cap(1, 0, 1.0)
    c.cap(2, 0, 1.0)
    c.res(1, 0, 1.0)
    c.res(2, 0, 1.0)
    c.vccs(1, 0, 2, 0, 2.0)
    c.vccs(2, 0, 1, 0, -2.0)
    return c


def test_relaxation_needs_dominance_full_newton_does_not():
    # node Jacobian [[1/h + 1, 2], [-2, 1/h + 1]]: Gauss-Seidel rate 4 / (1/h + 1)^2
    for h in (0.25, 0.5):
        out, _ = ita(gyrator(h), [0.0, 1.0, 0.0], h, 3, 1e-10, max_evals=2000)
        ref = backward_euler_newton(gyrator(h), [0.0, 1.0, 0.0], h, 3)
        assert maxdiff(out, ref, [1, 2]) < 1e-9
    for h in (1.0, 2.0):
        backward_euler_newton(gyrator(h), [0.0, 1.0, 0.0], h, 3)
        with pytest.raises(NonConvergence):
            ita(gyrator(h), [0.0, 1.0, 0.0], h, 3, 1e-10, max_evals=2000)


def test_small_steps_make_the_chain_dominant():
    ckt, v0 = chain(4)
    ref = backward_euler_newton(ckt, v0, 1e-12, 600)
    rho = max(jacobian_rho(ckt, x, x, 1e-12) for _, x in ref)
    # limit as h -> 0: coupling capacitance over total capacitance, 4 fF / 14 fF
    assert rho < 4 / 14 + 0.01
    assert max(jacobian_rho(ckt, x, x, 1e-10) for _, x in ref) > 1

History

MOTIS (Chawla, Gummel and Kozak, 1975) introduced the one-sweep node-by-node update for MOS circuits. Saleh, Kleckner and Newton described iterated timing analysis for the SPLICE1 mixed-mode simulator at ICCAD-83: the sweep is repeated at each time point, with event-driven scheduling of the nodes to evaluate, until the relaxation converges. Newton and Sangiovanni-Vincentelli (1984) placed timing simulation, ITA and waveform relaxation in one framework of relaxation methods for circuit equations, with their convergence conditions.

References

  1. Resve A. Saleh, James E. Kleckner and A. Richard Newton, Iterated timing analysis in SPLICE1, ICCAD-83 Digest of Technical Papers, 139 to 140, 1983, the method (event-driven nonlinear Gauss-Seidel relaxation with one Newton step per node, repeated at each time point until convergence) and its use in SPLICE1
  2. A. R. Newton and A. L. Sangiovanni-Vincentelli, Relaxation-based electrical simulation, IEEE Transactions on Computer-Aided Design 3(4), 308 to 331, 1984, nonlinear relaxation at the level of the time-discretized equations, Gauss-Seidel-Newton and its convergence conditions, timing simulation as one sweep, iterated timing analysis, and waveform relaxation
  3. B. R. Chawla, H. K. Gummel and P. Kozak, MOTIS, an MOS timing simulator, IEEE Transactions on Circuits and Systems CAS-22(12), 901 to 910, 1975, the one-sweep node-by-node update that iterated timing analysis repeats to convergence
  4. James M. Ortega and Werner C. Rheinboldt, Iterative Solution of Nonlinear Equations in Several Variables, SIAM Classics in Applied Mathematics 30, 2000 (first published 1970), Chapter 10, Ostrowski's theorem on points of attraction and its use for nonlinear Gauss-Seidel and SOR-Newton iterations
  5. Harold Shichman and David A. Hodges, Modeling and simulation of insulated-gate field-effect transistor switching circuits, IEEE Journal of Solid-State Circuits 3(3), 285 to 289, 1968, the square-law MOSFET model used by the tests

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example