More › uncertainty

More

Uncertainty

No two parts are quite the same, and no delay is always as long. Write a value as the spread it is drawn from, and a study says how often each requirement holds: in 98.7 % of runs, not just yes or no. This page shows how, on the resistor divider of examples/divider.

A value that varies#

A distribution goes where a number goes. A constant, a parameter's value, a variable's start, a part's parameter and a thread's period or wcet all take one.

const R1:   float64 = normal(10kΩ, 1%)
const VREF: float64 = uniform(3.27V, 3.33V)
parameter SETTLE { value triangular(2ms, 3ms, 7ms) }
Written What it is
normal(mean, sd) A bell curve. sd is in the mean's unit, or a share of it: 1%.
uniform(low, high) Any value from low to high, each as likely.
triangular(low, mode, high) From low to high, most often near mode.
lognormal(mean, sd) Always above zero, with a long tail to the high side.
exponential(mean) The time between events that come at random.
choice(a, b, c) One of the values listed, each as likely.

Every number of a distribution is in the unit of the first, and nothing is converted. normal(10kΩ, 100Ω) is an error; write normal(10kΩ, 0.1kΩ) or normal(10kΩ, 1%).

A single run reads the mean. archec sim, archec test, the generated code and the Arche app all take R1 as 10 kΩ, as if you had written 10kΩ. A choice is read as its first value. So adding a distribution changes nothing until a study draws it.

How often a requirement holds#

A requirement says the share of runs it needs with holds. Without it, the requirement must hold in every run.

requirement REQ-GAIN "Half the reference" {
  text "The divider shall give half the reference voltage within 2 %."
  holds 98%
}

study yield "How many boards are good" {
  run
  worst-case
  monte-carlo 1000
}

monte-carlo 1000 with run makes 1000 runs. Each run draws every distribution once, then runs the test cases on archec's simulator. worst-case with run also runs them at each corner: every value at its lowest or its highest. A normal value's ends are 3 sd either side of its mean.

$ archec study main.arche yield
study yield — the test cases at 1000 draws and 8 corners, on the simulator (system Board, seed 1)
  what varies
    R1    normal(10kΩ, 0.1kΩ)
    R2    normal(10kΩ, 0.1kΩ)
    VREF  uniform(3.27V, 3.33V)

  ✓ REQ-GAIN Half the reference  needs 98 %
    at the mean  holds (TP-DIV/TC-HALF)
    monte carlo  holds in 99.5 % of runs (995 of 1000), 98.8 % … 99.8 % with 95 % confidence
      run 882 (off by 18.5 %): R1 = 10.2552kΩ, R2 = 9.78053kΩ, VREF = 3.27845V
        again: archec sim main.arche --test TC-HALF --draw yield:882
    worst case   holds at 4 of 8 corners
      corner 5 (off by 50 %): R1 = 10.3kΩ, R2 = 9.7kΩ, VREF = 3.33V

The report has three lines for each requirement. The first is the single run at the means. The second is the share of draws it held in, and the interval the true share is in. The third is the corners. Here nearly every board is good, though the worst case is not: that is the difference between the two.

A requirement is proved when the low end of the interval reaches its holds. It fails when the high end is below it. In between, the runs do not say, and the study tells you to draw more (--runs 10000). The interval is the Wilson interval at 95 %.

archec study records the result, and archec status shows it with the other evidence. Change a distribution and the record is out of date.

$ archec status main.arche
REQ-GAIN   Half the reference
  ✓ study   yield/REQ-GAIN  sim    just now  held in 995 of 1000 runs (99.5 %), 98.8 % … 99.8 % with 95 % confidence; needs 98 %; held at 4 of 8 corners

Running one draw again#

Each run draws from the study's seed and its own number, so the same study gives the same runs every time. The report names the runs that failed, the furthest from holding first, with the values they drew. --draw runs one of them alone, where the trace and archec why can explain it.

$ archec sim main.arche --test TC-HALF --draw yield:882
run 882 of study yield: R1 = 10.2552kΩ, R2 = 9.78053kΩ, VREF = 3.27845V
  ✗ TP-DIV TC-HALF Half the reference, within 2 %
      at 10.000 ms: abs(div.error) < 0.02 — not so (div.error = -0.0236904)

--draw yield:c5 runs corner 5. seed 7 in the study, or --seed 7, gives other draws.

Tolerances and distributions#

A parameter's tolerance is the older way to say that a value varies. It says the same thing as a distribution, and a study reads both as one list.

Written Monte Carlo draws Worst case takes
value 12; tolerance 5% uniform in 11.4 … 12.6 11.4 and 12.6
value 12; tolerance 5%; distribution normal normal, the band at 3 sd 11.4 and 12.6
value normal(12, 0.2) normal, sd 0.2 11.4 and 12.6
value uniform(11.4, 12.6) uniform 11.4 and 12.6

Write one or the other on a parameter, not both. Without run, a study reads its output formulas as the Arche app computes them, and gives each output's range or its mean and percentiles. With run, it simulates the test cases.

Physical networks#

A part's parameter in a physical network takes a distribution too. A single archec physics run reads its mean, and a batch draws it for each run.

$ archec physics main.arche Drive --for 3s --batch 200 --print load.w
                       mean        min        max          σ
  DcMotor.r         1.00366   0.879821    1.12981  0.0452255  (varied)
  load.w            1.19308    1.05962    1.35389  0.0531668

Limits#

  • A distribution's arguments are numbers. A constant's name is not read there.
  • Two parts made from one component share the draw of a parameter's default. Give each part its own argument for draws of their own.
  • A study with run uses archec's simulator alone. Test cases that need a plant, an FMU or the Arche app's simulator are not drawn.
  • Python bodies read the constants at their mean. Only what the action language says follows a draw.
  • lognormal and exponential have no highest value, so a worst case keeps them at their mean and says so.
  • A worst case runs 4096 corners at most, which is 12 values. Name the ones to take to their ends: worst-case R1, R2.
  • The formulas' Monte Carlo, without run, draws normal and uniform parameters only.
  • The values of a failing run are printed, and --json lists the five furthest runs of each requirement, not every run.
  • The Arche app shows a study at the mean values. It does not draw.