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:
- Importing external simulation scripts from GitHub
- Transforming scripts into standardized
simulate(**params)functions - Executing single and batch simulations with automatic result storage
- Analyzing results using AI-powered reasoning agents
- Managing models, results, and conversations through REST APIs
simexr_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
- Python 3.8+
- Git
- OpenAI API key
# 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.txtCopy the example configuration file and add your OpenAI API key:
cp config.yaml.example config.yamlThen 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.pyThis will automatically:
- Start the API server
- Launch the Streamlit web interface
- Open your browser to http://localhost:8501
Start just the API server for programmatic access:
source simexr_venv/bin/activate
python start_api.py --host 127.0.0.1 --port 8000The server will be available at:
- API: http://127.0.0.1:8000
- Documentation: http://127.0.0.1:8000/docs
Once the Streamlit app is running, you can:
- π₯ Import Models: Use the "Import Models" page to import scripts from GitHub
- βοΈ Run Simulations: Use the "Run Simulations" page to execute simulations
- π View Results: Use the "View Results" page to explore simulation data
- π€ AI Analysis: Use the "AI Analysis" page to ask questions about your results
- π Search Models: Use the "Model Search" page to find existing models
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:
- Dashboard: Overview of system status, recent activity, and quick actions
- Import Models: Import and transform scripts from GitHub URLs
- βRun Simulations: Execute single or batch simulations with custom parameters
- View Results: Explore simulation results with interactive data tables
- AI Analysis: Ask AI-powered questions about your simulation results
- Model Search: Search and browse all available models
- Fuzzy Search: Intelligent model search with relevance scoring
- Interactive Results: View and download simulation results as CSV
- AI Chat: Natural language analysis of simulation data
- βParameter Management: Edit and manage simulation parameters
- Script Editor: View and edit simulation scripts
- Templates: Pre-built parameter templates for common systems
GET /health/status- System health statusPOST /health/test- Run system tests
POST /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 results
POST /reasoning/ask- Ask AI reasoning questionsGET /reasoning/history/{model_id}- Get reasoning historyGET /reasoning/conversations- Get all conversationsGET /reasoning/stats- Get reasoning statistics
GET /database/results- Get simulation resultsGET /database/models- Get database models
We 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- Use appropriate indexes for large datasets
- Implement result pagination for large result sets
- Use vectorized operations in simulation scripts
- Implement parallel processing for batch simulations
- Cache frequently used simulation results
- Implement conversation caching
- Use streaming responses for long analyses
- Optimize prompt engineering for faster responses
- MCP Server Integration: Standard protocol or MCP server for agentic control of scientific experimentation workflow
- Advanced Exploration: Using better techniques for domain specific param space exploration
- Cybershuttle Integration: Imntegration with research jupyter notebooks on cybershuttle
- Plugin System: Extensible architecture for custom features
- Integration APIs: Connect with other scientific tools and platforms
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
For questions and support:
- Create an issue on GitHub
- Check the documentation at
/docs - Review the API documentation at
/docs
SimExR Framework - Empowering scientific simulation with AI reasoning capabilities.