Parallel Execution Recommender
Parallel Execution Recommender analyzes Python code to identify sequential operations that could be parallelized for better performance. It uses an AI model to detect opportunities for multiprocessing or threading and suggests rewrites to improve runtime efficiency, making it particularly useful for computationally intensive applications.
Installation
- Python 3.7+
openaipytest
Usage
Run the tool from the command line:
python parallel_execution_recommender.py --script <path_to_python_script> --api-key <your_openai_api_key>--script: Path to the Python script you want to analyze.--api-key: Your OpenAI API key.
Source Code
import argparse
import openai
import os
def analyze_code_for_parallelization(script_path, api_key):
"""
Analyze Python code to identify sequential operations that could be parallelized.
Args:
script_path (str): Path to the Python script to analyze.
api_key (str): OpenAI API key.
Returns:
str: Recommendations for parallelization.
"""
if not os.path.exists(script_path):
raise FileNotFoundError(f"The file {script_path} does not exist.")
with open(script_path, 'r') as file:
code_content = file.read()
try:
openai.api_key = api_key
response = openai.Completion.create(
engine="text-davinci-003",
prompt=f"Analyze the following Python code and suggest opportunities for parallelization using multiprocessing or threading. Highlight potential risks like race conditions.\n\n{code_content}",
max_tokens=1000
)
if 'choices' in response and len(response['choices']) > 0:
return response['choices'][0]['text'].strip()
else:
raise RuntimeError("Unexpected response format from OpenAI API.")
except openai.error.OpenAIError as e:
raise RuntimeError(f"Error communicating with OpenAI API: {e}")
def main():
parser = argparse.ArgumentParser(description="Parallel Execution Recommender: Analyze Python code for parallelization opportunities.")
parser.add_argument('--script', required=True, help="Path to the Python script to analyze.")
parser.add_argument('--api-key', required=True, help="OpenAI API key.")
args = parser.parse_args()
try:
recommendations = analyze_code_for_parallelization(args.script, args.api_key)
print("Recommendations for parallelization:")
print(recommendations)
except FileNotFoundError as e:
print(f"Error: {e}")
except RuntimeError as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()
README
Parallel Execution Recommender
Parallel Execution Recommender analyzes Python code to identify sequential operations that could be parallelized for better performance. It uses OpenAI's API to detect opportunities for multiprocessing or threading and suggests rewrites to improve runtime efficiency.
Installation
1. Clone this repository.
2. Install the required dependencies:
pip install -r requirements.txtUsage
Run the tool from the command line:
python parallel_execution_recommender.py --script <path_to_python_script> --api-key <your_openai_api_key>--script: Path to the Python script you want to analyze.--api-key: Your OpenAI API key.
Testing
To run the tests, install pytest if you haven't already:
pip install pytestThen run:
pytest test_parallel_execution_recommender.pyAll tests should pass without requiring network access, as external API calls are mocked.
Requirements
- Python 3.7+
openaipytest
License
This project is licensed under the MIT License.
Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- parallel_execution_recommender
- Category
- AI-Powered Code Optimization
- Generated
- June 11, 2026
- Tests
- Passing โ
- Fix Loops
- 4
Quick Install
Clone just this tool:
git clone --depth 1 --filter=blob:none --sparse \ https://github.com/ptulin/autoaiforge.git cd autoaiforge git sparse-checkout set generated_tools/2026-06-11/parallel_execution_recommender cd generated_tools/2026-06-11/parallel_execution_recommender pip install -r requirements.txt 2>/dev/null || true python parallel_execution_recommender.py