Skip to main content

Overview

Veydra’s simulation engine provides powerful, real-time model execution capabilities built on modern web technologies. Run complex system dynamics models directly in your browser with instant feedback and interactive parameter adjustment.

Core Technology

Pyodide Integration

Veydra uses Pyodide to run Python models directly in the browser:
  • WebAssembly Performance: Near-native execution speed
  • Full Python Support: Complete scientific Python stack
  • Browser-Based: No server dependencies for model execution
  • Real-time Processing: Instant parameter updates

Simulation Features

Real-time Execution

Instant model runs with parameter changes

Multi-Stock Support

Handle complex models with multiple stocks

Scenario Comparison

Baseline vs current scenario analysis

Data Export

Export results in multiple formats

Execution Workflow

Model Processing

1

Model Loading

  1. Load Python model code from project
  2. Initialize Pyodide environment
  3. Load model-specific configuration
  4. Prepare simulation namespace
2

Parameter Setup

  1. Apply current parameter values
  2. Configure simulation time range
  3. Set baseline vs scenario mode
  4. Initialize data structures
3

Execution

  1. Run Python model function
  2. Capture stock and flow values
  3. Process time series data
  4. Generate visualization data
4

Visualization

  1. Update chart displays
  2. Refresh stock-flow diagram
  3. Update data tables
  4. Enable export options

Parameter Management

Active Parameters

Parameters marked as “Active” enable real-time simulation updates:
# Example parameter configuration
active_parameters = {
    'growth_rate': {
        'value': 0.05,
        'min': 0.0,
        'max': 0.2,
        'step': 0.01
    },
    'capacity_limit': {
        'value': 1000,
        'min': 100,
        'max': 5000,
        'step': 100
    }
}

Parameter Types

Support for integers, floats, and scientific notation with configurable ranges and step sizes
Toggle switches for on/off model features and conditional logic
Text inputs for model configuration and scenario naming

Simulation Modes

Baseline Mode

Run models with default parameters to establish baseline behavior:
  • Default Values: Uses original model parameters
  • Reference Point: Basis for scenario comparison
  • Reproducible: Consistent results for comparison
  • Benchmarking: Standard for model validation

Scenario Mode

Test different parameter combinations to explore “what-if” scenarios:
  • Interactive Parameters: Real-time slider adjustments
  • Multiple Scenarios: Save and compare different configurations
  • Sensitivity Analysis: Understand parameter impact
  • Optimization: Find optimal parameter combinations

Comparison Mode

Side-by-side analysis of baseline vs scenario results:

Visual Comparison

Overlay baseline and scenario charts

Difference Analysis

Calculate and display differences

Percentage Changes

Show relative changes from baseline

Statistical Summary

Key metrics and summary statistics

Data Processing

Time Series Handling

Veydra automatically processes simulation results into time series data:
  • Automatic Indexing: Time-based data organization
  • Interpolation: Smooth data visualization
  • Aggregation: Multiple time scale support
  • Filtering: Data cleaning and validation

Output Configuration

Model outputs are configured via outputs.json files:
{
  "stocks": [
    {
      "name": "population",
      "display_name": "Population",
      "units": "individuals",
      "color": "#2E8B57"
    }
  ],
  "flows": [
    {
      "name": "birth_rate", 
      "display_name": "Birth Rate",
      "units": "births/year",
      "color": "#4169E1"
    }
  ]
}

Performance Optimization

Caching Strategy

  • Model Caching: Store compiled models for faster execution
  • Parameter Caching: Remember recent parameter sets
  • Result Caching: Cache simulation outputs
  • File Caching: Local storage for model files

Memory Management

  • Efficient Data Structures: Optimized for large datasets
  • Garbage Collection: Automatic memory cleanup
  • Incremental Updates: Only process changed data
  • Resource Monitoring: Track memory usage
Large models with many parameters may require longer initial load times but will run smoothly once cached

Error Handling

Graceful Failures

The simulation engine includes robust error handling:
Python syntax errors in model code are caught and displayed with helpful debugging information
Execution errors during simulation show specific error messages and line numbers
Invalid parameter values or data format issues are automatically detected and reported
Automatic fallback to last known good state when errors occur

Advanced Features

Custom Model Functions

Write sophisticated Python models with full library support:
import numpy as np
import pandas as pd

def complex_model(params, time_range):
    # Complex calculations with scientific libraries
    data = np.array(time_range)
    results = pd.DataFrame()
    
    # Your model logic here
    
    return results.to_dict('records')

Multi-Stock Analysis

Handle models with multiple interacting stocks:
  • Cross-stock Dependencies: Model interactions between stocks
  • Synchronized Updates: Consistent time-step processing
  • Relationship Mapping: Track dependencies and influences
  • Aggregate Views: Summary statistics across all stocks

Debugging Tools

Execution Monitoring

  • Real-time Logs: View Python execution output
  • Performance Metrics: Track execution time and memory
  • Parameter Tracking: Monitor parameter changes
  • Error Reporting: Detailed error messages and stack traces

Model Validation

  • Syntax Checking: Pre-execution code validation
  • Parameter Validation: Check ranges and types
  • Output Verification: Ensure proper data formats
  • Consistency Checks: Verify model logic
Use the browser’s developer console to see detailed execution logs and debug model issues

Next Steps

I