A comprehensive framework for importing, executing, and analyzing scientific simulations with AI-powered reasoning capabilities.
SimExR is a FastAPI-based framework that provides a complete pipeline for:
simulate(**params)
functionssimexr_mod/ โโโ api/ # FastAPI application and routers โ โโโ main.py # Main API application โ โโโ dependencies.py # Dependency injection โ โโโ routers/ # API endpoint definitions โ โโโ simulation.py # Simulation execution APIs โ โโโ reasoning.py # AI reasoning APIs โ โโโ database.py # Database read-only APIs โ โโโ health.py # Health check APIs โโโ core/ # Core business logic โ โโโ interfaces.py # Abstract base classes โ โโโ patterns.py # Design patterns implementation โ โโโ services.py # Main service layer โโโ execute/ # Simulation execution engine โ โโโ loader/ # Script loading and transformation โ โโโ run/ # Simulation execution โ โโโ test/ # Code testing and refinement โโโ reasoning/ # AI reasoning engine โ โโโ agent/ # Reasoning agent implementation โ โโโ messages/ # LLM client implementations โ โโโ base.py # Base reasoning classes โโโ db/ # Database layer โ โโโ repositories/ # Data access layer โ โโโ services/ # Database services โ โโโ utils/ # Database utilities โโโ code/ # Code processing utilities โ โโโ refactor/ # Code refactoring โ โโโ extract/ # Metadata extraction โ โโโ utils/ # Code utilities โโโ utils/ # Configuration and utilities
# Clone the repository git clone <repository-url> cd simexr_mod # Create virtual environment python -m venv simexr_venv source simexr_venv/bin/activate # On Windows: simexr_venv\Scripts\activate # Install dependencies pip install -r requirements.txt
Copy the example configuration file and add your OpenAI API key:
cp config.yaml.example config.yaml
Then edit config.yaml
and replace YOUR_OPENAI_API_KEY_HERE
with your actual OpenAI API key from https://platform.openai.com/account/api-keys.
The framework uses SQLite by default. The database will be automatically created at mcp.db
on first run.
Start the complete application with the user-friendly Streamlit interface:
source simexr_venv/bin/activate python start_streamlit.py
This will automatically:
Start just the API server for programmatic access:
source simexr_venv/bin/activate python start_api.py --host 127.0.0.1 --port 8000
The server will be available at:
Once the Streamlit app is running, you can:
Complete workflow: Import GitHub scripts โ Transform with AI โ Run simulations โ Analyze results โ Get AI insights. The system automatically handles script transformation, parameter extraction, and result storage, enabling researchers to go from raw code to AI-powered insights in minutes.
If you prefer to use the API directly:
# Import and transform a simulation curl -X POST "http://127.0.0.1:8000/simulation/transform/github" \ -H "Content-Type: application/json" \ -d '{ "github_url": "https://github.com/vash02/physics-systems-dataset/blob/main/vanderpol.py", "model_name": "vanderpol_transform", "max_smoke_iters": 3 }' # Run simulations curl -X POST "http://127.0.0.1:8000/simulation/run" \ -H "Content-Type: application/json" \ -d '{ "model_id": "vanderpol_transform_eac8429aea8f", "parameters": { "mu": 1.5, "z0": [1.5, 0.5], "eval_time": 25, "t_iteration": 250, "plot": false } }' # Analyze results with AI curl -X POST "http://127.0.0.1:8000/reasoning/ask" \ -H "Content-Type: application/json" \ -d '{ "model_id": "vanderpol_transform_eac8429aea8f", "question": "What is the behavior of the van der Pol oscillator for mu=1.0 and mu=1.5? How do the trajectories differ?", "max_steps": 5 }'
The SimExR framework includes a modern, user-friendly web interface built with Streamlit:
GET /health/status
- System health statusPOST /health/test
- Run system testsPOST /simulation/transform/github
- Import and transform GitHub scriptsPOST /simulation/run
- Run single simulationPOST /simulation/batch
- Run batch simulationsGET /simulation/models
- List all modelsGET /simulation/models/search
- Fuzzy search models by nameGET /simulation/models/{model_id}
- Get model informationGET /simulation/models/{model_id}/results
- Get simulation resultsDELETE /simulation/models/{model_id}/results
- Clear model resultsPOST /reasoning/ask
- Ask AI reasoning questionsGET /reasoning/history/{model_id}
- Get reasoning historyGET /reasoning/conversations
- Get all conversationsGET /reasoning/stats
- Get reasoning statisticsGET /database/results
- Get simulation resultsGET /database/models
- Get database modelsGET /database/stats
- Get database statisticsWe successfully tested the complete workflow from GitHub import to AI analysis:
# Test URL: https://github.com/vash02/physics-systems-dataset/blob/main/vanderpol.py # Result: Successfully imported and transformed into simulate(**params) function # Model ID: vanderpol_transform_eac8429aea8f
# Parameters: mu=1.5, z0=[1.5, 0.5], eval_time=25, t_iteration=250 # Result: Successfully executed with detailed logging # Execution time: ~0.06 seconds # Data points: 250 time steps, 15x15 grid
# Parameter grid: 2 different configurations # Result: Successfully executed with tqdm progress bars # Automatic result saving to database # Execution time: ~0.5 seconds total
# Question: "What is the behavior of the van der Pol oscillator for mu=1.0 and mu=1.5?" # Result: Comprehensive scientific analysis with: # - Common behavior identification # - Parameter-specific differences # - Technical details and insights # Execution time: ~83 seconds
API Endpoint | Status | Response Time | Features |
---|---|---|---|
GET /health/status | โ | <100ms | System health |
POST /simulation/transform/github | โ | ~5s | Import + transform + refine |
POST /simulation/run | โ | ~0.1s | Single simulation + auto-save |
POST /simulation/batch | โ | ~0.5s | Batch simulation + tqdm + auto-save |
GET /simulation/models | โ | <100ms | 50 models listed |
GET /simulation/models/search | โ | <100ms | Fuzzy search with relevance scoring |
GET /simulation/models/{id}/results | โ | <200ms | Results with NaN handling |
POST /reasoning/ask | โ | ~83s | AI analysis with 5 reasoning steps |
GET /reasoning/history/{id} | โ | <100ms | Conversation history |
GET /reasoning/stats | โ | <100ms | 173 conversations, 18 models |
โ
GitHub Integration: Successfully imports and transforms external scripts
โ
Code Refactoring: Converts scripts to standardized simulate(**params)
format
โ
Automatic Result Saving: All simulations automatically saved to database
โ
Enhanced Logging: Detailed execution logs with result previews
โ
tqdm Progress Bars: Visual progress for batch operations
โ
NaN Handling: Proper JSON serialization of scientific data
โ
Fuzzy Search: Intelligent model search with relevance scoring
โ
AI Reasoning: Comprehensive analysis of simulation results
โ
Error Handling: Graceful handling of various error conditions
The framework supports dynamic parameter extraction and validation:
# Example parameter structure for van der Pol oscillator parameters = { "mu": 1.5, # Damping parameter "z0": [1.5, 0.5], # Initial conditions [x0, y0] "eval_time": 25, # Simulation time "t_iteration": 250, # Number of time steps "plot": False # Plotting flag }
curl -X POST "http://127.0.0.1:8000/simulation/batch" \ -H "Content-Type: application/json" \ -d '{ "model_id": "your_model_id", "parameter_grid": [ {"param1": "value1", "param2": "value2"}, {"param1": "value3", "param2": "value4"} ] }'
# Search by partial name curl "http://127.0.0.1:8000/simulation/models/search?name=vanderpol&limit=5" # Search by model type curl "http://127.0.0.1:8000/simulation/models/search?name=lorenz&limit=3"
curl -X POST "http://127.0.0.1:8000/reasoning/ask" \ -H "Content-Type: application/json" \ -d '{ "model_id": "your_model_id", "question": "Analyze the stability of the system and identify bifurcation points", "max_steps": 10 }'
OpenAI API Key Error
# Ensure API key is set in utils/config.yaml # Or set environment variable export OPENAI_API_KEY="your-key-here"
Import Errors
# Ensure virtual environment is activated source simexr_venv/bin/activate # Install missing dependencies pip install -r requirements.txt
Database Connection Issues
# Check database file permissions ls -la mcp.db # Recreate database if corrupted rm mcp.db # Restart server to recreate
Simulation Execution Errors
# Check script syntax python -m py_compile your_script.py # Verify simulate function exists grep -n "def simulate" your_script.py
Enable detailed logging by setting environment variables:
export LOG_LEVEL=DEBUG export SIMEXR_DEBUG=true python start_api.py --host 127.0.0.1 --port 8000
This project is licensed under the MIT License - see the LICENSE file for details.
For questions and support:
/docs
/docs
SimExR Framework - Empowering scientific simulation with AI reasoning capabilities.