Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

DuckDB Simulation Engine

ERAD includes a high-performance simulation engine powered by DuckDB for million+ asset scale simulations.

Overview

The DuckDB engine replaces the Python loop-based approach with vectorized SQL computation:

FeatureLegacy EngineDuckDB Engine
Asset scale~10K1M+
ParallelismNone (single-threaded)All CPU cores
StorageIn-memory Pydantic objectsColumnar DuckDB tables
ExportSQLite (row-by-row ORM)Parquet, SQLite, CSV, Arrow

The engine is the default for HazardSimulator.run(). Use engine='legacy' to fall back.

Quick Start

Direct Engine Usage (Scale Path)

For 100K+ assets, bypass Pydantic objects entirely and load data from arrays:

Conversion Utilities

Convert between Pydantic models and DuckDB engine in either direction:

CLI Commands

The erad engine CLI provides command-line access to the DuckDB engine:

# Run simulation and export to Parquet
erad engine run <model_name> <hazard_name> -o results.parquet -f parquet

# Convert between formats
erad engine convert results.parquet results.db
erad engine convert results.db results.csv

# Query results with SQL
erad engine query results.parquet --sql "SELECT * FROM asset_states WHERE survival_probability < 0.5"

# Show summary statistics
erad engine info results.parquet

Export Formats

FormatMethodBest For
Parquetengine.export_to_parquet(path)Long-term storage, analytics (columnar, compressed)
SQLiteengine.export_to_sqlite(path)Compatibility with legacy ERAD, simple queries
CSVengine.export_to_csv(path)Sharing with non-Python tools
Arrowengine.export_to_arrow()Zero-copy interop with pandas/polars
DataFrameengine.export_to_dataframe()Interactive analysis in notebooks

Custom SQL Queries

Access the underlying DuckDB connection for custom analytics: