From Prompt to Protocol: Fast Charging Batteries with Large Language Models
- Python 3.9+
- CUDA (optional, for GPU acceleration)
- Clone the repository:
git clone https://github.com/your-repo/prompt-to-protocol.git
cd prompt-to-protocol- Create a virtual environment:
conda create -n charging python=3.12.3
conda activate charging- Install dependencies:
For Case 1 & Case 2 (Constant / Predefined Heating Optimization):
pip install -r requirements.txtNote: Case 1 & Case 2 require
pybamm==24.1
For Case 3 (Adaptive Charging Optimization):
pip install ax-platform==0.4.0 deap==1.4.1 matplotlib==3.8.2 "numpy<2" openai==1.51.2 optuna==4.0.0 pandas==2.2.3 scipy==1.14.1 termcolor==2.5.0
pip install pybamm==25.1.1Note: Case 3 requires
pybamm==25.1.1due to API changes in PyBaMM
For LLM-based optimization, you need to configure your OpenAI API key:
Option 1: Using a .env file (Recommended)
- Create a
.envfile in the project root:
touch .env- Add your API key to the
.envfile:
export OPENAI_API_KEY="your-api-key-here"
- Load the environment variables before running scripts:
source .envThe scripts/ directory contains self-contained examples that you can run directly:
Test the battery simulation:
python scripts/MWE_simulation.pyRun a complete SAASBO optimization:
python scripts/MWE_optimization.pyThis will:
- Initialize a neural network for charging current control
- Run 30 Sobol initialization trials
- Run 60 batches of SAASBO optimization (3 samples per batch)
- Save results to
./experiments/MWE_results/
prompt-to-protocol/
├── scripts/ # MWE scripts (standalone examples)
│ ├── MWE_optimization.py # Complete optimization example
│ └── MWE_simulation.py # Simulation example
├── src/
│ ├── p2o/ # Prompt-to-Optimizer
│ │ ├── evaluate_model/ # Optimization methods
│ │ │ ├── SAABO_constant_heating.py # Case 2
│ │ │ ├── SAABO_adaptive_RNN.py # Case 3
│ │ │ ├── ECM_gradient_descent.py # Case 1
│ │ │ └── random_constant_heating.py # Case 2
│ │ ├── simulation/ # Battery simulation
│ │ │ ├── sim_p2o_c1_c2.py # Case 1 & 2 simulation
│ │ │ └── sim_p2o_c3.py # Case 3 simulation
│ │ ├── evolution/ # Evolutionary algorithms
│ │ ├── evaluation/ # Evaluation scripts
│ │ └── llm_generation/ # LLM-based generation
│ ├── p2p/ # Prompt-to-Protocol
│ │ ├── simulation/
│ │ ├── evolution/
│ │ └── llm_generation/
│ └── tools/ # Utility functions
├── experiments/ # Experiment results
├── plots/ # Visualization notebooks
├── requirements.txt
└── README.md
See LICENSE for details.