Algorithmadvanced
Asymptotic waveform evaluation
Also called AWE.
Pillage and Rohrer's reduced model of a linear circuit that matches 2q moments of its response by a q-pole Pade approximation.
- Solves
- Model order reduction
- Time
- Θ(n³ + q n² + q³ + I q²) worst · average · best
- Space
- Θ(n² + q²) extra
- Where
- I = the number of sweeps of the root finder; n = the number of nodes of the circuit; q = the number of poles of the model
- Model
- Real RAM
- Properties
- deterministicnot exactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Lawrence T. Pillage, Ronald A. Rohrer, 1990
Asymptotic waveform evaluation (AWE) replaces a large linear RC or RLC circuit, such as an RC tree of an extracted wire, by a small model with poles. It computes the moments of the transfer function, the coefficients of its Taylor series at , by repeated solves with the conductance matrix. From moments it builds the Padé approximation with poles, then the poles, the residues and the response in closed form. Pillage and Rohrer published it in 1990. With it gives the Elmore delay. With it gives the exact transfer function. In between, the model can have unstable poles although the circuit is stable.
In plain words
A wire with many resistors and capacitors responds to a step at its input with a smooth rise at its output. The exact rise is a sum of many decaying exponentials, one per node. AWE keeps only a few of them.
It does not simulate the circuit in time. It solves for the voltages once at DC, and then again with the capacitors fed by the previous solution, a few times. Each solve gives one number, a moment. From moments it fits a ratio of two polynomials that has poles and agrees with the first moments. The poles and residues of this ratio give a formula for the response, from which the delay at 50 percent can be read.
The problem
The input is a linear circuit in nodal form,
with real matrices (conductances, invertible) and (capacitances), an input vector , an output vector , and an order . The transfer function is , and its expansion at is
The output is a rational function with , and whose expansion agrees with , together with its poles (the roots of ) and residues . This is a model order reduction problem: a model of order for a circuit of order .
The algorithm
AWE(G, C, b, l, q)- 1
x_0 ← G⁻¹ b ▷ the DC solution, one LU of G - 2
for k ← 1 to 2q − 1 do x_k ← G⁻¹ (−C x_{k−1}) ▷ reuse the LU of G - 3
m_k ← lᵀ x_k for k = 0 .. 2q − 1 ▷ the moments - 4
b_0 ← 1; solve Σ_{j=1..q} b_j m_{k−j} = −m_k for k = q .. 2q − 1 - 5
a_k ← Σ_{j=0..k} b_j m_{k−j} for k = 0 .. q − 1 - 6
p_1 .. p_q ← the roots of Q(s) = Σ_{j=0..q} b_j s^j - 7
k_i ← P(p_i) / Q′(p_i) for i = 1 .. q, where P(s) = Σ_k a_k s^k - 8
return P, Q, the poles p_i and the residues k_i
Lines L1 to L3 compute the moments. Line L4 is the Hankel system of the Padé approximation: it makes the coefficients of in vanish. Line L5 takes the low-order part of as the numerator. Line L6 finds the poles, for example by the Durand-Kerner method. Line L7 is the partial fraction decomposition for simple poles. The response to a unit step is then
The implementation computes lines L1 to L5 in exact rational arithmetic and lines L6 and L7 in floating point. It checks the stability of exactly by the Routh-Hurwitz criterion.
Example
A stable model. Take a ladder of three sections, with , and a unit step source at its left end, and the output at the far end. The DC solution is all ones, so , and the moments are . The Elmore delay is .
| poles | 50 percent delay | |||
|---|---|---|---|---|
| 1 | ||||
| 2 | , | 5.9428 | ||
| 3 | , , | 5.9404 |
For , line L4 solves and , so and , and line L5 gives and . The model with is the exact transfer function. The two-pole model has the right dominant pole to four digits and a 50 percent delay within 0.04 percent of the exact 5.9404. The one-pole model is 6.7 percent early here.
An unstable model. Take the same circuit with the output at the middle node. The moments are , and line L4 solves and , so . Its roots are and . The model has a pole in the right half-plane, and its step response grows without bound, although every pole of the circuit is negative. The model with at this node is exact and stable.
Correctness
The proof shows the following.
- Moments. Lines L1 to L3 give the Taylor coefficients of at 0, by the Neumann series of .
- 2q moments are matched. If the Hankel matrix of line L4 is invertible, then , and is the only rational function of that type with this property.
- q = n is exact. By Cramer's rule, with of degree at most and , so with the model is itself and .
- Residues and the step response. For simple poles, line L7 gives the partial fractions, the step response has the form above, and .
- Elmore delay. For an RC tree, and is the Elmore delay at the output.
- Stability is not guaranteed. The unstable example above is a proof that AWE with can give a pole in the right half-plane for a stable RC tree.
What is proved is the matching of moments, not an error bound on the waveform or the delay for . The rest is measured. On 300 random RC trees with 3 to 6 nodes and integer and from 1 to 9 (Python random.Random(9)), at all 1296 outputs, the model with was unstable at 112 outputs (8.6 percent). At the other 1184, the mean relative error of the 50 percent delay against the exact model was 3.1 percent for and 46 percent for . The error was more than 10 percent at 44 outputs for and at 541 for . The worst cases were near the driver, where a slow pole with a small residue appears.
Proof: AWE computes the moments of the transfer function, its model matches the first 2q of them and is the unique such model, q = n gives the exact function, and stability is not guaranteedfull
Setting. A linear circuit has the nodal equations in the Laplace domain, where and are real matrices, is invertible, is the input vector and the input. The output is . So the transfer function is
Write and . All arithmetic in lines L1 to L5 is exact (rational numbers); lines L6 and L7 use floating point.
Theorem 1 (moments). For , where is the spectral radius ( unrestricted if ),
and lines L1 to L3 compute .
Proof. , so . For the Neumann series converges, which gives the expansion. Line L1 sets , and line L2 sets , so by induction, and line L3 gives .
Theorem 2 (matching of 2q moments). Suppose the Hankel matrix with entries (, ) is invertible. Let , let solve line L4 and let be given by line L5. With and ,
So the Taylor coefficients of at 0 are .
Proof. The coefficient of in is . For , by line L5. For , by line L4. So has no terms of degree below . Since , is a power series, and .
Theorem 3 (uniqueness). Under the hypothesis of Theorem 2, if and are polynomials with , , and , then and .
Proof. . Since , the coefficients of in are 0, which says that the coefficients of solve the system of line L4. As is invertible, . Then is the part of degree below of , which is .
Theorem 4 (q = n is exact). Let and suppose that line L4 succeeds for . Then , and as rational functions.
Proof. By Cramer's rule, , where is the determinant of with column replaced by . Each term of is a product of entries of degree at most 1 in , so , and each term of has one constant factor from , so . Hence with and . Also . The pair , meets the conditions of Theorem 3 with , since . So and .
If is singular, line L4 has no unique solution, and the implementation raises an error. This happens, for example, for on a circuit with one capacitor, whose moments give .
Theorem 5 (residues and step response). Suppose and the roots of are simple. Then
and the inverse Laplace transform of , the response of the model to a unit step, is
Proof. and the roots are simple, so the partial fraction decomposition has the stated form, with , since and . No root is 0 because . Then
whose inverse transform is . Summing over gives . At the decomposition gives , and . So the constant is , and .
Lines L6 and L7 compute the roots and the residues in floating point by an iteration, so the poles and residues of the implementation are approximations of these exact values. The coefficients of and are exact.
Theorem 6 (the first moment is minus the Elmore delay). For an RC tree driven at its root through the resistor by a source of value 1, with a capacitor from node to ground, and output at node (), and , the Elmore delay, where is the resistance of the common part of the paths from the source to and to .
Proof. At no current flows in the capacitors, so no current flows in the resistors, and every node has voltage 1: , and . Then . Here is the voltage at node when the source is set to 0 and a unit current is injected at node . That current flows to ground along the unique path from to the source, so the voltage at a node on that path is the resistance between the node and the source, and every node off the path has the voltage of the node where its path to the source meets the path from . The voltage at is therefore the resistance of the common part of the two paths, .
Proposition 7 (stability is not guaranteed). There is an RC tree, whose poles all lie in the open left half-plane, for which the AWE model with has a pole in the right half-plane.
Proof. Take the ladder with and and the output at the middle node. Exact computation by lines L1 to L3 gives . Line L4 solves and , so and , and . Its roots are , and . The circuit itself has . All its coefficients are positive and , so by the Routh-Hurwitz condition for degree 3 all its roots have negative real parts.
The function is_stable of the implementation decides with the Routh test in exact arithmetic whether all roots of lie in the open left half-plane. Its correctness is the Routh-Hurwitz theorem, which is not proved here.
Theorem 8 (running time). With dense matrices of order , lines L1 to L3 take arithmetic operations: one LU factorization of and triangular solves and products with . Lines L4 and L5 take and . Each iteration of the root finder in line L6 takes , and line L7 takes .
Proof. The LU factorization of a dense matrix takes operations, each pair of triangular solves , and each product and each inner product at most . The Hankel system is a dense system. Line L5 sums at most products for each of coefficients. One Durand-Kerner sweep evaluates and a product of differences at each of points. Line L7 evaluates two polynomials of degree below at points.
No bound on the number of iterations of the root finder is proved here. For an RC tree, is sparse and the moments take operations each by two passes over the tree, as for the Elmore delay.
Complexity
- Moments. With dense matrices, one LU factorization of costs , and each of the moments costs for a product with and two triangular solves. For an RC tree, is a tree Laplacian plus a diagonal, and each moment takes time by two passes over the tree, as in the Elmore delay.
- Padé and residues. The Hankel system costs , the numerator , and each sweep of the root finder . No bound on the number of sweeps is proved here. In practice is 2 to 4, so this part is small.
- Space. The LU factors take for dense matrices, and only two moment vectors are needed at a time.
- Compared with simulation. A time-domain simulation solves one linear system per time step, and needs many steps to resolve the fastest and the slowest time constants. AWE needs solves with one matrix.
Properties
- Not exact for . It is an approximation of the transfer function near , so it is good for the slow parts of the response and less good for the start of the step response.
- The moments are exact. In exact arithmetic, the first moments of the model equal those of the circuit.
- Not stable in general. The Padé approximation does not keep the stability of the circuit, as the example shows. The model also need not be passive, so it can make a larger circuit unstable when it is connected to other parts.
- Ill-conditioned in floating point. The moments grow or shrink like powers of the time constants, so the Hankel matrix becomes nearly singular as grows. In floating point, AWE is useful only for small . The implementation here avoids this problem by exact arithmetic, which costs more time.
Variants and improvements
- Moment shifting and frequency scaling. Expand at a point , or scale , to reduce the spread of the moments.
- Complex frequency hopping. Expand at several points and combine the poles found near each of them.
- Krylov methods. The moments span the Krylov subspace of and . Padé via Lanczos (PVL) of Feldmann and Freund computes the same Padé model from a Lanczos process without forming the moments. PRIMA uses an Arnoldi basis and a congruence transform, matches block moments instead of , and keeps the model passive.
- Closed-form delay metrics. Formulas in the first two or three moments of an RC tree give fast delay estimates that are always defined, with no poles to compute.
When to use it
- To get a delay and a slew of an RC or RLC interconnect that is more accurate than the Elmore delay, with a cost of a few linear solves.
- For a few low-order models where the result is checked for stability, and where a lower order is used if it is not stable.
- Not when the reduced model is connected back to a simulator and must be passive. Use PRIMA or a similar projection method.
Pitfalls
- Unstable poles. Always check the poles. A model with a pole in the right half-plane, as in the example, has a response that grows without bound. The usual fix is to use a lower order, or to drop the unstable poles and refit the residues.
- Singular Hankel matrix. With one capacitor, the moments are and the Hankel matrix for is singular. A circuit with fewer distinct poles than has no model with poles.
- Rounding of the moments. In floating point, the moments must be scaled, or the Hankel matrix is singular to working precision already for small .
- Multiple poles. Line L7 assumes simple poles. For a double pole the response has a term , and the residue formula divides by .
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/asymptotic-waveform-evaluation/. The authors are listed in prov/5A3DBS.jsonl.
import cmath
from fractions import Fraction
from typing import NamedTuple, Sequence
class AweModel(NamedTuple):
moments: list # m_0 .. m_{2q-1}, exact
numerator: list # a_0 .. a_{q-1} of P(s), exact
denominator: list # b_0 = 1, b_1 .. b_q of Q(s), exact
poles: list # roots of Q, complex floats
residues: list # P(p) / Q'(p) for each pole, complex floats
def lu_factor(A: Sequence[Sequence]) -> tuple:
"""LU factorization with row pivoting on the first non-zero entry (exact for Fractions)."""
n = len(A)
M = [[Fraction(x) for x in row] for row in A]
perm = list(range(n))
for c in range(n):
p = next((r for r in range(c, n) if M[r][c] != 0), None)
if p is None:
raise ValueError("singular matrix")
M[c], M[p] = M[p], M[c]
perm[c], perm[p] = perm[p], perm[c]
for r in range(c + 1, n):
if M[r][c] != 0:
f = M[r][c] / M[c][c]
M[r][c] = f
for k in range(c + 1, n):
M[r][k] -= f * M[c][k]
return M, perm
def lu_solve(factor: tuple, rhs: Sequence) -> list:
M, perm = factor
n = len(M)
y = [Fraction(rhs[perm[i]]) for i in range(n)]
for i in range(n):
for k in range(i):
y[i] -= M[i][k] * y[k]
for i in range(n - 1, -1, -1):
for k in range(i + 1, n):
y[i] -= M[i][k] * y[k]
y[i] /= M[i][i]
return y
def polyval(c: Sequence, s):
"""c[k] is the coefficient of s^k."""
v = 0
for x in reversed(c):
v = v * s + x
return v
def durand_kerner(c: Sequence, iterations: int = 2000) -> list:
"""All complex roots of the polynomial with coefficients c (c[k] of s^k)."""
c = [complex(x) for x in c]
while c and c[-1] == 0:
c.pop()
deg = len(c) - 1
if deg < 1:
return []
monic = [x / c[-1] for x in c]
radius = 1.0 + max(abs(x) for x in monic[:-1]) # Cauchy bound on the roots
z = [radius * (0.4 + 0.9j) ** k for k in range(deg)]
for _ in range(iterations):
change = 0.0
for i in range(deg):
den = 1.0
for j in range(deg):
if j != i:
den *= z[i] - z[j]
step = polyval(monic, z[i]) / den
z[i] -= step
change = max(change, abs(step))
if change <= 1e-15 * radius:
break
return z
def moments(G, C, b, l, count: int) -> list:
"""m_k = l^T (-G^{-1} C)^k G^{-1} b for k = 0 .. count-1, exactly."""
n = len(G)
factor = lu_factor(G)
x = lu_solve(factor, b) # @line L1
out = [sum(Fraction(l[i]) * x[i] for i in range(n))] # @line L3
for _ in range(count - 1):
cx = [-sum(Fraction(C[i][j]) * x[j] for j in range(n)) for i in range(n)]
x = lu_solve(factor, cx) # @line L2
out.append(sum(Fraction(l[i]) * x[i] for i in range(n))) # @line L3
return out
def asymptotic_waveform_evaluation(G, C, b, l, q: int) -> AweModel:
"""The q-pole AWE model of H(s) = l^T (G + sC)^{-1} b.
G, C are n x n matrices and b, l vectors of ints or Fractions. The model
P(s)/Q(s) with deg P <= q-1 and deg Q <= q matches the moments m_0 ..
m_{2q-1}. Raises ValueError if the Hankel matrix of the moments is singular.
"""
if q < 1:
raise ValueError("q must be at least 1")
m = moments(G, C, b, l, 2 * q)
hankel = [[m[k - j] for j in range(1, q + 1)] for k in range(q, 2 * q)]
rhs = [-m[k] for k in range(q, 2 * q)]
den = [Fraction(1)] + lu_solve(lu_factor(hankel), rhs) # @line L4
num = [sum(den[j] * m[k - j] for j in range(k + 1)) for k in range(q)] # @line L5
poles = durand_kerner(den) # @line L6
dden = [k * den[k] for k in range(1, len(den))]
residues = [polyval(num, p) / polyval(dden, p) for p in poles] # @line L7
return AweModel(m, num, den, poles, residues) # @line L8
def is_stable(den: Sequence) -> bool:
"""Exact Routh test: True if and only if every root of Q lies in the open left half-plane."""
c = [Fraction(x) for x in den]
while c and c[-1] == 0:
c.pop()
if len(c) <= 1:
return True
hi = c[::-1] # coefficients from the highest power down
rows = [hi[0::2], hi[1::2]]
while len(rows[-1]) > 0 and any(x != 0 for x in rows[-1]):
a, b = rows[-2], rows[-1]
if b[0] == 0:
return False # a zero pivot: some root is on or right of the imaginary axis
nxt = []
for j in range(len(a) - 1):
right = b[j + 1] if j + 1 < len(b) else 0
nxt.append((b[0] * a[j + 1] - a[0] * right) / b[0])
rows.append(nxt)
rows = [r for r in rows if r]
if len(rows) != len(c):
return False # a row of zeros: roots symmetric about the origin
first = [r[0] for r in rows]
return all(x != 0 for x in first) and all((x > 0) == (first[0] > 0) for x in first)
def step_response(model: AweModel, t: float) -> float:
"""y(t) = m_0 + sum_i (k_i / p_i) exp(p_i t), the response to a unit step at t = 0."""
y = complex(model.moments[0])
for p, k in zip(model.poles, model.residues):
y += k / p * cmath.exp(p * t)
return y.real
test_asymptotic_waveform_evaluation.py 283 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/asymptotic-waveform-evaluation/. The authors are listed in prov/5A3DBS.jsonl.
import itertools
import random
from fractions import Fraction
import pytest
from asymptotic_waveform_evaluation import (
asymptotic_waveform_evaluation,
durand_kerner,
is_stable,
moments,
polyval,
step_response,
)
def rc_tree(parent, R, C):
"""Nodal equations (G + sC) v = b for an RC tree driven by a unit source through R[root]."""
n = len(parent)
G = [[Fraction(0)] * n for _ in range(n)]
Cm = [[Fraction(0)] * n for _ in range(n)]
b = [Fraction(0)] * n
for i in range(n):
g = 1 / Fraction(R[i])
Cm[i][i] = Fraction(C[i])
G[i][i] += g
if parent[i] < 0:
b[i] += g
else:
p = parent[i]
G[p][p] += g
G[i][p] -= g
G[p][i] -= g
return G, Cm, b
def unit(n, i):
return [1 if k == i else 0 for k in range(n)]
def random_tree(rng, n):
parent = [-1] + [rng.randrange(i) for i in range(1, n)]
R = [rng.randint(1, 9) for _ in range(n)]
C = [rng.randint(1, 9) for _ in range(n)]
return parent, R, C
def polymul(a, b):
out = [Fraction(0)] * (len(a) + len(b) - 1)
for i, x in enumerate(a):
for j, y in enumerate(b):
out[i + j] += x * y
return out
def polyadd(a, b):
k = max(len(a), len(b))
return [(a[i] if i < len(a) else 0) + (b[i] if i < len(b) else 0) for i in range(k)]
def det_poly(M):
"""det of a matrix of polynomials by the Leibniz formula."""
n = len(M)
total = [Fraction(0)]
for perm in itertools.permutations(range(n)):
sign = 1
for i in range(n):
for j in range(i + 1, n):
if perm[i] > perm[j]:
sign = -sign
p = [Fraction(sign)]
for i in range(n):
p = polymul(p, M[i][perm[i]])
total = polyadd(total, p)
return total
def exact_transfer(G, C, b, l):
"""H(s) = N(s) / D(s) by Cramer's rule, with no moments involved."""
n = len(G)
M = [[[G[i][j], C[i][j]] for j in range(n)] for i in range(n)]
D = det_poly(M)
N = [Fraction(0)]
for i in range(n):
if l[i] != 0:
Mi = [[[b[r], 0] if c == i else M[r][c] for c in range(n)] for r in range(n)]
N = polyadd(N, [l[i] * x for x in det_poly(Mi)])
return N, D
def series(N, D, count):
"""The first count Taylor coefficients of N(s) / D(s) at s = 0."""
out = []
for k in range(count):
v = N[k] if k < len(N) else Fraction(0)
for j in range(1, min(k, len(D) - 1) + 1):
v -= D[j] * out[k - j]
out.append(v / D[0])
return out
def elmore(parent, R, C, i):
def path(v):
out = set()
while v >= 0:
out.add(v)
v = parent[v]
return out
pi = path(i)
return sum(C[k] * sum(R[e] for e in pi & path(k)) for k in range(len(parent)))
def test_moments_against_cramer_expansion():
rng = random.Random(1)
for _ in range(40):
n = rng.randint(1, 5)
parent, R, C = random_tree(rng, n)
G, Cm, b = rc_tree(parent, R, C)
l = [rng.randint(-2, 2) for _ in range(n)]
N, D = exact_transfer(G, Cm, b, l)
assert moments(G, Cm, b, l, 7) == series(N, D, 7)
def test_ladders_of_three_to_six_sections():
rng = random.Random(6)
for n in range(3, 7):
R = [rng.randint(1, 9) for _ in range(n)]
C = [rng.randint(1, 9) for _ in range(n)]
G, Cm, b = rc_tree([-1] + list(range(n - 1)), R, C)
l = unit(n, n - 1)
N, D = exact_transfer(G, Cm, b, l)
exact = series(N, D, 2 * n)
assert moments(G, Cm, b, l, 2 * n) == exact
for q in range(1, n + 1):
model = asymptotic_waveform_evaluation(G, Cm, b, l, q)
assert series(model.numerator, model.denominator, 2 * q) == exact[:2 * q]
def test_minus_first_moment_is_the_elmore_delay():
rng = random.Random(2)
for _ in range(60):
n = rng.randint(1, 7)
parent, R, C = random_tree(rng, n)
G, Cm, b = rc_tree(parent, R, C)
for i in range(n):
m = moments(G, Cm, b, unit(n, i), 2)
assert m[0] == 1
assert -m[1] == elmore(parent, R, C, i)
def test_model_matches_two_q_moments():
rng = random.Random(3)
checked = 0
for _ in range(80):
n = rng.randint(2, 6)
parent, R, C = random_tree(rng, n)
G, Cm, b = rc_tree(parent, R, C)
i = rng.randrange(n)
for q in range(1, n + 1):
try:
model = asymptotic_waveform_evaluation(G, Cm, b, unit(n, i), q)
except ValueError:
continue # singular Hankel matrix: no q-pole model exists
exact = moments(G, Cm, b, unit(n, i), 2 * q + 1)
assert series(model.numerator, model.denominator, 2 * q) == exact[:2 * q]
checked += 1
assert checked > 200
def test_q_equal_n_gives_the_exact_transfer_function():
rng = random.Random(4)
for _ in range(25):
n = rng.randint(1, 5)
_, R, C = random_tree(rng, n)
# Far end of a chain: the numerator is a constant, so no pole cancels.
G, Cm, b = rc_tree([-1] + list(range(n - 1)), R, C)
l = unit(n, n - 1)
N, D = exact_transfer(G, Cm, b, l)
model = asymptotic_waveform_evaluation(G, Cm, b, l, n)
assert model.denominator == [x / D[0] for x in D]
assert polymul(model.numerator, D) == polymul(N, model.denominator)[:len(model.numerator) + len(D) - 1]
assert is_stable(model.denominator)
assert all(p.real < 0 and abs(p.imag) < 1e-6 * abs(p) for p in model.poles)
def test_one_pole_model_is_the_elmore_exponential():
G, Cm, b = rc_tree([-1, 0, 1], [1, 2, 3], [3, 1, 2])
model = asymptotic_waveform_evaluation(G, Cm, b, unit(3, 2), 1)
td = elmore([-1, 0, 1], [1, 2, 3], [3, 1, 2], 2)
assert model.denominator == [1, td]
assert model.poles[0] == pytest.approx(-1 / td)
assert step_response(model, float(td)) == pytest.approx(1 - 1 / 2.718281828459045)
def test_unstable_two_pole_model():
# Ladder R = (1, 1, 1), C = (1, 2, 1), output at the middle node.
G, Cm, b = rc_tree([-1, 0, 1], [1, 1, 1], [1, 2, 1])
model = asymptotic_waveform_evaluation(G, Cm, b, unit(3, 1), 2)
assert model.moments == [1, -7, 48, -330]
assert model.denominator == [1, 6, -6]
assert not is_stable(model.denominator)
assert max(p.real for p in model.poles) == pytest.approx((6 + 60 ** 0.5) / 12, abs=1e-12)
# The circuit itself is stable, and so is the exact model q = 3.
exact = asymptotic_waveform_evaluation(G, Cm, b, unit(3, 1), 3)
assert is_stable(exact.denominator)
assert all(p.real < 0 for p in exact.poles)
def test_exact_stability_test_agrees_with_the_roots():
rng = random.Random(5)
for _ in range(400):
deg = rng.randint(1, 5)
roots = []
while len(roots) < deg:
re = rng.choice([-1, 1]) * rng.randint(1, 5) / 2
if deg - len(roots) >= 2 and rng.random() < 0.5:
im = rng.randint(1, 4) / 2
roots += [complex(re, im), complex(re, -im)]
else:
roots.append(complex(re, 0))
poly = [Fraction(1)]
for r in roots:
if r.imag > 0:
poly = polymul(poly, [Fraction(r.real ** 2 + r.imag ** 2), Fraction(-2 * r.real), Fraction(1)])
elif r.imag == 0:
poly = polymul(poly, [Fraction(-r.real), Fraction(1)])
assert is_stable(poly) == all(r.real < 0 for r in roots)
if len(set(roots)) == len(roots): # a multiple root is found to about sqrt(eps) only
found = durand_kerner(poly)
for r in roots:
assert min(abs(r - z) for z in found) < 1e-8
assert not is_stable([1, 0, 1]) # roots +i and -i
assert not is_stable([0, 1]) # root 0
assert is_stable([5])
def simulate(G, C, b, l, t_end, steps):
"""Brute force: RK4 on C v' = b - G v from v = 0, for a diagonal C."""
n = len(G)
Gf = [[float(x) for x in row] for row in G]
cf = [float(C[i][i]) for i in range(n)]
bf = [float(x) for x in b]
def f(v):
return [(bf[i] - sum(Gf[i][j] * v[j] for j in range(n))) / cf[i] for i in range(n)]
h = t_end / steps
v = [0.0] * n
for _ in range(steps):
k1 = f(v)
k2 = f([v[i] + h / 2 * k1[i] for i in range(n)])
k3 = f([v[i] + h / 2 * k2[i] for i in range(n)])
k4 = f([v[i] + h * k3[i] for i in range(n)])
v = [v[i] + h / 6 * (k1[i] + 2 * k2[i] + 2 * k3[i] + k4[i]) for i in range(n)]
return sum(l[i] * v[i] for i in range(n))
def test_step_response_against_simulation():
G, Cm, b = rc_tree([-1, 0, 1, 1], [1, 2, 1, 3], [1, 1, 2, 1])
l = unit(4, 3)
exact = asymptotic_waveform_evaluation(G, Cm, b, l, 4)
two = asymptotic_waveform_evaluation(G, Cm, b, l, 2)
assert step_response(exact, 0.0) == pytest.approx(0.0, abs=1e-9)
assert step_response(two, 0.0) == pytest.approx(0.0, abs=1e-9)
worst = 0.0
for t in (0.5, 2.0, 5.0, 10.0, 20.0):
y = simulate(G, Cm, b, l, t, 4000)
assert step_response(exact, t) == pytest.approx(y, abs=1e-8)
worst = max(worst, abs(step_response(two, t) - y))
assert worst < 0.02 # measured for this circuit, not a bound
def test_errors():
G, Cm, b = rc_tree([-1], [2], [3])
with pytest.raises(ValueError):
asymptotic_waveform_evaluation(G, Cm, b, [1], 0)
with pytest.raises(ValueError):
asymptotic_waveform_evaluation(G, Cm, b, [1], 2) # one pole only: singular Hankel matrix
assert polyval([1, 2, 3], 2) == 17
History
Elmore (1948) used the first moment of the impulse response as the delay of an amplifier, which is the case . Padé approximation of a series is much older. Pillage and Rohrer (1990) used the moments of the circuit equations to build models with poles for the timing analysis of interconnect, and AWE was widely used for RC and RLC delay calculation in the 1990s. The problems with stability and with conditioning led to Krylov-subspace methods such as PVL (1995) and PRIMA (1998).
References
- Lawrence T. Pillage and Ronald A. Rohrer, Asymptotic waveform evaluation for timing analysis, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 9(4), 352 to 366, 1990, the moment recurrence, the Padé approximation with q poles from 2q moments, the residues and the step response
- W. C. Elmore, The transient response of damped linear networks with particular regard to wideband amplifiers, Journal of Applied Physics 19(1), 55 to 63, 1948, the first moment of the impulse response as a delay, the one-pole case of AWE
Where this leads
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 5A3DBS Edit this page History Report an error Markdown