Algorithmadvanced
PRIMA
Also called passive reduced-order interconnect macromodeling.
Odabasioglu, Celik and Pileggi's model order reduction by projection on a block Krylov subspace with Arnoldi, which keeps the reduced model passive.
- Solves
- Model order reduction
- Time
- Θ(n³ + k n² + k² n) worst · average · best
- Space
- Θ(n² + k n) extra
- Where
- k = the order of the reduced model (at most q p for q blocks of p ports); n = the number of unknowns of the circuit
- Model
- Real RAM
- Properties
- deterministicnot exactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Altan Odabasioglu, Mustafa Celik, Lawrence T. Pileggi, 1997
PRIMA reduces a large linear RLC circuit, such as the extracted model of a group of wires, to a small model that is passive: it does not create energy, so it can be connected to the rest of a circuit and simulated without making it unstable. It builds an orthonormal basis of the block Krylov subspace of the circuit equations by a block Arnoldi iteration, and then projects the matrices by the congruence , , . Odabasioglu, Celik and Pileggi published it in 1997 and 1998. The model matches block moments of the transfer function, half as many as the Padé model of AWE, but it keeps passivity and stability, which AWE and PVL do not.
In plain words
A model with the right moments, as in AWE, can still behave badly: it can have a pole in the right half-plane, or it can generate energy when it is connected to other parts. PRIMA chooses a few directions in the space of node voltages and currents, those that the input reaches in the first few steps of the equations. It then writes the circuit equations only in these directions.
The trick is the way the equations are cut down. Both sides of each matrix are multiplied by the same basis. This keeps the properties that make a circuit passive: resistors still only take energy, and capacitors and inductors still only store it. The price is that, for the same size, the model matches fewer moments than AWE.
The problem
The input is a linear circuit in modified nodal form,
with real matrices and of order ( invertible), inputs in and outputs in , and a number of blocks. For an RLC circuit, the unknowns are the node voltages and the inductor currents, and
with conductances , the incidence matrix of the inductors, their series resistances , the capacitances and the inductances . Then is positive semidefinite and is symmetric positive semidefinite. With (each port injects a current and observes its voltage), is the impedance matrix, and the circuit is passive.
The output is a reduced model of order whose block moments agree with the moments for and which is passive. This is a model order reduction problem with a passivity constraint.
The algorithm
PRIMA(G, C, B, L, q)- 1
R ← G⁻¹ B ▷ one LU of G, p solves - 2
X_0 ← an orthonormal basis of the columns of R ▷ Gram-Schmidt - 3
for k ← 1 to q − 1 do - 4
V ← G⁻¹ (−C X_{k−1}) ▷ the next block of A = −G⁻¹C - 5
for j ← 0 to k − 1 do V ← V − X_j (X_jᵀ V) ▷ block modified Gram-Schmidt - 6
X_k ← an orthonormal basis of the columns of V ▷ drop dependent columns - 7
X ← [X_0, X_1, …, X_{q−1}] - 8
Ĝ ← Xᵀ G X; Ĉ ← Xᵀ C X; B̂ ← Xᵀ B; L̂ ← Xᵀ L ▷ the congruence transform - 9
return Ĝ, Ĉ, B̂, L̂
Lines L1 to L7 are the block Arnoldi process on with the start block , with Gram-Schmidt orthogonalization. All solves use one LU decomposition of . Line L8 is the projection. It is a congruence: the same multiplies both sides of and . The reduced transfer function is . The implementation orthogonalizes each new vector twice and drops a vector whose norm falls below of its norm before line L5. It also has helpers for the moments, the transfer function and the poles of a model.
Example
An RC ladder with one port. Take three nodes in a chain, with from ground to node 0, node 0 to node 1 and node 1 to node 2, and from the nodes to ground. One port injects a current at node 0 and observes its voltage, so and is the input impedance. Its moments are .
At DC all three nodes are at the same voltage, so and . With , , and , so , with moments . The first two moments agree. The second basis vector for is , and
| moments of | poles | |
|---|---|---|
| 1 | ||
| 2 | , | |
| 3 | all | , , |
Here and are symmetric and , so moments agree, not only . With the model is the circuit.
An RLC ladder. Take three nodes with a conductance 1 at node 0 only, capacitors 1 at all nodes, and two branches, each a resistor 1 in series with an inductor 1, between nodes 0 and 1 and between nodes 1 and 2. There are 5 unknowns. The impedance at node 0 has moments . With the reduced model of order 2 has the moments and the poles and . With , the moments agree up to , and the poles are and . The circuit has the poles , and . All poles are in the left half-plane, as the theory says.
Correctness
The proof shows the following.
- The basis. The columns of are orthonormal and span the block Krylov subspace .
- q block moments. If is invertible, then for . The proof only uses that the span of contains the Krylov subspace.
- 2q block moments in the symmetric case. If and are symmetric and , as for an RC circuit, then for . For one port the model is then the Padé model of AWE, and so in that case the Padé model is stable.
- Full order. With columns in , .
- Passivity. If and are positive semidefinite and , the same holds for the reduced model, and is positive semidefinite for .
- Stability. Under the same conditions, with invertible, all poles of are in the closed left half-plane, and in the open one if is positive definite.
The proofs are in exact arithmetic. The tests check the moments against exact rational moments of RC and RLC ladders of 3 to 6 sections, the orthonormality of to , the poles and the positive-real condition at random points of the right half-plane in floating point. How many moments a model needs for a given accuracy of the waveform is not proved here; it depends on the circuit.
Proof: PRIMA spans the block Krylov subspace, matches q block moments (2q when G and C are symmetric), gives the full model at full order, and keeps passivity and stabilityfull
Setting. A linear circuit in modified nodal form is
with real of order , invertible, of size and of size . Write and . The block moments are the coefficients of at , (Neumann series of , as for AWE). The block Krylov subspace of order is
the span of all columns of these blocks. PRIMA returns the columns and the reduced matrices , , and , with and reduced moments , where and . The proofs are in exact arithmetic.
Theorem 1 (the basis). The columns of are orthonormal, and . More precisely, for each .
Proof. By induction on . Line L2 makes an orthonormal basis of the columns of , so the claim holds for . Suppose . Line L4 sets . Since the columns of lie in , those of lie in . Conversely, . Since , the columns of lie in the span of . For , the induction hypothesis gives . So lies in , and . Lines L5 and L6 subtract from its projection on and take an orthonormal basis of the rest, dropping the columns that are dependent (deflation). This changes neither nor the orthonormality of the whole set. If a whole block is dropped, then , the subspace is invariant under , all later are equal to it, and the loop can stop.
Theorem 2 (q block moments). If is invertible, then and for . The same holds for every of full column rank with ; orthonormality is not needed.
Proof. We show by induction. For : , so for some . Then , so and . For , let , so by the induction hypothesis. Since , for some . Multiply by : , so . Hence . Finally .
The hypothesis that is invertible is needed. When is positive definite, is positive definite too and is invertible. When is only semidefinite, as in the modified nodal form of an RLC circuit, can be singular although is not. Example: node voltages and inductor currents of a ladder with a conductance 1 at node 0 only, capacitors 1 at all nodes and inductors 1 between nodes 0, 1 and 1, 2, with one port at node 0. Then is (at DC the inductors are shorts), , and gives , and . Here because has a zero block for the currents, and the off-diagonal entries are 0 because each column of the incidence block sums to 0.
Theorem 3 (2q block moments in the symmetric case). If and are symmetric, and is invertible, then for .
Proof. Since is symmetric, , and . By induction, . So for ,
The reduced matrices and are symmetric and , so the same identities hold for with and . Let . By Theorem 2, and , so
The values and with cover .
For one port () with , symmetric and , the reduced model is a rational function with numerator degree at most and denominator degree at most that matches moments. So it is the Padé approximation of AWE, which is unique when its Hankel matrix is invertible. For an RC circuit with positive definite this Padé model is therefore stable, by Theorem 6.
Theorem 4 (full order). If has columns, then .
Proof. Then is an orthogonal matrix, and , so wherever either side exists, and .
Theorem 5 (passivity). Suppose is positive semidefinite, is symmetric positive semidefinite and . Then and have the same properties and . For every with at which is invertible, the Hermitian part is positive semidefinite, and .
Proof. , and , and . Now fix and a complex vector , and let . Then , using that the matrices are real. The real part of this is
since for a real symmetric . The real part of is . The last claim holds because all matrices are real.
This is the positive-real condition of a passive multiport, here on the set where is defined. The same computation with shows that the original circuit has the property, so the theorem says that the congruence transform keeps it.
Theorem 6 (poles). Under the hypotheses of Theorem 5, if is invertible, every pole of , that is every with , has . If moreover is positive definite, then . If and are symmetric and is positive definite, the poles are real and negative.
Proof. Let with . Then , and the real part gives . If , then because is positive semidefinite, so , which is impossible for invertible . So and . If is positive definite, so is (as has full column rank), and the inequality is strict. In the symmetric case, is a ratio of real numbers, negative when is positive definite.
Theorem 7 (running time). With dense matrices and columns in , PRIMA takes for the LU factorization of , for the solves and the products with in lines L1 and L4, for the Gram-Schmidt steps of lines L2, L5 and L6, and for line L8. It uses extra space.
Proof. Each of the columns is produced by one product with and two triangular solves, , and is orthogonalized twice against at most earlier columns, each. Line L8 forms and in and the inner products in . The LU factors take space and takes .
Complexity
- Time. One LU factorization of takes for dense matrices. Each of the basis vectors costs a product with and two triangular solves, , and two Gram-Schmidt passes against at most vectors, . The congruence takes . In total . For sparse circuits, the factorization and the products cost about the number of nonzero entries of the factors and of instead.
- Space. The factors of and the basis vectors, for dense matrices.
- Compared with AWE. The same number of solves with gives the same Krylov subspace. AWE forms the moments directly, which is ill-conditioned for larger , while PRIMA keeps an orthonormal basis, which is stable in floating point.
Properties
- Passive. The reduced model of an RLC circuit with is passive, so it can be connected to other passive or active parts in a simulator.
- Half the moments of Padé. In general block moments are matched where a Padé model of the same order matches . For symmetric and the count is again.
- Not a realizable netlist. The reduced matrices are dense and have no direct circuit form. Turning them into resistors and capacitors needs extra work.
- Order grows with ports. Each block has columns, so a model with many ports is large even for small .
- Numerically stable. With reorthogonalization, the basis stays orthonormal to rounding error, so larger orders work, unlike AWE.
Variants and improvements
- Expansion points. Use in place of for an to match moments at , which avoids a singular and gives better accuracy at high frequency. Several points can be combined in one basis (multi-point or rational Krylov methods).
- PVL and SyPVL. Padé via Lanczos of Feldmann and Freund computes the Padé model with a Lanczos process. It matches moments, but the model need not be passive. Symmetric variants for RC circuits keep passivity.
- Structure-preserving reduction. Split by the blocks of the unknowns (voltages and currents) before the congruence. The model then keeps the RLC structure and, in some methods, matches more moments.
- Balanced truncation. Balanced truncation has an a priori error bound but costs for Lyapunov equations, too much for large circuits. Positive-real balanced truncation keeps passivity.
When to use it
- To make small passive models of large RC or RLC interconnect networks for circuit simulation, timing and signal integrity analysis.
- When the model must be connected back to a simulator, where a non-passive model can create a growing response.
- Not when the number of ports is very large compared with the useful order, and not when a guaranteed error bound is needed.
Pitfalls
- . Passivity is proved only for . A model of a transfer from one node to another (a voltage gain, not an impedance) has no such guarantee.
- Singular . For an RLC circuit, can be singular although is not. The proof gives an example: an LC ladder with one conductance and gives , so the model has a pole at and does not match the moments. An expansion point avoids this.
- Loss of orthogonality. One Gram-Schmidt pass loses orthogonality after many steps. The proofs need the exact span, so reorthogonalize, and drop vectors that are nearly dependent.
- Breaking the congruence. Using a different basis on the left, or scaling the rows, keeps the moments but not passivity.
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/prima/. The authors are listed in prov/KQ4G00.jsonl.
import math
from typing import NamedTuple, Sequence
class ReducedModel(NamedTuple):
G: list # k x k, X^T G X
C: list # k x k, X^T C X
B: list # k x p, X^T B
L: list # k x r, X^T L
X: list # the k orthonormal basis vectors (each of length n)
def lu_factor(A: Sequence[Sequence]) -> tuple:
"""LU factorization with partial pivoting. Works for float and complex entries."""
n = len(A)
M = [list(row) for row in A]
perm = list(range(n))
for c in range(n):
p = max(range(c, n), key=lambda r: abs(M[r][c]))
if M[p][c] == 0:
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):
f = M[r][c] / M[c][c]
M[r][c] = f
if f != 0:
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 = [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 dot(u: Sequence, v: Sequence) -> float:
return sum(a * b for a, b in zip(u, v))
def matvec(A: Sequence[Sequence], x: Sequence) -> list:
return [dot(row, x) for row in A]
def columns(B: Sequence[Sequence]) -> list:
return [[row[j] for row in B] for j in range(len(B[0]))]
def project_out(v: list, block: list) -> list:
"""v minus its components along the orthonormal vectors of block, one at a time."""
for x in block:
h = dot(x, v)
v = [a - h * b for a, b in zip(v, x)]
return v
def orthonormalize(vectors: list, basis: list, scales=None, tol: float = 1e-10) -> list:
"""Modified Gram-Schmidt of vectors against basis and against each other.
Each vector is orthogonalized twice. A vector whose norm falls below tol
times its scale (by default its own norm) is dropped (deflation).
Returns the new unit vectors.
"""
out = []
for i, v in enumerate(vectors):
v = [float(x) for x in v]
first = math.sqrt(dot(v, v)) if scales is None else scales[i]
if first == 0.0:
continue
for _ in range(2):
for x in basis + out:
h = dot(x, v)
v = [a - h * b for a, b in zip(v, x)]
norm = math.sqrt(dot(v, v))
if norm > tol * first:
out.append([a / norm for a in v])
return out
def prima(G, C, B, L, q: int) -> ReducedModel:
"""PRIMA: congruence projection of (G + sC) x = B u, y = L^T x onto the block Krylov
subspace span{R, AR, ..., A^(q-1) R}, with A = -G^{-1} C and R = G^{-1} B.
G, C are n x n, B is n x p and L is n x r (lists of rows). With L = B,
G + G^T positive semidefinite and C symmetric positive semidefinite, the
reduced model is passive.
"""
if q < 1:
raise ValueError("q must be at least 1")
factor = lu_factor([[float(x) for x in row] for row in G])
R = [lu_solve(factor, [float(x) for x in b]) for b in columns(B)] # @line L1
blocks = [orthonormalize(R, [])] # @line L2
basis = list(blocks[0])
for _ in range(1, q): # @line L3
if not blocks[-1]:
break # the Krylov subspace is invariant: nothing new to add
V = [lu_solve(factor, [-x for x in matvec(C, v)]) for v in blocks[-1]] # @line L4
scales = [math.sqrt(dot(v, v)) for v in V]
for Xj in blocks:
V = [project_out(v, Xj) for v in V] # @line L5
new = orthonormalize(V, basis, scales) # @line L6
blocks.append(new)
basis.extend(new)
X = basis # @line L7
GX = [matvec(G, x) for x in X]
CX = [matvec(C, x) for x in X]
Gr = [[dot(X[i], GX[j]) for j in range(len(X))] for i in range(len(X))] # @line L8
Cr = [[dot(X[i], CX[j]) for j in range(len(X))] for i in range(len(X))]
Br = [[dot(x, b) for b in columns(B)] for x in X]
Lr = [[dot(x, c) for c in columns(L)] for x in X]
return ReducedModel(Gr, Cr, Br, Lr, X) # @line L9
def transfer(G, C, B, L, s: complex) -> list:
"""H(s) = L^T (G + sC)^{-1} B, an r x p complex matrix."""
n = len(G)
factor = lu_factor([[G[i][j] + s * C[i][j] for j in range(n)] for i in range(n)])
X = [lu_solve(factor, [complex(x) for x in b]) for b in columns(B)]
return [[dot(l, x) for x in X] for l in columns(L)]
def block_moments(G, C, B, L, count: int) -> list:
"""M_k = L^T (-G^{-1} C)^k G^{-1} B for k = 0 .. count-1, in floating point."""
factor = lu_factor([[float(x) for x in row] for row in G])
X = [lu_solve(factor, [float(x) for x in b]) for b in columns(B)]
out = []
for _ in range(count):
out.append([[dot(l, x) for x in X] for l in columns(L)])
X = [lu_solve(factor, [-x for x in matvec(C, v)]) for v in X]
return out
def polyval(c: Sequence, s):
v = 0
for x in reversed(c):
v = v * s + x
return v
def durand_kerner(c: Sequence, iterations: int = 4000) -> 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])
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 poles(Gr, Cr) -> list:
"""The finite poles of (Gr + s Cr)^{-1}: s = -1/mu for the non-zero eigenvalues mu of Gr^{-1} Cr.
The characteristic polynomial comes from the Faddeev-LeVerrier recurrence
and its roots from Durand-Kerner, so this is meant for small orders only.
"""
k = len(Gr)
factor = lu_factor(Gr)
cols = [lu_solve(factor, c) for c in columns(Cr)]
M = [[cols[j][i] for j in range(k)] for i in range(k)]
coeffs = [0.0] * (k + 1) # det(mu I - M) = sum coeffs[i] mu^i
coeffs[k] = 1.0
N = [[float(i == j) for j in range(k)] for i in range(k)]
for m in range(1, k + 1):
MN = [[dot(M[i], [N[r][j] for r in range(k)]) for j in range(k)] for i in range(k)]
c = -sum(MN[i][i] for i in range(k)) / m
coeffs[k - m] = c
N = [[MN[i][j] + (c if i == j else 0.0) for j in range(k)] for i in range(k)]
scale = max(abs(x) for x in coeffs)
mus = durand_kerner(coeffs)
out = []
for mu in mus:
if abs(mu) <= 1e-12 * scale:
continue
s = -1.0 / mu
# Newton polishing on det(Gr + s Cr): d/ds log det = trace((Gr + s Cr)^{-1} Cr).
for _ in range(3):
try:
f = lu_factor([[Gr[i][j] + s * Cr[i][j] for j in range(k)] for i in range(k)])
except ValueError:
break # s is an exact pole
t = sum(lu_solve(f, [complex(x) for x in c])[i] for i, c in enumerate(columns(Cr)))
if t == 0:
break
s -= 1.0 / t
out.append(s)
return out
test_prima.py 273 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/prima/. The authors are listed in prov/KQ4G00.jsonl.
import random
from fractions import Fraction
import pytest
from prima import block_moments, lu_factor, poles, prima, transfer
def rc_tree(parent, R, C, ports):
"""Nodal G, C of an RC tree with a resistor R[root] from the root to ground.
Port j injects a current at node ports[j] and observes its voltage (L = B)."""
n = len(parent)
G = [[Fraction(0)] * n for _ in range(n)]
Cm = [[Fraction(0)] * n for _ in range(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:
p = parent[i]
G[p][p] += g
G[i][p] -= g
G[p][i] -= g
B = [[Fraction(int(i == k)) for k in ports] for i in range(n)]
return G, Cm, B
def rlc_ladder(g, c, r, ind, ports):
"""Modified nodal analysis of an RLC ladder.
Node k has a conductance g[k] and a capacitor c[k] to ground. Branch j joins
node j and node j + 1 by a resistor r[j] in series with an inductor ind[j].
The unknowns are the n node voltages and the n - 1 branch currents, and
G = [[N, E], [-E^T, Rb]], C = diag(c, ind), so G + G^T >= 0 and C >= 0."""
n = len(g)
m = n - 1
size = n + m
G = [[Fraction(0)] * size for _ in range(size)]
Cm = [[Fraction(0)] * size for _ in range(size)]
for k in range(n):
G[k][k] = Fraction(g[k])
Cm[k][k] = Fraction(c[k])
for j in range(m):
a, b, row = j, j + 1, n + j
G[a][row] += 1
G[b][row] -= 1
G[row][a] -= 1
G[row][b] += 1
G[row][row] = Fraction(r[j])
Cm[row][row] = Fraction(ind[j])
B = [[Fraction(int(i == k)) for k in ports] for i in range(size)]
return G, Cm, B
def exact_solve(A, rhs):
n = len(A)
M = [list(row) + [rhs[i]] for i, row in enumerate(A)]
for col in range(n):
p = next(r for r in range(col, n) if M[r][col] != 0)
M[col], M[p] = M[p], M[col]
for r in range(n):
if r != col and M[r][col] != 0:
f = M[r][col] / M[col][col]
M[r] = [x - f * y for x, y in zip(M[r], M[col])]
return [M[i][n] / M[i][i] for i in range(n)]
def exact_moments(G, C, B, count):
"""Brute force: M_k = B^T (-G^{-1} C)^k G^{-1} B in exact arithmetic."""
n = len(G)
cols = [[B[i][j] for i in range(n)] for j in range(len(B[0]))]
X = [exact_solve(G, b) for b in cols]
out = []
for _ in range(count):
out.append([[sum(l[i] * x[i] for i in range(n)) for x in X] for l in cols])
X = [exact_solve(G, [-sum(C[i][j] * v[j] for j in range(n)) for i in range(n)]) for v in X]
return out
def close(A, B, rel):
scale = max(abs(x) for row in B for x in row)
return all(abs(a - b) <= rel * scale for ra, rb in zip(A, B) for a, b in zip(ra, rb))
def reduced_moments(model, count):
return block_moments(model.G, model.C, model.B, model.L, count)
def random_ladder(rng, n):
return [-1] + list(range(n - 1)), [rng.randint(1, 9) for _ in range(n)], [rng.randint(1, 9) for _ in range(n)]
def test_rc_ladders_match_q_and_2q_moments():
rng = random.Random(1)
for n in range(3, 7):
parent, R, C = random_ladder(rng, n)
G, Cm, B = rc_tree(parent, R, C, [0])
exact = exact_moments(G, Cm, B, 2 * n)
for q in range(1, n):
model = prima(G, Cm, B, B, q)
got = reduced_moments(model, 2 * q + 1)
for k in range(2 * q): # G and C are symmetric and L = B: 2q moments
assert close(got[k], [[float(x) for x in row] for row in exact[k]], 1e-9), (n, q, k)
# The next moment is not matched in general.
if q == 1:
assert not close(got[2], [[float(x) for x in row] for row in exact[2]], 1e-6)
def pade(m, q):
"""Exact [q-1/q] Pade approximation from the moments m_0 .. m_{2q-1}: (P, Q) with Q(0) = 1."""
hankel = [[m[k - j] for j in range(1, q + 1)] for k in range(q, 2 * q)]
den = [Fraction(1)] + exact_solve(hankel, [-m[k] for k in range(q, 2 * q)])
num = [sum(den[j] * m[k - j] for j in range(k + 1)) for k in range(q)]
return num, den
def test_one_port_rc_model_is_the_pade_approximation():
# Rational of type (q-1, q) matching 2q moments: the Pade approximation, which is unique.
rng = random.Random(7)
for _ in range(20):
n = rng.randint(3, 6)
parent = [-1] + [rng.randrange(i) for i in range(1, n)]
G, Cm, B = rc_tree(parent, [rng.randint(1, 9) for _ in range(n)], [rng.randint(1, 9) for _ in range(n)],
[rng.randrange(n)])
m = [row[0][0] for row in exact_moments(G, Cm, B, 2 * n)]
for q in range(1, n):
P, Q = pade(m, q)
model = prima(G, Cm, B, B, q)
for s in (0.2, 1j, 1 + 1j):
hr = transfer(model.G, model.C, model.B, model.L, s)[0][0]
h = sum(complex(a) * s ** k for k, a in enumerate(P)) / sum(complex(b) * s ** k for k, b in enumerate(Q))
assert abs(hr - h) <= 1e-7 * abs(h)
def test_rlc_and_multiport_match_q_block_moments():
rng = random.Random(2)
for n in range(3, 6):
g = [Fraction(rng.randint(1, 5), 10) for _ in range(n)]
c = [rng.randint(1, 5) for _ in range(n)]
r = [Fraction(rng.randint(1, 5), 10) for _ in range(n - 1)]
ind = [rng.randint(1, 5) for _ in range(n - 1)]
for ports in ([0], [0, n - 1]):
G, Cm, B = rlc_ladder(g, c, r, ind, ports)
size = len(G)
exact = exact_moments(G, Cm, B, 2 * size)
for q in range(1, size // len(ports)):
model = prima(G, Cm, B, B, q)
assert len(model.X) == q * len(ports)
got = reduced_moments(model, q)
for k in range(q):
assert close(got[k], [[float(x) for x in row] for row in exact[k]], 1e-8), (n, ports, q, k)
def test_basis_is_orthonormal_and_deflates():
rng = random.Random(3)
parent, R, C = random_ladder(rng, 6)
G, Cm, B = rc_tree(parent, R, C, [0, 5])
model = prima(G, Cm, B, B, 3)
X = model.X
assert len(X) == 6
for i in range(len(X)):
for j in range(len(X)):
assert abs(sum(a * b for a, b in zip(X[i], X[j])) - (i == j)) < 1e-12
# Two equal ports span one direction only, and q p > n stops at n vectors.
G, Cm, B = rc_tree(parent, R, C, [2, 2])
assert len(prima(G, Cm, B, B, 1).X) == 1
G, Cm, B = rc_tree(parent, R, C, [0])
assert len(prima(G, Cm, B, B, 10).X) == 6
def test_full_order_gives_the_same_transfer_function():
rng = random.Random(4)
for _ in range(10):
n = rng.randint(3, 6)
parent = [-1] + [rng.randrange(i) for i in range(1, n)]
G, Cm, B = rc_tree(parent, [rng.randint(1, 9) for _ in range(n)], [rng.randint(1, 9) for _ in range(n)], [0])
model = prima(G, Cm, B, B, n)
for s in (0.1, 1j, 0.3 + 2j, 5.0):
h = transfer(G, Cm, B, B, s)[0][0]
hr = transfer(model.G, model.C, model.B, model.L, s)[0][0]
assert abs(h - hr) <= 1e-9 * abs(h)
def det(A):
try:
M, perm = lu_factor(A)
except ValueError:
return 0.0 # a zero column during elimination: exactly singular
sign = 1
p = list(perm)
for i in range(len(p)):
while p[i] != i:
j = p[i]
p[i], p[j] = p[j], p[i]
sign = -sign
out = sign
for i in range(len(M)):
out *= M[i][i]
return out
def test_poles_in_the_left_half_plane():
rng = random.Random(5)
for trial in range(40):
n = rng.randint(3, 5)
if trial % 2 == 0:
parent = [-1] + [rng.randrange(i) for i in range(1, n)]
G, Cm, B = rc_tree(parent, [rng.randint(1, 9) for _ in range(n)],
[rng.randint(1, 9) for _ in range(n)], [0])
else:
G, Cm, B = rlc_ladder([Fraction(rng.randint(1, 5), 10) for _ in range(n)],
[rng.randint(1, 5) for _ in range(n)],
[Fraction(rng.randint(0, 5), 10) for _ in range(n - 1)],
[rng.randint(1, 5) for _ in range(n - 1)], [0])
q = rng.randint(1, len(G) - 1)
model = prima(G, Cm, B, B, q)
ps = poles(model.G, model.C)
assert len(ps) == len(model.X) # the reduced C is non-singular here
for p in ps:
assert p.real < 0
# p is a root of det(G_r + p C_r), relative to Hadamard's bound on the determinant
k = len(model.G)
M = [[model.G[i][j] + p * model.C[i][j] for j in range(k)] for i in range(k)]
hadamard = 1.0
for i in range(k):
hadamard *= sum((abs(model.G[i][j]) + abs(p) * abs(model.C[i][j])) ** 2 for j in range(k)) ** 0.5
assert abs(det(M)) <= 1e-10 * hadamard
if trial % 2 == 0:
assert abs(p.imag) <= 1e-7 * abs(p) # symmetric RC: real poles
def test_rlc_model_is_positive_real():
rng = random.Random(6)
g = [Fraction(1, 10), Fraction(0), Fraction(0), Fraction(1, 20)]
c = [1, 2, 1, 3]
r = [Fraction(1, 10), Fraction(0), Fraction(1, 5)]
ind = [2, 1, 3]
G, Cm, B = rlc_ladder(g, c, r, ind, [0, 3])
for q in (1, 2, 3):
model = prima(G, Cm, B, B, q)
for _ in range(200):
s = complex(rng.uniform(0.0, 3.0), rng.uniform(-5.0, 5.0))
H = transfer(model.G, model.C, model.B, model.L, s)
# Hermitian part of a 2 x 2 matrix: positive semidefinite
h11 = H[0][0].real
h22 = H[1][1].real
h12 = (H[0][1] + H[1][0].conjugate()) / 2
assert h11 >= -1e-9 and h22 >= -1e-9
assert h11 * h22 - abs(h12) ** 2 >= -1e-9
def test_reduced_g_can_be_singular_for_rlc():
# LC ladder with one conductance: G is invertible, but X^T G X is diag(1/3, 0).
G, Cm, B = rlc_ladder([1, 0, 0], [1, 1, 1], [0, 0], [1, 1], [0])
assert lu_factor([[float(x) for x in row] for row in G])
model = prima(G, Cm, B, B, 2)
s3, s5 = 3 ** -0.5, 5 ** -0.5
assert model.X[0] == pytest.approx([s3, s3, s3, 0, 0], abs=1e-12)
assert model.X[1] == pytest.approx([0, 0, 0, 2 * s5, s5], abs=1e-12)
assert model.G[0][0] == pytest.approx(1 / 3, abs=1e-12)
assert max(abs(model.G[0][1]), abs(model.G[1][0]), abs(model.G[1][1])) < 1e-12
def test_errors():
G, Cm, B = rc_tree([-1], [1], [1], [0])
with pytest.raises(ValueError):
prima(G, Cm, B, B, 0)
with pytest.raises(ValueError):
lu_factor([[0.0, 0.0], [0.0, 1.0]])
History
Moment matching for interconnect started with AWE (Pillage and Rohrer, 1990), which forms the moments directly and can give unstable models. Feldmann and Freund (1995) computed the same Padé model stably with a Lanczos process (PVL), but its models need not be passive. Odabasioglu, Celik and Pileggi presented PRIMA at ICCAD 1997 and in IEEE TCAD in 1998: block Arnoldi with a congruence transform, with a proof that the reduced model is passive.
References
- Altan Odabasioglu, Mustafa Celik and Lawrence T. Pileggi, PRIMA: passive reduced-order interconnect macromodeling algorithm, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 17(8), 645 to 654, 1998, the block Arnoldi algorithm, the congruence transform, the theorem on the matched block moments and the proof of passivity for RLC circuits in modified nodal form
- Altan Odabasioglu, Mustafa Celik and Lawrence T. Pileggi, PRIMA: passive reduced-order interconnect macromodeling algorithm, Proceedings of the IEEE/ACM International Conference on Computer-Aided Design, 58 to 65, 1997, the conference version
- Peter Feldmann and Roland W. Freund, Efficient linear circuit analysis by Padé approximation via the Lanczos process, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 14(5), 639 to 649, 1995, PVL, the Padé model from the Lanczos process, which matches 2q moments but does not keep passivity
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 KQ4G00 Edit this page History Report an error Markdown