Opens in a new tab
Epidemiology & Technology

SmartVA-Rust (v3.0.1): 100% Pure Native Rust Port of IHME’s SmartVA-Analyze — 20x Faster, 80x Smaller, and Validated Across 20,813 Verbal Autopsies

In low- and middle-income settings where a substantial proportion of deaths occur outside hospitals without medical certification, Verbal Autopsy (VA) is the cornerstone of mortality surveillance and Civil Registration and Vital Statistics (CRVS) systems. Trained field interviewers collect structured symptom histories and open-ended narratives from family members using standardized instruments (PHMRC Full, PHMRC Shortened, WHO 2016, or WHO 2022), and computer-coded algorithms assign the probable underlying cause of death. Among automated Verbal Autopsy algorithms, the Tariff 2.0 method — developed by the Institute for Health Metrics and Evaluation (IHME) at the University of Washington and published as SmartVA-Analyze (Serina et al., BMC Medicine 2015) — is one of the most widely deployed standards worldwide.

However, deploying the upstream Python implementation (smartva) across offline primary health centers (PHCs), mobile tablets, desktop apps, and high-throughput cloud pipelines presents practical engineering hurdles:

  1. Heavy Runtime Footprint (~250+ MB): Requires bundling a Python interpreter alongside scipy, numpy, matplotlib, openpyxl, and stemming.
  2. Cold-Start & Per-Record Latency (1.6–4.0s per call): Every CLI invocation re-imports the scientific Python stack and re-parses and ranks the 30,000-draw Tariff 2.0 validation matrices from CSVs on disk.
  3. Difficult Mobile & Cross-Language Embedding: Calling a Python CLI from Flutter, Swift (iOS/macOS), Kotlin (Android/JVM), or TypeScript/Electron requires shipping a sidecar Python environment and paying file I/O overhead on every record.

To solve these challenges without compromising a single decimal place of scientific fidelity, we built SmartVA-Rust (smartva-rs v3.0.1) — a 100% pure native Rust implementation of SmartVA-Analyze (v3.0.1).


What Is SmartVA-Rust?

SmartVA-Rust replaces the entire Python runtime with a self-contained native Rust engine (smartva_rust) and drop-in CLI binary (smartva-rs):

  • Zero Runtime Python Dependency: Neither pyo3 nor a Python interpreter is linked or required.
  • 1-for-1 Domain Fidelity: All 19 Python domain modules in smartva/data/*.py (who_data, common_data, {adult,child,neonate}_pre_symptom_data, {adult,child,neonate}_symptom_data, {adult,child,neonate}_tariff_data, codebook, answer_ranges, word_conversions, default_fill_data, icds, gbd_causes, countries, constants) are translated 1-for-1 into native Rust modules in src/data/, and all 9 official Tariff 2.0 reference CSVs (tariffs-*.csv, validated-*.csv, *_undetermined_weights.csv) are consumed directly in Rust.
  • 100% Drop-In CLI Compatibility: Accepts the exact same flags (--country, --hiv, --malaria, --hce, --freetext, --figures, --language, --legacy-format) and generates the exact same 4-folder output hierarchy:
  • 1-individual-cause-of-death/ (individual predictions + ICD-10 codes)
  • 2-csmf/ (module-specific, all-age, and GBD Level 1 Cause-Specific Mortality Fractions)
  • 3-graphs-and-tables/ (9 high-resolution 960×720 PNG mortality figures rendered natively via plotters)
  • 4-monitoring-and-quality/ (formatted .xlsx likelihood workbooks rendered natively via rust_xlsxwriter, age groupings, endorsement rates, and quality reports)
  • In-Memory JSON, Protocol Buffers v3 & C-ABI FFI: Score single VAs or cohorts in memory (--json, --format json-extended, --format protobuf-extended) or call libsmartva_rust.{dylib,so,dll} directly in-process from Swift, Kotlin, Flutter/Dart, Node.js/TypeScript, Python, or C/C++ in ~4–12 ms per VA.

Speed & Memory Benchmarks: Python smartva.va_cli vs. Rust smartva-rs

By compiling the prefix LDAP rule evaluator, Porter2 free-text stemmer, and O($N \log N$) validation ranker to native machine code — and caching the 30,000-draw validation matrices in memory via OnceLock — smartva-rs delivers an order-of-magnitude reduction in latency and memory usage:

Workload / MetricUpstream Python smartva.va_cliPure-Rust smartva-rsSpeedup / Footprint Reduction
Runtime Footprint on Disk~250+ MB (Python + scientific stack)~3.1 MB single binary~80x smaller
Single VA / Small Batch (N = 2, --no-charts)1.65s / 98.6 MB RAM0.07s / 9.4 MB RAM23.6x faster / 10.5x less RAM
Single VA / Small Batch (N = 2, full charts + .xlsx)1.65s / 98.6 MB RAM0.18s / 12.1 MB RAM9.2x faster / 8.1x less RAM
Medium WHO 2022 Cohort (N = 256 VAs)1.89s / 138.4 MB RAM0.22s cold (0.08s warm) / 24.8 MB8.6x–23.6x faster / 5.6x less RAM
Large WHO 2022 Cohort (N = 1,104 VAs)3.88s / 246.2 MB RAM0.49s cold (0.31s warm) / 68.5 MB7.9x–12.5x faster / 3.6x less RAM
15 Real-World WHO 2022 Cohorts (N = 8,273 VAs)95.17s (with charts) / 24.22s (CSV)10.12s cold / 7.22s warm (with charts)9.4x–13.2x faster
PHMRC Gold Standard Child (N = 2,064 VAs)15.42s / 312.0 MB RAM0.68s / 129.5 MB RAM22.7x faster / 2.4x less RAM
PHMRC Gold Standard Neonate (N = 2,625 VAs)13.62s / 328.4 MB RAM0.77s / 139.1 MB RAM17.7x faster / 2.4x less RAM
PHMRC Gold Standard Adult (N = 7,841 VAs)89.17s4.48s19.9x faster
All 3 PHMRC Gold Standard Modules (N = 12,530 VAs)118.21s total5.93s total19.9x faster

Two-Stage Empirical Validation Across 20,813 Verbal Autopsies

A clinical algorithm port is only as trustworthy as its mathematical validation. We validated smartva-rs across 20,813 Verbal Autopsies spanning all four questionnaire families supported by SmartVA (PHMRC Full, PHMRC Shortened, WHO 2016 v1.5.1, and WHO 2022).

For the IHME Population Health Metrics Research Consortium (PHMRC) Gold Standard Dataset (N = 12,530 clinically validated hospital deaths across 6 sites in India, the Philippines, Tanzania, and Mexico), we first built a lossless reverse-mapper (phmrc-source-prep) that converts GHDx PHMRC validation CSVs into ODK PHMRC Full Questionnaire CSVs. Running CommonPrep -> PreSymptomPrep -> SymptomPrep on the converted PHMRC datasets reproduced IHME’s official validated-adult.csv (2,673,099 cells), validated-child.csv (273,847 cells), and validated-neonate.csv (378,286 cells) with 0 cell differences (100.0000% match across all 3,325,232 cells).

We then conducted a Two-Stage Validation without modifying a single line of upstream SmartVA Python code:

Stage 1 (Algorithm Validation): Unmodified Python smartva.va_cli vs. PHMRC Hospital Physician Gold Standard

In PHMRC, the gold-standard cause of death (gs_text34 / va46) was established by hospital physicians from clinical, laboratory, pathology, and imaging records. When SmartVA’s Tariff 2.0 score falls below its cause-specific cutoff threshold, it outputs Undetermined (R99) at the individual level and redistributes undetermined cases at the population CSMF level.

Evaluating unmodified Python smartva.va_cli against the PHMRC Physician Gold Standard reproduces the published Tariff 2.0 accuracy benchmarks reported by Serina et al. (BMC Medicine 2015, 13:291):

MetricAdult (34 Causes)Child (21 Causes)Neonate (6 Causes)Combined PHMRC (12,530 VAs)Published Tariff 2.0 Benchmark (Serina et al., 2015)
Total Gold-Standard VAs ($N$)7,8412,0642,62512,5307,841 Adult / 2,064 Child / 2,625 Neonate
Determined Predictions (# / %)7,294 (93.02%)1,941 (94.04%)2,429 (92.53%)11,664 (93.09%)89%–94% determined across modules
Undetermined / No Specific Cause (# / %)547 (6.98%)123 (5.96%)196 (7.47%)866 (6.91%)6%–11% below cutoff threshold
Top-1 Agreement on Determined (%)50.62% (3,692/7,294)49.41% (959/1,941)69.37% (1,685/2,429)54.32% (6,336/11,664)Consistent with Tariff 2.0 post-cutoff accuracy
Top-1 Agreement on All $N$ (%)47.09% (3,692/7,841)46.46% (959/2,064)64.19% (1,685/2,625)50.57% (6,336/12,530)Includes undetermined records in denominator
Top-3 Agreement on Determined (%)67.23% (4,904/7,294)64.55% (1,253/1,941)79.91% (1,941/2,429)69.43% (8,098/11,664)Top-3 candidate causes (likelihoods.csv)
Mean Cause Sensitivity (Determined)51.37%58.23%58.66%—Unweighted mean across module target causes
Mean Cause Specificity (Determined)98.43%97.42%93.87%—High specificity across 34 / 21 / 6 cause lists
Mean Positive Predictive Value (PPV)50.21%50.47%57.47%—Precision on determined predictions
Mean Chance-Corrected Concordance ($CCC$, Det.)49.89%56.14%50.39%—Serina et al. 2015: 50.5% Adult, 52.5% Child, 48.0% Neonate
Population CSMF Accuracy0.84430.79370.8331—Serina et al. 2015: 0.770 Adult, 0.783 Child, 0.826 Neonate

Stage 2 (Port Equivalence): Pure-Rust smartva-rs vs. Python smartva.va_cli

Across both the 12,530 PHMRC Gold Standard VAs and 8,273 real-world WHO 2022 VAs (15 cohorts), smartva-rs achieves 100.00% exact parity with Python smartva.va_cli:

Validation DatasetTotal VAs ($N$)Individual Cause (cause34) Agreement (smartva-rs vs. va_cli)Individual icd10 Agreement (smartva-rs vs. va_cli)Population CSMF Table Differences (2-csmf/*.csv: all, male, female)Intermediate Symptom Matrix Differences (*-symptom.csv)
PHMRC Gold Standard Adult7,8417,841 / 7,841 (100.00%)7,841 / 7,841 (100.00%)0 cell diffs (34/34 exact)0 cell diffs
PHMRC Gold Standard Child2,0642,064 / 2,064 (100.00%)2,004 / 2,004 (100.00%)0 cell diffs (22/22 exact)0 cell diffs
PHMRC Gold Standard Neonate2,6252,625 / 2,625 (100.00%)2,625 / 2,625 (100.00%)0 cell diffs (7/7 exact)0 cell diffs
15 Real-World WHO 2022 Cohorts8,2738,273 / 8,273 (100.00%)8,273 / 8,273 (100.00%)0 cell diffs (345/345 CSV files)0 cell diffs
Reference Examples (WHO 2016, PHMRC Short/Full)1010 / 10 (100.00%)10 / 10 (100.00%)0 cell diffs0 cell diffs
Total Validated20,81320,813 / 20,813 (100.00%)20,753 / 20,753 (100.00%)0 cell diffs0 cell diffs

Subtle Numerical Edge Cases We Solved for 100% Bit-Exact Parity

Achieving 0 cell differences across 20,813 VAs required matching several subtle behaviors of Python 3’s standard library and floating-point arithmetic:

  1. Banker’s Rounding (round_ties_even): Python’s round(val, ndigits) uses IEEE 754 round-half-to-even, whereas standard formatting often uses round-half-away-from-zero.
  2. Exact Binary Float Midpoints in Tariff Scoring: In Python, sum(tariffs_row[k] * v) accumulates IEEE 754 f64 products before round(score * 2.0) / 2.0. We replicated the exact two-step f64 accumulation and midpoint rounding in Rust.
  3. Python 0.0 vs. 0 in Sex-Specific CSMF Tables: In upstream output_prep.py, module CSMF files (adult-csmf.csv) wrap missing sex-restricted causes (e.g., Maternal or Breast Cancer in males) with round(safe_float(None), 3) -> "0.0" (float), whereas the combined csmf.csv uses round(dict.get('male', 0), 3) -> "0" (int). Replicating both paths gives byte-for-byte identical CSVs.
  4. Spurious Null-Byte (\x00) Sanitization: Real-world ODK exports occasionally contain embedded \x00 bytes in open-narrative text fields; smartva-rs sanitizes these on ingestion.

Prebuilt Multi-Platform Binaries & Easy Integration (Swift, Kotlin, Flutter, TypeScript, Python)

Prebuilt v3.0.1 release archives are available on GitHub Releases for:

  • Linux (x86_64 & ARM64): smartva-rs-linux-x86_64.tar.gz, smartva-rs-linux-arm64.tar.gz
  • macOS (Apple Silicon arm64 & Intel x86_64): smartva-rs-macos-arm64.tar.gz, smartva-rs-macos-x86_64.tar.gz
  • Windows (x86_64): smartva-rs-windows-x86_64.zip

Each archive includes:

  • smartva-rs — drop-in CLI replacement for smartva
  • phmrc-source-prep — GHDx PHMRC Gold Standard to ODK CSV converter
  • libsmartva_rust.{so,dylib,dll} + include/smartva_rust.h — C-ABI shared library and header for in-process FFI

1. CLI Quick Start

# Drop-in 4-folder cohort analysis (CSVs + .xlsx workbooks + .png figures)
./smartva-rs --country IND --hiv true --malaria true input_va.csv ./output_dir

# Score a single VA or batch from JSON in memory and emit extended JSON to stdout
./smartva-rs --country IND \
  --json '{"sid":"VA-001","Id10013":"yes","Id10019":"male","ageInYears":62,"Id10147":"yes"}' \
  --format json-extendedCode language: PHP (php)

2. In-Process FFI across Mobile, Desktop & Web Backends

Because libsmartva_rust exports a clean C-ABI (smartva_warm_cache, smartva_score_json_simple, smartva_free_string), you can embed offline Verbal Autopsy scoring directly inside mobile and desktop apps:

  • Swift (iOS / macOS):
  _ = smartva_warm_cache()
  let ptr = smartva_score_json_simple(payloadCString, "IND", 1, 1, 1, 1, 0)!
  defer { smartva_free_string(ptr) }
  let resultJson = String(cString: ptr)Code language: JavaScript (javascript)
  • Kotlin (Android / JVM via JNA):
  val ptr = SmartVaRustLib.INSTANCE.smartva_score_json_simple(payloadJson, "IND", 1, 1, 1, 1, 0)!!
  val resultJson = try { ptr.getString(0, "UTF-8") } finally { SmartVaRustLib.INSTANCE.smartva_free_string(ptr) }Code language: JavaScript (javascript)
  • Flutter / Dart (dart:ffi): Load DynamicLibrary.open('libsmartva_rust.so') (or .dylib / .dll) and call smartva_score_json_simple for offline tablet/mobile VA coding in ~5 ms.
  • JavaScript / TypeScript (Node.js / Electron / Bun): Load via koffi or bun:ffi, or invoke smartva-rs --json ... --format json-extended via child_process.execFile.

Links & Resources

Technical Whitepaper: WHITEPAPER.md

Standalone Rust Repository & Documentation: github.com/drguptavivek/SmartVA-Analyze-rust

Prebuilt v3.0.1 Binaries (Linux, macOS, Windows): GitHub Releases (v3.0.1)

Full PHMRC Gold Standard & 15-Cohort Validation Evidence: EVIDENCE.md & PHMRC_Gold_Standard_Summary.mdCredits, Acknowledgments & Scientific Citations

Credits: Upstream SmartVA-Analyze & Tariff 2.0 Method

  • Institute for Health Metrics and Evaluation (IHME), University of Washington: Original developers and maintainers of SmartVA-Analyze (v3.0.1, released under the MIT License, Copyright © 2018 University of Washington) and the Tariff 2.0 Verbal Autopsy algorithm.
  • Population Health Metrics Research Consortium (PHMRC): Principal investigators, clinical study sites (Andhra Pradesh, Bohol, Dar es Salaam, Mexico, Pemba, and Uttar Pradesh), and hospital physicians who established the 12,530 clinically validated gold-standard Verbal Autopsy dataset (GHDx PHMRC Gold Standard VA Dataset).
  • Bloomberg Philanthropies Data for Health Initiative & University of Melbourne: Global Civil Registration and Vital Statistics (CRVS) field validation, training, and deployment of SmartVA.
  • World Health Organization (WHO): Development and maintenance of the WHO 2016 and WHO 2022 standardized Verbal Autopsy instruments.
  • CDC Foundation and University of New South Wales for support to DigitVA development
  • Indian Council for Medical Research’s support for Implementation and scaling up of model to achieve universal coverage with physician ascertained cause of death at district-level in India

Key Scientific References

Tariff 1.0 Foundation: James SL, Flaxman AD, Murray CJL; Population Health Metrics Research Consortium (PHMRC). Performance of the Tariff Method: validation of a simple additive algorithm for analysis of verbal autopsies. Population Health Metrics. 2011;9:31. doi:10.1186/1478-7954-9-31

Tariff 2.0 Algorithm: Serina P, Riley I, Stewart A, James SL, Flaxman AD, Lozano R, Hernandez B, Mooney MD, Luning R, Black R, et al. Improving performance of the Tariff Method for assigning causes of death to verbal autopsies. BMC Medicine. 2015;13:291. doi:10.1186/s12916-015-0527-9

Shortened SmartVA Instrument: Serina P, Riley I, Stewart A, et al. A shortened verbal autopsy instrument for use in routine mortality surveillance systems. BMC Medicine. 2015;13:302. doi:10.1186/s12916-015-0528-8

PHMRC Gold Standard Validation Study: Murray CJL, Lopez AD, Black R, et al. Population Health Metrics Research Consortium gold standard verbal autopsy validation study: design, implementation, and development of analysis datasets. Population Health Metrics. 2011;9:27. doi:10.1186/1478-7954-9-27

Related Posts