Algorithm Search⌘K

Algorithmadvanced

Effect-cause diagnosis

Also called effect-cause analysis, Abramovici-Breuer diagnosis.

Abramovici and Breuer's diagnosis that reasons back from the observed failing outputs to the lines that could explain them, with no precomputed dictionary.

Time
O((T + K + C T) (L + P)) worst · averageO(T (L + P)) best
Space
O(T L + P) extra
Where
C = the number of candidates simulated; K = the number of distinct failing outputs; L = the number of lines; P = the number of gate input pins; T = the number of tests
Properties
deterministicexactofflineiterative
Origin
Miron Abramovici, Melvin A. Breuer, 1980

Effect-cause diagnosis finds the defect of a failing chip by starting from its effects, the outputs that were wrong on the tester, and reasoning back to the lines that could have caused them. It needs no fault dictionary, the table of all faulty responses that is otherwise built in advance. Abramovici and Breuer (1980) introduced the approach for multiple stuck-at faults. The version on this page is the common single-fault form, close to the method of Waicukauski and Lindbloom (1989). A fault that explains the data must lie in the fan-in cone of every failing output, and it must be excited on every failing test. These two rules cut the 2L single stuck-at faults of a circuit with L lines down to a few candidates, and only those candidates are simulated. The answer is exactly the set of single stuck-at faults that reproduce the observed response, the same set that a full dictionary lookup would return.

In plain words

A chip failed some tests, and we know which outputs were wrong. Instead of trying every possible break, we ask where a break could be. A break can only spoil outputs that it is wired to, so it must sit somewhere upstream of every wrong output. A break also does nothing on a test where the broken wire would have carried the stuck value anyway, so on every failed test the good value of that wire must be the opposite of the stuck value. This leaves a short list of suspects. We then try each suspect on the computer and keep the ones that fail in exactly the way the chip failed.

The problem

The input is a combinational circuit CC with lines ℓ1,…,ℓL\ell_1, \ldots, \ell_L (stems and fan-out branches), tests t0,…,tT−1t_0, \ldots, t_{T-1}, and the output vectors z0,…,zT−1z_0, \ldots, z_{T-1} that a chip gave on them, with at least one test failing. The output is the set of single stuck-at faults ff, from the stuck-at fault model, such that CC with ff gives exactly zjz_j on every tjt_j. With scan design, a sequential circuit is tested as a combinational one, so this covers scan chips too.

The algorithm

  1. EFFECT-CAUSE(C, the tests t_0, ..., t_(T-1), the observed outputs z_0, ..., z_(T-1))
  2. 1for j ← 0 to T − 1 do g_j ← the values of all lines of the good circuit on t_j
  3. 2FAIL ← the tests j whose outputs in g_j differ from z_j; if FAIL is empty, return the empty set
  4. 3S ← all lines
  5. 4for each output o that is wrong on some test of FAIL do
  6. 5S ← S ∩ (the fan-in cone of o)
  7. 6CAND ← the faults "ℓ stuck at 1 − v" for each ℓ in S whose good value is v on every test of FAIL
  8. 7KEPT ← empty; for each fault f in CAND do
  9. 8if C with f gives z_j on every t_j then add f to KEPT
  10. 9return KEPT

Line L1 is one logic simulation of the good circuit per test. Line L2 compares it with the tester data. Lines L3 to L5 keep only the lines that reach every wrong output; a fan-in cone is found by a search backward from the output. Line L6 keeps one fault per surviving line, and only when the line holds the same good value on all failing tests. Lines L7 and L8 are the only fault simulation, one fault at a time on all tests, and they keep a candidate only when its response matches the chip on every test, passing tests included.

Example

Take the circuit of the fault dictionary page: z=a∧bz = a \wedge b and y=b∨cy = b \vee c, where bb has the branches b>zb{>}z and b>yb{>}y, with the tests abc=110,010,100,001abc = 110, 010, 100, 001. The good values are below; each branch has the value of bb.

test aa bb cc zz yy
0: 110 1 1 0 1 1
1: 010 0 1 0 0 1
2: 100 1 0 0 0 0
3: 001 0 0 1 0 1

A chip with yy wrong on tests 0, 1 and 3. Line L2 gives FAIL = {0, 1, 3}, and the only wrong output is yy. Lines L3 to L5 leave the cone of yy: bb, b>yb{>}y, cc, yy. On the failing tests bb and b>yb{>}y take the values 1, 1, 0, and cc takes 0, 0, 1, so line L6 drops them. Only yy holds 1 on all three, so the one candidate is yy/0. Line L8 simulates it, it matches, and the answer is {y/0}\{y/0\}, after one fault simulation instead of 14.

A chip with zz wrong on test 0 only. FAIL = {0} and the wrong output is zz, so S is the cone of zz: aa, bb, b>zb{>}z, zz, all with value 1 on test 0. Line L6 gives four candidates, aa/0, bb/0, b>zb{>}z/0 and zz/0. In line L8, bb/0 also makes yy wrong on tests 0 and 1, which the chip did not show, so it is dropped. The answer is {a/0,b>z/0,z/0}\{a/0, b{>}z/0, z/0\}, three equivalent faults that no test can tell apart, and the same set as the dictionary lookup.

A chip with zz wrong on test 0 and yy wrong on test 3. The cones of zz and yy share bb only, and bb is 1 on test 0 and 0 on test 3, so line L6 gives no candidate and the answer is empty. No single stuck-at fault explains this chip.

On random circuits with fixed seeds, the number of candidates was small. For 10 circuits of 8 inputs and 40 gates with 24 random tests, and 30 random faults per circuit taken as the defect, line L8 simulated 12.1 faults on average, against 260.8 faults in the circuit, and kept 2.45. For 100 gates, 12 inputs and 40 tests it simulated 16.7 against 619.3 and kept 2.51. These are measurements on random netlists, not bounds.

Correctness

The full proof is on the proof page. It rests on two facts about a single stuck-at fault ff on a line ℓ\ell.

  1. Reach. A line whose fan-in cone does not contain ℓ\ell has the same value in the faulty and in the good circuit, on every test. So if ff changes an output, ℓ\ell lies in the fan-in cone of that output.
  2. Excitation. If the good value of ℓ\ell on a test equals the stuck value, the faulty circuit equals the good circuit on that test, so the test passes.

Let ff = "ℓ\ell stuck at vv" reproduce the observed response. Every wrong output is changed by ff, so by fact 1 ℓ\ell survives lines L4 and L5. Every failing test is changed by ff, so by fact 2 the good value of ℓ\ell is 1−v1 - v on each of them; that value is the same on all failing tests, and line L6 makes exactly the fault ff. Line L8 then keeps it. Conversely, line L8 keeps only faults that reproduce the response. So the answer is exactly the set of single stuck-at faults with the observed response.

Proof: Effect-cause diagnosis returns exactly the single stuck-at faults that reproduce the observed responsefull

We use the notation of the page. The circuit CC is combinational, so its lines can be ordered so that each line is a primary input or is computed from lines earlier in the order. A fan-out branch is a line computed from its stem by the identity. The fan-in cone cone(u)\mathrm{cone}(u) of a line uu is the set of lines with a path to uu, uu included. For a fault ff = "ℓ\ell stuck at vv" and a test tt, write g(u)g(u) for the value of line uu in the good circuit on tt and h(u)h(u) for its value in CC with ff on tt. In the faulty circuit h(ℓ)=vh(\ell) = v, and every other line is computed by its gate from the faulty values of its inputs.

Lemma 1 (reach). If ℓ∉cone(u)\ell \notin \mathrm{cone}(u), then h(u)=g(u)h(u) = g(u).

Proof. By induction along the order. Let ℓ∉cone(u)\ell \notin \mathrm{cone}(u). Then u≠ℓu \ne \ell, since u∈cone(u)u \in \mathrm{cone}(u). If uu is a primary input, both circuits give it the value of the test. Otherwise uu is computed by the same gate in both circuits from its inputs u1,…,uru_1, \ldots, u_r, which come earlier in the order. Each cone(ui)\mathrm{cone}(u_i) is a subset of cone(u)\mathrm{cone}(u), so ℓ∉cone(ui)\ell \notin \mathrm{cone}(u_i), and by the induction hypothesis h(ui)=g(ui)h(u_i) = g(u_i). So the gate gives the same value, h(u)=g(u)h(u) = g(u). ■\blacksquare

Lemma 2 (excitation). If g(ℓ)=vg(\ell) = v, then h(u)=g(u)h(u) = g(u) for every line uu.

Proof. By induction along the order. For u=ℓu = \ell, h(ℓ)=v=g(ℓ)h(\ell) = v = g(\ell). For a primary input u≠ℓu \ne \ell both values are the test value. For any other u≠ℓu \ne \ell, the inputs come earlier, have equal values by the induction hypothesis, and the same gate gives the same value. ■\blacksquare

Theorem 1. Let at least one test fail. Then EFFECT-CAUSE returns exactly the set AA of single stuck-at faults ff such that CC with ff gives zjz_j on every test tjt_j.

Proof. Line L8 adds a fault to KEPT only when it gives zjz_j on every tjt_j, so KEPT ⊆A\subseteq A. For the other direction, let ff = "ℓ\ell stuck at vv" be in AA.

It survives lines L3 to L5. Let oo be an output that line L4 visits, so oo is wrong on some failing test tjt_j, that is zj(o)≠gj(o)z_j(o) \ne g_j(o). Since f∈Af \in A, hj(o)=zj(o)≠gj(o)h_j(o) = z_j(o) \ne g_j(o), and by Lemma 1 this forces ℓ∈cone(o)\ell \in \mathrm{cone}(o). So ℓ\ell is in every set intersected in line L5, and ℓ∈S\ell \in S.

Line L6 makes it. Let j∈j \in FAIL. Some output differs between zjz_j and gjg_j, so hj≠gjh_j \ne g_j on that output, and by Lemma 2 gj(ℓ)≠vg_j(\ell) \ne v, that is gj(ℓ)=1−vg_j(\ell) = 1 - v. This holds for every j∈j \in FAIL, so ℓ\ell has the single good value 1−v1 - v on all failing tests, and line L6 puts the fault "ℓ\ell stuck at 1−(1−v)1 - (1 - v)" = ff in CAND.

Line L8 keeps it. Since f∈Af \in A, the test of line L8 succeeds, and ff is added to KEPT.

So A⊆A \subseteq KEPT, and KEPT =A= A. Line L9 returns it. ■\blacksquare

Corollary 1 (same as a full dictionary). If DD is the set of all single stuck-at faults, then AA is the answer of lookup_full of the fault dictionary on the same tests and outputs, by Theorem 1 of that page.

Corollary 2 (the true fault is kept). If the chip behaves like CC with a single stuck-at fault ff and some test fails, then f∈Af \in A, so the answer contains ff.

Remark (no failing test). If no test fails, line L2 returns the empty set. Every fault that no test detects reproduces such a response, so the empty answer means only that there is nothing to diagnose, and Theorem 1 is stated for at least one failing test.

Count of simulations. Line L6 makes at most one fault per line of SS, so line L8 simulates at most ∣S∣≤L|S| \le L faults, at most half of the 2L2L single stuck-at faults. ■\blacksquare

Complexity

Line L1 costs O(T(L+P))O(T (L + P)) for PP gate input pins, and line L2 costs O(TL)O(T L). Each fan-in cone is a backward search in O(L+P)O(L + P), so lines L3 to L5 cost O(K(L+P))O(K (L + P)) for KK distinct wrong outputs. Line L6 costs O(L⋅∣FAIL∣)O(L \cdot |FAIL|). Line L8 costs O(T(L+P))O(T (L + P)) per candidate, so O(CT(L+P))O(C T (L + P)) for CC candidates. Since each line gives at most one candidate, C≤LC \le L, and the worst case is half the cost of simulating all 2L2L faults. In practice the cones of several failing outputs overlap little and C is far smaller than L, as in the measurements above. Space is O(TL)O(T L) for the good values plus O(L+P)O(L + P) for the netlist and one cone.

Properties

  • Exact for single stuck-at faults. The answer equals the brute-force answer that simulates every fault, and the full dictionary answer.
  • No preparation. Nothing is stored between chips, so a changed test set or netlist costs nothing.
  • Cost per chip. Each chip needs its own simulations, so diagnosing many chips of one design can cost more than one dictionary.
  • Not robust as written. If the defect is not a single stuck-at fault, the answer may be empty or wrong.

Variants and improvements

  • Abramovici and Breuer (1980). The original method allows multiple stuck-at faults. It processes the tests one by one and deduces, from the observed output values, the values that internal lines must have had in the chip. Lines whose deduced values show they are fault-free are removed, and the lines that remain are the possible fault sites, with no assumption that only one fault is present.
  • Path tracing. Instead of whole fan-in cones, trace back from each wrong output only through lines whose change could propagate, as in critical path tracing. This gives a smaller S at the same exactness for the single fault model.
  • Scoring instead of exact match. Waicukauski and Lindbloom (1989) score each candidate by how many failing bits it explains and how many it predicts wrongly, and report the best ones. This tolerates defects that behave like a stuck-at fault on some tests only, such as bridges from the bridging fault model.
  • Several defects. Diagnose each wrong output separately, then choose a few candidates that together explain all failing bits, a set cover problem.
  • Faster verification. Simulate the candidates with a bit-parallel simulator such as PPSFP, many tests per word.

When to use it

Use it for large designs, where a fault dictionary of F⋅T⋅OF \cdot T \cdot O bits does not fit, for chips tested with a changing test set, and for failure analysis of a few chips at a time. Use a dictionary instead when the same small design is diagnosed very often and the table fits. Use the scoring variants when the defect may not be a stuck-at fault.

Pitfalls

  • Intersecting cones with several defects. Line L5 keeps only lines in the cone of every wrong output. With two defects, wrong outputs in two separate parts of the circuit leave S empty, and the answer is empty although both defects are visible. When the single fault assumption is in doubt, keep the candidates of each wrong output (the union over L4 to L6 per output) and solve a cover, instead of intersecting.
  • Requiring one good value in line L6. A stuck-at fault fails only when its line holds the opposite value, so line L6 asks for one good value on all failing tests. A transition fault or a bridge fails with different values on different tests, and line L6 drops it. For those models, change line L6 to the excitation rule of that model.
  • Checking the failing tests only in line L8. A candidate that matches the failing tests but fails a test that the chip passed is wrong, like bb/0 in the example. Line L8 must compare all tests.
  • A partial tester log. If the tester stopped after the first failures, the tests after that point have no data. Treating them as passes in line L8 rejects the true fault. Compare only the tests that were recorded.
  • Reading equivalent faults as poor resolution. An answer of several faults may be one class of equivalent faults, which no test can split. Check the fault collapsing classes before adding tests.

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.

effect_cause_diagnosis.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/effect-cause-diagnosis/. The authors are listed in prov/4MRNNQ.jsonl.
"""Effect-cause diagnosis of a single stuck-at fault, with no fault dictionary.

The input is a circuit, the tests applied on the tester and the output vector
the chip gave on each test. The algorithm starts from the effects (the failing
outputs) and reasons back to the causes:

1. simulate the good circuit and find the failing outputs of every test;
2. a fault that explains the data must reach every failing output, so it sits
   in the intersection of the fan-in cones of all failing outputs;
3. it must be excited on every failing test, so its stuck value is the
   complement of the good value of its line, and that good value must be the
   same on all failing tests;
4. simulate only the surviving candidates and keep those whose response equals
   the observed response.

The result is exactly the set of single stuck-at faults whose response equals
the observed one: the set a full-response fault dictionary would return.
Cost: O(T (L + P)) for the good simulation and the cones, plus O(C T (L + P))
to verify C candidates, against O(2L T (L + P)) to simulate every fault.
"""

from __future__ import annotations

from typing import Sequence

from td3net import Circuit, Fault


def fanin_cone(circuit: Circuit, line: int) -> set[int]:
    """All lines with a path to `line`, the line included. O(L + P)."""
    seen = {line}
    stack = [line]
    while stack:
        u = stack.pop()
        for v in circuit.fanin[u]:
            if v not in seen:
                seen.add(v)
                stack.append(v)
    return seen


def diagnose(
    circuit: Circuit,
    tests: Sequence[Sequence[int]],
    responses: Sequence[Sequence[int]],
) -> tuple[list[Fault], int]:
    """Single stuck-at faults that reproduce the observed responses, and the number simulated.

    Precondition: one response (a 0/1 vector over the primary outputs) per test.
    Returns ([], 0) when no test fails: a passing chip gives nothing to explain.
    """
    if len(tests) != len(responses):
        raise ValueError("one response per test")
    good = [circuit.simulate(t) for t in tests]  # @line L1
    failing_outputs = [
        {k for k, o in enumerate(circuit.po) if g[o] != r[k]} for g, r in zip(good, responses)
    ]
    fail = [j for j, d in enumerate(failing_outputs) if d]  # @line L2
    if not fail:
        return [], 0
    suspects = set(range(circuit.n_lines))  # @line L3
    for k in set().union(*(failing_outputs[j] for j in fail)):  # @line L4
        suspects &= fanin_cone(circuit, circuit.po[k])  # @line L5
    candidates: list[Fault] = []
    for line in sorted(suspects):  # @line L6
        values = {good[j][line] for j in fail}
        if len(values) == 1:
            candidates.append((line, 1 - values.pop()))
    kept: list[Fault] = []
    for f in candidates:  # @line L7
        if all(circuit.outputs(t, f) == tuple(r) for t, r in zip(tests, responses)):  # @line L8
            kept.append(f)
    return kept, len(candidates)  # @line L9
td3net.py 166 lines
# SPDX-License-Identifier: MIT
# Shared helper of the td3 eda pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Gate-level combinational circuits with single stuck-at faults (two values).

A circuit is built from named primary inputs, gates in topological order and
named primary outputs. Every place where a fault can sit is a *line*:

- one stem line for each primary input and for each gate output;
- when a net feeds two or more sinks (gate input pins or primary outputs), one
  branch line for each sink. A net with one sink has no branch line.

Lines are numbered 0, 1, ... in topological order, so every line comes after
the lines it reads. A single stuck-at fault is a pair (line, value). Building a
circuit and simulating one vector take O(L + P) time for L lines and P gate
input pins.

This module holds the circuit model and plain simulation of the good circuit
and of one faulty circuit. It holds no diagnosis algorithm.
"""

from __future__ import annotations

import random
from typing import Optional, Sequence

OPS = ("AND", "OR", "NAND", "NOR", "NOT", "BUF", "XOR", "XNOR")

Fault = tuple[int, int]


def eval_gate(op: str, vals: Sequence[int]) -> int:
    """Two-valued output of a gate."""
    if op in ("AND", "NAND"):
        r = int(all(vals))
    elif op in ("OR", "NOR"):
        r = int(any(vals))
    elif op in ("XOR", "XNOR"):
        r = 0
        for v in vals:
            r ^= v
    else:
        r = vals[0]
    return r ^ int(op in ("NAND", "NOR", "XNOR", "NOT"))


class Circuit:
    """A combinational circuit as a DAG of lines (see the module comment)."""

    def __init__(
        self,
        inputs: Sequence[str],
        gates: Sequence[tuple[str, str, Sequence[str]]],
        outputs: Sequence[str],
    ) -> None:
        nets = list(inputs) + [g[0] for g in gates]
        if len(set(nets)) != len(nets):
            raise ValueError("net names must be unique")
        defined = set(inputs)
        sinks: dict[str, list[tuple[str, int, int]]] = {n: [] for n in nets}
        for gi, (name, op, fanin) in enumerate(gates):
            if op not in OPS:
                raise ValueError(f"unknown gate type {op}")
            if (op in ("NOT", "BUF")) != (len(fanin) == 1) or not fanin:
                raise ValueError(f"wrong number of inputs for {name}")
            for pin, src in enumerate(fanin):
                if src not in defined:
                    raise ValueError(f"{src} is used before it is defined")
                sinks[src].append(("gate", gi, pin))
            defined.add(name)
        for k, src in enumerate(outputs):
            if src not in defined:
                raise ValueError(f"unknown output {src}")
            sinks[src].append(("po", k, 0))

        self.name: list[str] = []
        self.kind: list[str] = []
        self.op: list[str] = []
        self.fanin: list[list[int]] = []
        self.index: dict[str, int] = {}
        pin_line: dict[tuple[str, int, int], int] = {}

        def add(name: str, kind: str, op: str, fanin: list[int]) -> int:
            line = len(self.name)
            self.name.append(name)
            self.kind.append(kind)
            self.op.append(op)
            self.fanin.append(fanin)
            self.index[name] = line
            return line

        def add_net(net: str, kind: str, op: str, fanin: list[int]) -> None:
            stem = add(net, kind, op, fanin)
            sk = sinks[net]
            if len(sk) < 2:
                for s in sk:
                    pin_line[s] = stem
                return
            for s in sk:
                if s[0] == "po":
                    label = f"{net}>out{s[1]}"
                else:
                    gname = gates[s[1]][0]
                    same = sum(1 for t in sk if t[0] == "gate" and t[1] == s[1])
                    label = f"{net}>{gname}" + (f".{s[2]}" if same > 1 else "")
                pin_line[s] = add(label, "branch", "BUF", [stem])

        self.pi: list[int] = []
        for net in inputs:
            add_net(net, "pi", "PI", [])
            self.pi.append(self.index[net])
        for gi, (name, op, fanin) in enumerate(gates):
            add_net(name, "gate", op, [pin_line[("gate", gi, p)] for p in range(len(fanin))])
        self.po: list[int] = [pin_line[("po", k, 0)] for k in range(len(outputs))]
        self.n_lines = len(self.name)
        self.fanout: list[list[int]] = [[] for _ in range(self.n_lines)]
        for line in range(self.n_lines):
            for j in self.fanin[line]:
                self.fanout[j].append(line)

    def faults(self) -> list[Fault]:
        """All 2L single stuck-at faults, in line order."""
        return [(line, v) for line in range(self.n_lines) for v in (0, 1)]

    def fault_name(self, fault: Fault) -> str:
        return f"{self.name[fault[0]]}/{fault[1]}"

    def simulate(self, vector: Sequence[int], fault: Optional[Fault] = None) -> list[int]:
        """Values of all lines for one input vector, with an optional stuck-at fault."""
        vals = [0] * self.n_lines
        k = 0
        for line in range(self.n_lines):
            if self.kind[line] == "pi":
                v = vector[k]
                k += 1
            else:
                v = eval_gate(self.op[line], [vals[j] for j in self.fanin[line]])
            if fault is not None and fault[0] == line:
                v = fault[1]
            vals[line] = v
        return vals

    def outputs(self, vector: Sequence[int], fault: Optional[Fault] = None) -> tuple[int, ...]:
        vals = self.simulate(vector, fault)
        return tuple(vals[o] for o in self.po)


def random_circuit(rng: random.Random, n_inputs: int, n_gates: int, max_fanin: int = 3) -> Circuit:
    """A random circuit of AND, OR, NAND, NOR, XOR and NOT gates. Every net with no sink is an output."""
    ops = ("AND", "OR", "NAND", "NOR", "XOR", "NOT")
    inputs = [f"i{k}" for k in range(n_inputs)]
    nets = list(inputs)
    gates: list[tuple[str, str, list[str]]] = []
    for k in range(n_gates):
        op = rng.choice(ops)
        if op == "NOT" or len(nets) < 2:
            op, fanin = "NOT", [rng.choice(nets)]
        else:
            fanin = rng.sample(nets, rng.randint(2, min(max_fanin, len(nets))))
        gates.append((f"g{k}", op, fanin))
        nets.append(f"g{k}")
    used = {src for _, _, fanin in gates for src in fanin}
    outputs = [n for n in nets if n not in used]
    inner = [g[0] for g in gates if g[0] in used]
    if inner and rng.random() < 0.5:
        outputs.append(rng.choice(inner))
    return Circuit(inputs, gates, outputs)
test_effect_cause_diagnosis.py 98 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/effect-cause-diagnosis/. The authors are listed in prov/4MRNNQ.jsonl.

import random

import pytest

from effect_cause_diagnosis import diagnose, fanin_cone
from td3net import Circuit, random_circuit


def page_circuit() -> Circuit:
    return Circuit(["a", "b", "c"], [("z", "AND", ["a", "b"]), ("y", "OR", ["b", "c"])], ["z", "y"])


TESTS = [(1, 1, 0), (0, 1, 0), (1, 0, 0), (0, 0, 1)]


def names(c, faults):
    return sorted(c.fault_name(f) for f in faults)


def brute_force(c, tests, responses):
    """Simulate every single stuck-at fault and keep those that reproduce the responses."""
    want = [tuple(r) for r in responses]
    return [f for f in c.faults() if [c.outputs(t, f) for t in tests] == want]


def test_page_example_y_stuck_at_0():
    c = page_circuit()
    seen = [c.outputs(t, (c.index["y"], 0)) for t in TESTS]
    kept, simulated = diagnose(c, TESTS, seen)
    assert names(c, kept) == ["y/0"]
    assert simulated == 1  # one candidate simulated instead of 14 faults


def test_page_example_z_stuck_at_0():
    c = page_circuit()
    seen = [c.outputs(t, (c.index["z"], 0)) for t in TESTS]
    kept, simulated = diagnose(c, TESTS, seen)
    assert names(c, kept) == ["a/0", "b>z/0", "z/0"]
    assert simulated == 4  # a/0, b/0, b>z/0, z/0; b/0 also fails y and is dropped


def test_cone():
    c = page_circuit()
    assert names(c, [(x, 0) for x in fanin_cone(c, c.index["y"])]) == ["b/0", "b>y/0", "c/0", "y/0"]


def test_edge_cases():
    c = page_circuit()
    good = [c.outputs(t) for t in TESTS]
    assert diagnose(c, TESTS, good) == ([], 0)
    assert diagnose(c, [], []) == ([], 0)
    with pytest.raises(ValueError):
        diagnose(c, TESTS, good[:2])
    # A response no single stuck-at fault gives: z fails on test 0 and y fails on test 3.
    odd = [(0, 1), (0, 1), (0, 0), (0, 0)]
    kept, _ = diagnose(c, TESTS, odd)
    assert kept == [] and brute_force(c, TESTS, odd) == []


def test_against_exhaustive_fault_simulation():
    rng = random.Random(41)
    cases = 0
    for _ in range(50):
        ni = rng.randint(2, 6)
        c = random_circuit(rng, ni, rng.randint(1, 10))
        tests = [tuple(rng.randint(0, 1) for _ in range(ni)) for _ in range(rng.randint(1, 8))]
        good = [c.outputs(t) for t in tests]
        raw = {g: [c.outputs(t, g) for t in tests] for g in c.faults()}
        for f in c.faults():
            seen = raw[f]
            kept, simulated = diagnose(c, tests, seen)
            if seen == good:
                assert (kept, simulated) == ([], 0)
                continue
            assert f in kept  # the true fault is never lost
            assert sorted(kept) == sorted(g for g in c.faults() if raw[g] == seen)
            assert simulated <= 2 * c.n_lines
            cases += 1
    assert cases >= 500


def test_random_responses_against_brute_force():
    # Arbitrary tester data, most of it not produced by any single fault.
    rng = random.Random(42)
    for _ in range(300):
        ni = rng.randint(2, 5)
        c = random_circuit(rng, ni, rng.randint(1, 8))
        tests = [tuple(rng.randint(0, 1) for _ in range(ni)) for _ in range(rng.randint(1, 5))]
        good = [c.outputs(t) for t in tests]
        seen = [tuple(v ^ (rng.random() < 0.2) for v in g) for g in good]
        kept, _ = diagnose(c, tests, seen)
        if seen == good:
            assert kept == []
        else:
            assert sorted(kept) == sorted(brute_force(c, tests, seen))

History

Fault dictionaries came first: simulate every fault ahead of time and look up the chip. Abramovici and Breuer (1980) proposed to work in the other direction, from the effects to the causes, so that no dictionary is needed and multiple faults can be handled. They presented the idea at the 1980 Design Automation Conference and the full method for combinational circuits in IEEE Transactions on Computers the same year, and extended it to sequential circuits in 1982. With scan design and large chips, the practical form became tracing back from the failing outputs and simulating only the candidates, described by Waicukauski and Lindbloom (1989), with a score in place of an exact match.

References

  1. M. Abramovici and M. A. Breuer, Multiple fault diagnosis in combinational circuits based on an effect-cause analysis, IEEE Transactions on Computers C-29(6), 451 to 460, 1980, the effect-cause approach, the deduction of internal values from the observed response and the lines found fault-free
  2. M. Abramovici and M. A. Breuer, Fault diagnosis based on effect-cause analysis, an introduction, Proceedings of the 17th Design Automation Conference, 69 to 76, 1980, the idea of diagnosis without a fault dictionary
  3. J. A. Waicukauski and E. Lindbloom, Failure diagnosis of structured VLSI, IEEE Design and Test of Computers 6(4), 49 to 60, 1989, tracing back from the failing outputs to candidate faults and simulating only the candidates
  4. Miron Abramovici, Melvin A. Breuer and Arthur D. Friedman, Digital Systems Testing and Testable Design, IEEE Press, 1994, the chapter on logic-level diagnosis (effect-cause analysis)

About this page

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

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