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
- Model
- Real RAM
- Properties
- deterministicnot exactiterative
- Evidence
- Proof sketchCode in 1 languages
- 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 unknown. Its elements are capacitors, resistors, voltage-controlled current sources and MOSFETs with the square-law Shichman-Hodges model, whose transconductance , threshold and channel-length modulation are fitted to measured device curves. With step and previous voltages , the backward Euler companion model turns each capacitor between nodes and into a current with . The node equation of unknown node is
the sum of the currents that leave node . 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 is the set of unknown nodes whose depends on : the nodes that share an element with through which current flows at . It includes and, for a transistor, the drain and source nodes of every transistor whose gate is .
Input: the circuit, the initial voltages (consistent, for example a DC operating point), the step , the number of steps and the tolerance . Output: the voltages at the times .
The algorithm
ITA(circuit, v0, h, s, τ)- 1
v ← v0 with the fixed nodes at time 0; A ← all unknown nodes - 2
for k = 1, 2, ..., s - 3
vⁿ ← v; set the fixed nodes to their values at t = kh; add to A the fanout of each fixed node that changed - 4
Q ← a first-in first-out queue holding the nodes of A - 5
while Q is not empty - 6
i ← remove the first node of Q - 7
(F, D) ← F_i(v) and ∂F_i/∂v_i, at the newest voltages - 8
δ ← −F / D; v_i ← v_i + δ - 9
if |δ| > τ: append to Q each node of fanout(i) that is not in Q - 10
A ← the fanout of each node with |v_i − vⁿ_i| > τ; record v at t = kh - 11
return the recorded waveforms
Line L8 is one Newton step on the equation of node 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 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 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 ) 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; s, V and V. The node equations are and , linear, so each update solves its node exactly. The backward Euler solution is .
| update | node | new value | queue after | |
|---|---|---|---|---|
| 1 | 1 | 2, 1 | ||
| 2 | 2 | 1, 2 | ||
| 3 | 1 | 2, 1 | ||
| 4 | 2 | 1, 2 | ||
| 5 | 1 | 2 | ||
| 6 | 2 | empty |
After update 2 the errors are and ; after update 4 they are and , nine times smaller. This is Gauss-Seidel on , whose rate is . The loop stops after six evaluations, when both moves are below , with errors and V.
An inverter chain. Four CMOS inverters with V, , V and 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 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, | 225.45 | 381.95 | 544.13 | 4588 node evaluations | |
| ITA, | 225.45 | 381.95 | 544.15 | 7712 node evaluations | |
| ITA, | 225.45 | 381.95 | 544.15 | 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 . 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.
- On a linear node equation, one Newton node update solves it exactly, so on a linear circuit ITA is linear Gauss-Seidel.
- If the node Jacobian is strictly diagonally dominant by rows with ratio , a sweep of exact node solves reduces the maximum-norm error by the factor , and a sweep that moves no node by more than is within of the backward Euler solution.
- With one Newton step per node, the sweeps converge locally at an asymptotic rate of at most (by Ostrowski's theorem, cited).
- If every node has a capacitance to ground, small enough steps make the Jacobian dominant: as , where is the capacitance from node to other unknown nodes.
- 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 .
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 ( 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 .
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 with step and previous voltages . The unknown node voltages must satisfy the backward Euler node equations , where is the sum of the currents that leave node : the capacitor currents with , and the resistive currents of resistors, controlled sources and transistor channels. The fixed nodes (ground, supplies, inputs) have known values at . The Jacobian is
where is the nodal capacitance matrix and the Jacobian of the resistive currents. We assume is continuously differentiable; the level-1 MOSFET model is, since its current and first derivatives agree at the boundaries of its three regions. Let be a solution of .
A node update of node changes only . An exact node update sets to a root of with the other voltages fixed. A Newton node update, line L8 of the page, sets . 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 .
Dominance assumption. On a convex set that contains and the iterates, and
for a constant , the sum taken over unknown nodes . That is, is strictly diagonally dominant by rows, uniformly on .
Lemma 1 (a Newton node update is exact on a linear node equation). If is affine in , one Newton node update sets .
Proof. If with and independent of , then , the root.
So on a linear circuit (resistors, capacitors, linear controlled sources), the iteration of the page is exactly linear Gauss-Seidel on .
Theorem 1 (contraction of a sweep). Under the dominance assumption, a sweep of exact node updates maps to with
Proof. Let node be updated when the current vector is , which has the new values for nodes earlier in the order and the old values for the others, and let be with replaced by . Then . Along the segment from to , which lies in ,
Integration keeps the dominance: , and . So
By induction on the order, every new value satisfies , so every entry of is within of , and the bound for node is .
With the sweeps converge to , and is the only solution in : 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 , that is , then .
Proof. , so and .
Theorem 2 (one Newton step per node converges locally). Under the dominance assumption at (that is, for ), sweeps of Newton node updates converge to from every start close enough to , at a rate of at most per sweep in the limit.
Proof. Let be the sweep map. Update computes . Since and is continuous with ,
So is differentiable at its fixed point , and is the sweep map of linear Gauss-Seidel on , the matrix for the splitting . Theorem 1, applied to the linear map (dominance holds everywhere for a constant matrix), gives for every , so the spectral radius of is at most . By Ostrowski's theorem on points of attraction (Ortega and Rheinboldt, Chapter 10), attracts all starts in a neighbourhood, with asymptotic rate at most .
Theorem 3 (small steps give dominance). Suppose every unknown node has a capacitance to ground or to a fixed node, let be the total capacitance from to other unknown nodes, so that and , and suppose that on , and with . Then for with for all , the dominance assumption holds with
and as .
Proof. In row of , the diagonal is and the off-diagonal sum is at most . The ratio is below 1 exactly when , which follows from and .
For a node at the drain or source of a MOSFET, the channel current contributes to (the output conductance, plus the transconductance at the source), so unless a controlled source or a transistor gate on the node itself makes negative. The off-diagonal terms 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 , 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 , and every later update of a node it reads also moved that node by at most .
Proof. Line L7 evaluates and at the current vector, which holds the newest value of every node, and line L8 is the Newton node update. A node that reads , which means that depends on , is in the fanout of , so any update of by more than puts back in the queue (line L9), and is in its own fanout. If the queue is empty, no update after the last update of was larger than on any node that reads, and the last update of was not larger than either, otherwise would be in the queue.
Theorem 4 is weaker than Corollary 1: many small updates of a neighbour, each below , can add up, and nodes that did not move by more than 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 (about 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 .
Complexity
One node evaluation reads the elements at the node. A sweep costs , and with at most sweeps' worth of evaluations per time point, steps cost . No matrix is formed or factored, and the memory is beyond the waveforms. When all nodes are latent, a step costs only the copy of the voltages, .
On a chain of eight inverters, the node evaluations with 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 evaluations in every step.
Properties
- Matrix-free. Only diagonal derivatives 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 adds an error of about the same order as .
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 and S (a stable circuit), have a Gauss-Seidel rate of . ITA converged at and s and exceeded the evaluation limit at and s, while full Newton solved every step.
- Steps too large for dominance. On the inverter chain the measured along the trajectory was 0.283 at ps, close to the limit of the coupling capacitances, but above 1 at ps.
- A loose tolerance freezes nodes. With 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 , so 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 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.
# 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
- 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
- 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
- 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
- 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
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 8PGXDW Edit this page History Report an error Markdown