A small, reproducible CLI for a one-dimensional dimensional tolerance chain. It connects a mechanical clearance problem to deterministic bounds, statistical estimates, a simulation, and a cautious engineering decision.
The example estimates axial clearance between a housing span and a bearing plus spacer:
clearance = housing span − bearing width − spacer thickness
Positive clearance means axial separation. The example dimensions (35.00 ± 0.08 mm, 10.00 ± 0.02 mm, and 24.90 ± 0.03 mm) and functional limits [0.00, 0.20] mm are hypothetical engineering inputs, not values taken from a manufacturer's drawing or a standard. They are intended to make the model inspectable, not to represent a released design.
Input is a four-column CSV: component name, nominal dimension in millimeters, non-negative
bilateral tolerance in millimeters, and direction (+1 or -1). See
examples/axial_clearance.csv.
- Worst-case: signed nominal sum and arithmetic sum of tolerance magnitudes. Returns the guaranteed interval only for the stated one-dimensional model and correctly bounded dimensions.
- RSS: square root of the sum of squared bilateral tolerances. This is a statistical estimate under independent, centered contributions; it is not a worst-case limit.
- Monte Carlo: independent normal dimensions centered on each nominal, with each stated
bilateral tolerance interpreted as ±3σ. The distributions are not truncated, so sampled values
can exceed the stated component tolerances. The default is 100,000 samples and seed
20260925. - Cp/Cpk: conventional formulas using the sample standard deviation (
ddof=1) and the simulated mean. They describe the simulated model only. A real capability study also needs representative production measurements, a stable process, appropriate distribution assumptions, and a capable measurement system. If the sample standard deviation is zero, both indices are reported as undefined.
Generated by running the command below with the checked-in CSV, 100,000 samples, and seed
20260925:
Nominal result: 0.100000 mm
Worst-case: [-0.030000, 0.230000] mm
RSS tolerance: ±0.087750 mm
Monte Carlo: mean=0.099984 mm, s=0.029320 mm
In spec: 99.9450% | out: 0.0550%
Cp=1.1369 | Cpk=1.1367
This observed simulation has 55 out-of-spec samples. Its near-centered output does not remove the worst-case overlap with the [0.00, 0.20] mm limits. The calculation therefore identifies a design question: either revisit the tolerance allocation or validate the model and assumptions against engineering requirements and production data. The percentage, Cp and Cpk are synthetic outputs, not evidence that any manufacturing process is capable.
Machine-readable results are in reports/results.json; the generated
engineering summary is reports/report.md. The JSON records Python, NumPy,
and Matplotlib versions alongside the sample count and seed so the numerical environment is visible.
Python 3.10 or newer is required. NumPy and Matplotlib provide sampling and plotting; the remaining runtime logic uses the standard library.
python -m venv .venv
. .venv/bin/activate
python -m pip install -e '.[dev]'
tolerance-stackup examples/axial_clearance.csv --lsl 0 --usl 0.20 \
--case-description "Hypothetical axial clearance: housing span minus bearing width and spacer thickness." \
--result-name "Axial clearance"By default the command writes reports/results.json, reports/report.md, and
plots/stackup_distribution.png in the current directory. For other stacks, set an accurate
--case-description and --result-name; otherwise the report uses generic labels. Choose a
different sample count, seed, or output directory with --samples, --seed, and --output.
ruff check .
pytestTests include hand-checkable nominal, signed worst-case and RSS calculations, CSV validation, specification validation, reproducible simulation, and known Cp/Cpk values. GitHub Actions runs lint and tests on Python 3.10 and 3.12.
- This is an educational portfolio tool for a simple one-dimensional rigid stack.
- Dimensional contributors are assumed independent; common suppliers, lots, temperature shifts, assembly effects, and measurement correlations are not modeled.
- The ±3σ relationship and normal distributions are assumptions, not consequences of a drawing tolerance. RSS and Monte Carlo outputs depend on them.
- Worst-case checks the arithmetic limits of the specified stack, but does not validate geometry, datum strategy, form tolerances, metrology, or design requirements.
- This tool does not replace metrological validation, design review, or a process capability study based on real and representative manufacturing data. Simulated Cp/Cpk do not certify a process.
Tolerance stack-up · mechanical engineering · industrial engineering · statistical analysis · Monte Carlo simulation · process capability · Python · automated testing · reproducibility · engineering decision support.
Released under the MIT License. The project contains original code and uses NumPy, Matplotlib, pytest, and Ruff through their normal package installation mechanisms; no third-party source code is vendored.
