Algorithmadvanced
Timing simulation
Also called MOTIS timing simulation, event-driven timing simulation.
Chawla, Gummel and Kozak's fast transistor simulation that updates node voltages one at a time with simple models and events, skipping the full Newton solve.
- Time
- O(s (N + T)) worstO(s N + T) best
- Space
- O(N + T) extra
- Where
- N = the number of circuit nodes; T = the number of transistors; s = the number of time steps
- Model
- Real RAM
- Properties
- deterministicnot exactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- B. R. Chawla, H. K. Gummel, P. Kozak, 1975
Timing simulation computes the node voltages of a large MOS circuit over time, like a circuit simulator, but at a much lower cost per time step. A circuit simulator solves the whole nonlinear system of the circuit at each time point by Newton's method, with a sparse LU factorization at each iteration. MOTIS (Chawla, Gummel and Kozak, 1975) does not. At each time step it visits the nodes one at a time in a fixed order and moves each node voltage by one Newton step on that node's own equation, using the newest voltages of the other nodes. A node whose surroundings did not move is skipped. This page is in the circuit simulation half of logic and circuit simulation, at its fast end: it integrates the node equations of transient circuit analysis with backward Euler, and borrows selective trace from event-driven logic simulation. There is no delay model as on the logic pages. Delays come out of the integration, from the transistor currents and the node capacitances.
In plain words
Picture a chain of logic gates. Each wire between gates holds some charge, and the transistors pour current into it or drain it away. A full circuit simulator works out every wire at once at each tick of the clock, which is accurate but slow.
A timing simulator takes the wires one at a time, from the inputs toward the outputs. For each wire it asks how much current flows in now, and how fast that current would change if the wire's voltage moved. From these two numbers it takes one careful step for the wire, then goes to the next wire, which already sees the new value.
Wires far from any activity hardly move. The simulator notices that and leaves them alone until a neighbour moves again.
The problem
The circuit has nodes. Node has a capacitance to ground, and its current is the sum of the currents flowing into it through the channels of the transistors that touch it. Inputs are voltage sources with given waveforms. The node voltages obey for every , a stiff system of ordinary differential equations. Backward Euler with step asks, at each time point, for the solution of
In the language of companion models, each capacitor becomes a conductance with a current source , and the system is the resistive network of modified nodal analysis with only grounded elements. The transistors follow the square-law Shichman-Hodges model: with overdrive and channel voltage , the current is 0 in cutoff, in the linear region and in saturation. MOTIS itself used tables of the transistor characteristic.
The algorithm
MOTIS(circuit, init, h, t_end, ε)- 1
v ← the initial node voltages and the input voltages at time 0; every node is awake - 2
for t = h, 2h, ..., t_end - 3
set each input to its value at t; wake the nodes that a moved input feeds - 4
for each node i in the fixed order - 5
if i is asleep: skip it, its voltage stays - 6
(I, D) ← the current into i and its derivative in v_i, at the newest voltages - 7
v_i ← v_i + h I / (C_i − h D) - 8
if v_i moved by more than ε: wake i and the nodes it feeds, later in this step and in the next - 9
the awake nodes of the next step are those woken in this step - 10
record the voltages at t - 11
return the waveforms
Line L7 is one Newton step on the backward Euler equation of node alone, started from its old voltage . With , the step is exactly . The nodes that come earlier in the order already have their values at , and the later ones still have their values at . So one time step is one sweep of nonlinear Gauss-Seidel iteration with one Newton step per node.
The order matters. MOTIS orders the nodes from the inputs toward the outputs, so that a gate sees its input voltage at the new time. When the current into each node depends only on its own voltage and on nodes earlier in the order, as in a chain of gates with grounded capacitors, the backward Euler system is lower triangular, and a sweep that solves each node equation exactly gives the backward Euler solution itself.
With every node is updated at every step. With , a node sleeps once its voltage moves by no more than in a step, until a node or input that it reads moves by more than .
Example
A chain of four CMOS inverters with V, threshold 0.5 V, for both transistor types and fF on each output. The input rises from 0 to 1.8 V between 0.10 and 0.15 ns, and ps. When is still at 1.8 V and the input has reached 1.8 V, the n transistor is saturated and the p transistor is off, so A and , and line L7 moves by mV. The waveforms (volts):
| t (ns) | ||||
|---|---|---|---|---|
| 0.10 | 1.800 | 0.000 | 1.800 | 0.000 |
| 0.14 | 1.719 | 0.000 | 1.800 | 0.000 |
| 0.16 | 1.420 | 0.000 | 1.800 | 0.000 |
| 0.18 | 1.084 | 0.002 | 1.800 | 0.000 |
| 0.20 | 0.777 | 0.031 | 1.800 | 0.000 |
| 0.25 | 0.273 | 0.370 | 1.800 | 0.000 |
| 0.30 | 0.082 | 1.007 | 1.769 | 0.000 |
The outputs cross 0.9 V at 0.1916, 0.2920, 0.3944 and 0.4969 ns. A classical Runge-Kutta reference with a step of 0.05 ps gives 0.1921, 0.2926, 0.3952 and 0.4979 ns, so each crossing is within 1 ps, and the largest voltage difference on any node is 13 mV.
Correctness
The proof in proofs/correctness.md shows three facts exactly.
- If no transistor touching node has its gate on node , then for the square-law model. So : the node equation has exactly one solution, and the denominator of line L7 is at least for every step size.
- If the order makes the system lower triangular, a sweep that solves each node equation exactly gives the backward Euler solution, with no further iteration.
- One Newton step from lands within of the exact solution of the node equation (with the other voltages fixed), where is the current at the start of the step and , at most the sum of the of the transistors at the node, bounds how fast can change.
The rest is measured, not proved. The tests compare with a full backward Euler solve with Newton's method on the whole system and with a Runge-Kutta reference at a step 20 times finer:
- The sweep with exact node solves agrees with the full backward Euler Newton solution to V on the inverter chain (the test asks for ).
- One Newton step per node stays within 1.2 mV of full backward Euler at ps.
- Against the reference, the largest error is 13 mV at ps on the chain and 12 mV on a NAND gate whose internal stack node couples both ways, and every 0.9 V crossing is within 1.5 ps (the stated tolerances are 20 mV and 1.5 ps).
- The error falls by factors of 2.08, 1.98, 2.03 and 2.01 as halves from 8 ps to 0.5 ps: first order, as backward Euler is.
Whether the Gauss-Seidel sweep converges, or how large its error is, when nodes couple both ways through floating capacitors or pass transistors, depends on the circuit; MOTIS gives no bound, and iterated timing analysis repeats the sweep until it converges.
Proof: The node equations of backward Euler have unique solutions, a triangular order gives backward Euler in one sweep, and one Newton step is accurate to third order in hpartial
Setting. Node has capacitance and current , the sum over the transistors whose channel touches of the current flowing into . The transistors follow the square-law model of the page with parameter and threshold . Backward Euler with step asks for with for all , where . For fixed values of the other nodes, write for the node equation of . Lines L1 to L11 refer to the pseudocode of the page.
Lemma 1 (the device). For one transistor, the current into a channel terminal is a continuously differentiable function of the terminal voltages. Its derivative in is at most 0, and it is Lipschitz in with constant , as long as the gate of the transistor is not node .
Proof. Take an n transistor; the p case is the same with all voltages negated. Let and , where the source is the lower channel terminal. The current from drain to source is for , for and for . On the boundaries the pieces and their first derivatives agree: at both give , and ; at all are 0. Write and . If is the drain, the current into is and its derivative in is . If is the source, the current into is and its derivative is . At the two roles meet, and both derivatives equal , so the derivative is continuous there. In each region, and are 0, or , and as functions of alone they are piecewise linear with slopes in when is not the gate. A continuous piecewise linear function with slopes of size at most is Lipschitz with constant .
Theorem 1 (one solution per node). If no transistor at node has its gate on , then for all values of the other nodes, , and has exactly one root. The denominator of line L7 is at least .
Proof. , and by Lemma 1, summed over the transistors at . So is continuous and strictly increasing with slope at least . It tends to and at the two ends, so it has exactly one root. .
Theorem 2 (triangular order). Suppose that, in the order of line L4, each depends only on , on the inputs and on nodes earlier in the order, and that Theorem 1 applies to every node. Then the backward Euler system has exactly one solution , and the sweep that solves each node equation exactly, with the newest values of the earlier nodes, returns it.
Proof. Induction along the order. Node 1 depends only on itself and the inputs at , so its equation, alone, has one root, and every solution of the system must take this value. Suppose nodes have the unique values that every solution must take, and that the sweep has computed them. Then the equation of node involves only these values, the inputs and , so it has one root by Theorem 1, every solution takes it, and the sweep computes it.
Theorem 3 (one Newton step). Let Theorem 1 apply to node , fix the other voltages, let , let be the root of , and let be the result of line L7. Let at and let be the sum of over the transistors at node . Then
Proof. , and , so , which is the first bound. By Lemma 1, is Lipschitz with constant . Then
and the integrand is at most in size, so the integral is at most . Dividing by and using the first bound gives the second.
For the example of the page, , fF, ns and A give a bound of about V per node and step.
What is not proved here. Theorem 3 bounds the gap between one Newton step and the exact node solve in one step, with the other voltages fixed. Adding these gaps over the steps, and showing that the backward Euler map does not amplify them, would show that one Newton step per node keeps the first-order accuracy of backward Euler on a triangular circuit; that argument is not given here, and the tests measure it instead (a gap of 1.2 mV to full backward Euler at ps, and error ratios near 2 when halves). For circuits with two-way coupling, the single Gauss-Seidel sweep is not exact even with exact node solves, and its error depends on the circuit; Newton and Sangiovanni-Vincentelli (1984) analyze the convergence of the repeated sweep, which this page cites and does not prove.
Complexity
Each node update reads the transistors at the node, so a sweep costs , and steps cost . No matrix is built or factored. A full circuit simulator pays for a sparse LU factorization at each Newton iteration, which grows faster than linearly in for most circuits, and for several iterations per time point. With event skipping, a sleeping node costs only the test of line L5, so the cost of a quiet step is , and an implementation that keeps the awake nodes in a queue makes it proportional to the activity. On a chain of eight inverters with ps over 1 ns, V cut the node updates from 8000 to 3319, with a largest change of 3.9 mV from the unskipped run. These numbers are measured.
Properties
- No matrix. Each step costs a sweep over the nodes. Memory is linear in the circuit size.
- Implicit per node. The step size is not limited by the stiffness of a single node, since the update is backward Euler for that node.
- First order. The accuracy is that of backward Euler, and the step size must be small against the transition times.
- Order dependent. Feedback and two-way coupling are taken with a delay of one step for the nodes that come later in the order.
- Event driven. Inactive parts of the circuit cost almost nothing, which is where most of the speed on large digital circuits comes from.
Variants and improvements
- Iterated timing analysis. SPLICE repeats the Gauss-Seidel sweep at each time point until the voltages converge, which removes the error from two-way coupling; see iterated timing analysis.
- Waveform relaxation. Solve each subcircuit for a whole time window, then exchange waveforms and repeat. It lets each subcircuit use its own step size.
- Table models. MOTIS and its successors precompute transistor currents in tables to avoid evaluating the model.
- Mixed mode. Simulate parts of the circuit at timing level and the rest at gate level, as in mixed-mode simulation.
- Fast SPICE. Later commercial simulators combine partitioning, table models, event skipping and per-partition time steps on the same ideas.
When to use it
Use timing simulation for large digital MOS circuits where gate-level delays are not accurate enough and a full circuit simulator is too slow: memory arrays, custom datapaths, clock trees, checks of the waveforms and delays of whole blocks. Do not use it where strong two-way coupling decides the behavior, as in sense amplifiers, analog circuits and oscillators of coupled nodes, or where accuracy must be guaranteed; use a full transient circuit simulation there.
Pitfalls
- Too large a skip threshold. A node is put to sleep when it moves slowly, and nothing may wake it again. In the tests, V on the inverter chain froze the first output at 0.46 V after the input ramp ended, and the edge never reached the end of the chain.
- A bad order. If a gate comes before its input node, it sees the input one step late, and with feedback the delay adds up.
- Two-way coupling. Floating capacitors and pass transistors couple nodes in both directions. One sweep does not resolve them, so the waveforms can be wrong by much more than the step error.
- Too large a step. The update is defined for every step size, but backward Euler damps fast edges and shifts delays when is not small against the transition time.
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/timing-simulation/. The authors are listed in prov/F3Y8TC.jsonl.
"""Timing simulation of MOS circuits in the style of MOTIS.
Every circuit node has a capacitance to ground. Transistors follow the
square-law (Shichman-Hodges, level 1) model with no body effect and no
channel-length modulation. The node equations C_i dv_i/dt = I_i(v) are
discretized by backward Euler. Instead of solving the whole nonlinear
system by Newton's method, each time step visits the nodes in a fixed order,
Gauss-Seidel style, and does one Newton step on each node's own equation,
with the newest voltages of the other nodes. Nodes whose neighbours did not
move by more than eps are skipped (event skipping).
Units: volts, nanoseconds, femtofarads and microamperes, which agree:
1 fF * 1 V / 1 ns = 1 uA.
"""
from __future__ import annotations
from typing import Callable, Dict, List, Optional, Sequence, Tuple
class Circuit:
"""Nodes with grounded capacitors, fixed nodes with voltage waveforms, and MOSFETs."""
def __init__(self, vdd: float = 1.8, vt: float = 0.5) -> None:
self.vdd = vdd
self.vt = vt
self.fixed: Dict[str, Callable[[float], float]] = {"vdd": lambda t: vdd, "gnd": lambda t: 0.0}
self.order: List[str] = []
self.cap: Dict[str, float] = {}
self.trans: List[Tuple[str, str, str, str, float]] = [] # (kind, gate, a, b, k)
def add_input(self, name: str, wave: Callable[[float], float]) -> None:
self.fixed[name] = wave
def add_node(self, name: str, cap: float) -> None:
self.order.append(name)
self.cap[name] = cap
def add_transistor(self, kind: str, gate: str, a: str, b: str, k: float) -> None:
if kind not in ("n", "p"):
raise ValueError("a transistor is of type n or p")
self.trans.append((kind, gate, a, b, k))
def at_node(self) -> Dict[str, List[int]]:
"""Transistors whose channel touches each node."""
out: Dict[str, List[int]] = {n: [] for n in self.order}
for i, (kind, g, a, b, k) in enumerate(self.trans):
for n in {a, b}:
if n in out:
out[n].append(i)
return out
def fanout(self) -> Dict[str, List[str]]:
"""For each node or input, the nodes whose current depends on its voltage."""
out: Dict[str, set] = {n: set() for n in list(self.order) + list(self.fixed)}
for kind, g, a, b, k in self.trans:
for n in (a, b):
if n in self.cap:
out[g].add(n)
out[a].add(n)
out[b].add(n)
return {n: sorted(s, key=self.order.index) for n, s in out.items()}
def ramp(t0: float, t1: float, v0: float, v1: float) -> Callable[[float], float]:
"""A piecewise-linear waveform: v0 until t0, a straight line to v1 at t1, then v1."""
def wave(t: float) -> float:
if t <= t0:
return v0
if t >= t1:
return v1
return v0 + (v1 - v0) * (t - t0) / (t1 - t0)
return wave
def mos(kind: str, k: float, vt: float, vg: float, va: float, vb: float) -> Tuple[float, float, float, float]:
"""Channel current from terminal a to terminal b, and its derivatives in va, vb and vg."""
if kind == "n":
if va >= vb:
sign, vd, vs = 1.0, va, vb
else:
sign, vd, vs = -1.0, vb, va
vov, vds = vg - vs - vt, vd - vs
else:
if va >= vb:
sign, vs, vd = 1.0, va, vb
else:
sign, vs, vd = -1.0, vb, va
vov, vds = vs - vg - vt, vs - vd
if vov <= 0.0:
return 0.0, 0.0, 0.0, 0.0
if vds < vov:
cur = k * (vov * vds - 0.5 * vds * vds)
gm, gds = k * vds, k * (vov - vds)
else:
cur = 0.5 * k * vov * vov
gm, gds = k * vov, 0.0
# Derivatives of cur in the gate, the higher and the lower channel terminal.
if kind == "n":
d_g, d_hi, d_lo = gm, gds, -gm - gds
else:
d_g, d_hi, d_lo = -gm, gm + gds, -gds
if sign > 0:
return cur, d_hi, d_lo, d_g
return -cur, -d_lo, -d_hi, -d_g
def node_current(c: Circuit, at: Sequence[int], node: str, v: Dict[str, float]) -> Tuple[float, float]:
"""Current into the node through the channels at it, and its derivative in the node voltage."""
total = deriv = 0.0
for i in at:
kind, g, a, b, k = c.trans[i]
i_ab, d_a, d_b, d_g = mos(kind, k, c.vt, v[g], v[a], v[b])
sign = -1.0 if node == a else 1.0 # current a -> b leaves a and enters b
total += sign * i_ab
deriv += sign * ((d_a if node == a else 0.0) + (d_b if node == b else 0.0) + (d_g if node == g else 0.0))
return total, deriv
def motis(c: Circuit, init: Dict[str, float], t_end: float, h: float, eps: float = 0.0,
exact: bool = False) -> Tuple[List[float], Dict[str, List[float]], int]:
"""Timing simulation. Returns (time points, waveform of every node, node updates).
With exact=True each node equation is solved to convergence instead of one Newton step.
"""
at = c.at_node()
fan = c.fanout()
v = {n: f(0.0) for n, f in c.fixed.items()} # @line L1
v.update({n: init[n] for n in c.order})
active = set(c.order)
times, waves, evals = [0.0], {n: [v[n]] for n in c.order}, 0
steps = int(round(t_end / h))
for s in range(1, steps + 1): # @line L2
t = s * h
for n, f in c.fixed.items(): # @line L3
new = f(t)
if abs(new - v[n]) > eps or eps <= 0.0:
active.update(fan[n])
v[n] = new
woken = set()
for n in c.order: # @line L4
if n not in active and eps > 0.0: # @line L5
continue
evals += 1
old = v[n]
cur, d = node_current(c, at[n], n, v) # @line L6
v[n] = old + h * cur / (c.cap[n] - h * d) # @line L7
if exact:
v[n] = _solve_node(c, at[n], n, v, old, h)
if abs(v[n] - old) > eps: # @line L8
woken.add(n)
woken.update(fan[n])
active.update(fan[n])
active = woken # @line L9
times.append(t) # @line L10
for n in c.order:
waves[n].append(v[n])
return times, waves, evals # @line L11
def _solve_node(c: Circuit, at: Sequence[int], n: str, v: Dict[str, float], old: float, h: float) -> float:
"""Solve C (x - old) / h = I(x) for the voltage x of node n, others fixed.
The left side minus the right side increases in x when the gates at the node are
other nodes, so the root is unique. Newton steps, kept inside a bracket.
"""
def g(x: float) -> Tuple[float, float]:
v[n] = x
cur, d = node_current(c, at, n, v)
return c.cap[n] * (x - old) / h - cur, c.cap[n] / h - d
lo, hi = -10.0 * c.vdd - 10.0, 10.0 * c.vdd + 10.0
x = v[n]
for _ in range(200):
gx, dx = g(x)
if gx > 0:
hi = min(hi, x)
else:
lo = max(lo, x)
step = gx / dx
nxt = x - step
if not lo < nxt < hi:
nxt = 0.5 * (lo + hi)
if abs(nxt - x) < 1e-13:
x = nxt
break
x = nxt
v[n] = x
return x
def crossing(times: Sequence[float], wave: Sequence[float], level: float) -> Optional[float]:
"""First time at which the waveform crosses the level, by linear interpolation."""
for i in range(1, len(wave)):
a, b = wave[i - 1] - level, wave[i] - level
if a == 0.0:
return times[i - 1]
if a * b < 0.0:
return times[i - 1] + (times[i] - times[i - 1]) * a / (a - b)
return None
test_timing_simulation.py 244 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/timing-simulation/. The authors are listed in prov/F3Y8TC.jsonl.
"""Tests for MOTIS-style timing simulation against a fine-step RK4 reference and a full
backward Euler Newton solve."""
import random
from timing_simulation import Circuit, crossing, mos, motis, node_current, ramp
VDD = 1.8
T_END = 1.0 # ns
H = 0.001 # ns, 1 ps
H_REF = 0.00005 # ns, 0.05 ps for the RK4 reference
def chain(stages=4, cap=10.0, k=200.0):
c = Circuit(vdd=VDD)
c.add_input("in", ramp(0.1, 0.15, 0.0, VDD))
prev = "in"
init = {}
for s in range(stages):
y = f"y{s + 1}"
c.add_node(y, cap)
c.add_transistor("p", prev, "vdd", y, k)
c.add_transistor("n", prev, y, "gnd", k)
init[y] = VDD if s % 2 == 0 else 0.0
prev = y
return c, init
def nand_stack():
"""A NAND gate with the internal node m of its n stack, driving an inverter."""
c = Circuit(vdd=VDD)
c.add_input("a", ramp(0.1, 0.15, 0.0, VDD))
c.add_input("b", lambda t: VDD)
c.add_node("out", 10.0)
c.add_node("m", 3.0)
c.add_node("z", 10.0)
c.add_transistor("p", "a", "vdd", "out", 200.0)
c.add_transistor("p", "b", "vdd", "out", 200.0)
c.add_transistor("n", "a", "out", "m", 200.0)
c.add_transistor("n", "b", "m", "gnd", 200.0)
c.add_transistor("p", "out", "vdd", "z", 200.0)
c.add_transistor("n", "out", "z", "gnd", 200.0)
return c, {"out": VDD, "m": 0.0, "z": 0.0}
# ---------------------------------------------------------------- references
def rk4(c, init, t_end, h):
"""Classical Runge-Kutta on C dv/dt = I(v) with a fine step: the reference."""
at = c.at_node()
v = dict(init)
def f(t, vals):
full = {n: w(t) for n, w in c.fixed.items()}
full.update(vals)
return {n: node_current(c, at[n], n, full)[0] / c.cap[n] for n in c.order}
times, waves = [0.0], {n: [v[n]] for n in c.order}
for s in range(int(round(t_end / h))):
t = s * h
k1 = f(t, v)
k2 = f(t + h / 2, {n: v[n] + h / 2 * k1[n] for n in v})
k3 = f(t + h / 2, {n: v[n] + h / 2 * k2[n] for n in v})
k4 = f(t + h, {n: v[n] + h * k3[n] for n in v})
v = {n: v[n] + h / 6 * (k1[n] + 2 * k2[n] + 2 * k3[n] + k4[n]) for n in v}
times.append(t + h)
for n in c.order:
waves[n].append(v[n])
return times, waves
def solve_linear(a, b):
"""Gaussian elimination with partial pivoting."""
n = len(b)
m = [row[:] + [b[i]] for i, row in enumerate(a)]
for col in range(n):
p = max(range(col, n), key=lambda r: abs(m[r][col]))
m[col], m[p] = m[p], m[col]
for r in range(col + 1, n):
f = m[r][col] / m[col][col]
for j in range(col, n + 1):
m[r][j] -= f * m[col][j]
x = [0.0] * n
for r in range(n - 1, -1, -1):
x[r] = (m[r][n] - sum(m[r][j] * x[j] for j in range(r + 1, n))) / m[r][r]
return x
def backward_euler_newton(c, init, t_end, h):
"""Backward Euler with the full nonlinear system solved by Newton's method to 1e-13."""
at = c.at_node()
names = c.order
v = {n: w(0.0) for n, w in c.fixed.items()}
v.update(init)
times, waves = [0.0], {n: [v[n]] for n in names}
for s in range(1, int(round(t_end / h)) + 1):
t = s * h
for n, w in c.fixed.items():
v[n] = w(t)
old = {n: v[n] for n in names}
for _ in range(100):
res, jac = [], []
for n in names:
cur, _ = node_current(c, at[n], n, v)
res.append(c.cap[n] * (v[n] - old[n]) / h - cur)
row = []
for m in names: # derivative of the residual of n in v[m], by central differences
e = 1e-7
keep = v[m]
v[m] = keep + e
cp, _ = node_current(c, at[n], n, v)
v[m] = keep - e
cm, _ = node_current(c, at[n], n, v)
v[m] = keep
row.append((c.cap[n] / h if m == n else 0.0) - (cp - cm) / (2 * e))
jac.append(row)
dx = solve_linear(jac, [-r for r in res])
for n, d in zip(names, dx):
v[n] += d
if max(abs(d) for d in dx) < 1e-13:
break
times.append(t)
for n in names:
waves[n].append(v[n])
return times, waves
def max_error(a, b, stride=1):
"""Largest difference between waveforms a (coarse) and b (fine, stride points per coarse step)."""
return max(abs(x - b[i * stride]) for i, x in enumerate(a))
# ---------------------------------------------------------------- the device model
def test_mos_regions_and_symmetry():
k, vt = 200.0, 0.5
assert mos("n", k, vt, 0.4, 1.0, 0.0)[0] == 0.0 # cutoff
assert abs(mos("n", k, vt, 1.8, 1.8, 0.0)[0] - 0.5 * k * 1.3 ** 2) < 1e-9 # saturation
assert abs(mos("n", k, vt, 1.8, 0.2, 0.0)[0] - k * (1.3 * 0.2 - 0.02)) < 1e-9 # linear
assert abs(mos("p", k, vt, 0.0, 1.8, 0.0)[0] - 0.5 * k * 1.3 ** 2) < 1e-9
rng = random.Random(7)
for _ in range(500):
kind = rng.choice("np")
vg, va, vb = (rng.uniform(-0.2, 2.0) for _ in range(3))
assert abs(mos(kind, k, vt, vg, va, vb)[0] + mos(kind, k, vt, vg, vb, va)[0]) < 1e-12
def test_mos_derivatives():
rng = random.Random(8)
e = 1e-6
for _ in range(500):
kind = rng.choice("np")
vg, va, vb = (rng.uniform(-0.2, 2.0) for _ in range(3))
cur, da, db, dg = mos(kind, 200.0, 0.5, vg, va, vb)
for idx, d in ((1, da), (2, db), (0, dg)):
p = [vg, va, vb]
q = [vg, va, vb]
p[idx] += e
q[idx] -= e
num = (mos(kind, 200.0, 0.5, *p)[0] - mos(kind, 200.0, 0.5, *q)[0]) / (2 * e)
assert abs(num - d) < 1e-3 * (1 + abs(d))
# ---------------------------------------------------------------- the solver
def test_exact_node_solves_equal_full_newton_on_feed_forward_chain():
c, init = chain(4)
h = 0.002
_, w_exact, _ = motis(c, init, T_END, h, exact=True)
_, w_full = backward_euler_newton(c, init, T_END, h)
for n in c.order:
assert max_error(w_exact[n], w_full[n]) < 1e-9
def test_one_newton_step_stays_near_full_backward_euler():
c, init = chain(4)
h = 0.002
_, w_one, _ = motis(c, init, T_END, h)
_, w_full = backward_euler_newton(c, init, T_END, h)
assert max(max_error(w_one[n], w_full[n]) for n in c.order) < 0.005
def test_chain_against_fine_rk4_reference():
c, init = chain(4)
_, w_ref = rk4(c, init, T_END, H_REF)
stride = int(round(H / H_REF))
times, w, _ = motis(c, init, T_END, H)
ref_times = [i * H_REF for i in range(len(w_ref["y1"]))]
for n in c.order:
assert max_error(w[n], w_ref[n], stride) < 0.02 # volts, stated tolerance
t_sim = crossing(times, w[n], VDD / 2)
t_ref = crossing(ref_times, w_ref[n], VDD / 2)
assert abs(t_sim - t_ref) < 0.0015 # 1.5 ps, stated tolerance
assert w["y4"][-1] > VDD - 1e-3 # the edge went through
def test_first_order_error_ratio():
c, init = chain(2)
_, w_ref = rk4(c, init, 0.6, H_REF)
errors = []
for h in (0.004, 0.002, 0.001):
_, w, _ = motis(c, init, 0.6, h)
stride = int(round(h / H_REF))
errors.append(max(max_error(w[n], w_ref[n], stride) for n in c.order))
for e1, e2 in zip(errors, errors[1:]):
assert 1.6 < e1 / e2 < 2.5
def test_event_skipping_saves_work():
c, init = chain(8)
_, w_full, n_full = motis(c, init, T_END, H)
_, w_skip, n_skip = motis(c, init, T_END, H, eps=1e-4)
assert n_skip < 0.5 * n_full
assert max(max_error(w_skip[n], w_full[n]) for n in c.order) < 0.01
def test_bidirectional_stack_against_reference():
c, init = nand_stack()
_, w_ref = rk4(c, init, T_END, H_REF)
stride = int(round(H / H_REF))
_, w, _ = motis(c, init, T_END, H)
for n in c.order:
assert max_error(w[n], w_ref[n], stride) < 0.02
assert w["out"][-1] < 1e-3 and w["z"][-1] > VDD - 1e-3
def test_too_large_skip_threshold_loses_the_edge():
# Once the input ramp ends, nothing wakes y1 again. When its change per step falls
# below 0.01 V, it is put to sleep for good and freezes between the rails.
c, init = chain(8)
_, w, _ = motis(c, init, T_END, H, eps=1e-2)
assert 0.3 < w["y1"][-1] < 0.6
_, good, _ = motis(c, init, T_END, H)
assert good["y1"][-1] < 1e-3
def test_quiet_circuit_is_skipped():
c, init = chain(4)
c.fixed["in"] = lambda t: 0.0
_, w, evals = motis(c, init, T_END, H, eps=1e-6)
assert evals <= 4 * 2 # settles at once
assert all(w[n][-1] == init[n] for n in c.order)
History
Chawla, Gummel and Kozak at Bell Laboratories built MOTIS and described it in 1975, at the Design Automation Conference and in the IEEE Transactions on Circuits and Systems. It brought transistor-level timing to circuits far larger than a circuit simulator of the time could handle. Newton's SPLICE (1979) combined timing and logic simulation with events, and Newton and Sangiovanni-Vincentelli (1984) explained timing simulation as one sweep of a nonlinear relaxation method, which led to iterated timing analysis and waveform relaxation. The fast SPICE simulators of the 1990s and later build on these methods.
References
- 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 node-by-node backward difference update with one Newton step per node, the table models of MOS transistors and the skipping of inactive nodes
- P. Kozak, H. K. Gummel and B. R. Chawla, Operational features of an MOS timing simulator, Proceedings of the 12th Design Automation Conference, 95 to 101, 1975, the use of MOTIS on large MOS circuits
- A. R. Newton and A. L. Sangiovanni-Vincentelli, Relaxation-based electrical simulation, IEEE Transactions on Computer-Aided Design 3(4), 308 to 331, 1984, the analysis of timing simulation as one sweep of nonlinear Gauss-Seidel relaxation, and its relation to iterated timing analysis and waveform relaxation
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 F3Y8TC Edit this page History Report an error Markdown