A comprehensive toolkit for quantum circuit optimization using large language models (LLMs). This project provides tools for generating quantum circuit datasets and optimizing them using the OpenRouter AI provider.
- Dataset Generation: Create random quantum circuits using Cirq with configurable parameters
- Circuit Simulation: Simulate circuits with optional noise models
- AI-Powered Optimization: Use LLMs (OpenRouter) for circuit optimization via in-context learning
- Unified CLI: Simple command-line interface
- Extensible Architecture: Easy to add new optimization providers and circuit types
quantum-circuit-optimization/
├── src/
│ ├── data_generation/ # Quantum circuit dataset generation
│ │ ├── qc/ # Core quantum computing modules
│ │ └── scripts/ # Data generation scripts
│ └── model_training/ # AI-powered circuit optimization
│ ├── cli/ # Unified command-line interface
│ ├── config.py # Configuration management
│ └── optimizer.py # OpenRouter API integration
├── tests/ # Test suites
├── requirements.txt # Python dependencies
└── README.md # This file
- Python 3.10+
- Virtual environment support (venv, uv, conda, etc.)
-
Clone the repository:
git clone <repository_url> cd quantum-circuit-optimization
-
Create and activate virtual environment:
# Using uv (recommended) .venv/Scripts/python.exe -m uv venv .venv .venv/Scripts/python.exe -m ensurepip .venv/Scripts/python.exe -m pip install uv .venv/Scripts/python.exe -m uv pip install -r requirements.txt # Or using standard venv python -m venv .venv source .venv/bin/activate # Linux/macOS # or .venv\Scripts\activate # Windows pip install -r requirements.txt
Generate quantum circuit datasets for training and testing:
# Generate 100 circuits with default parameters
python src/data_generation/scripts/generate_dataset.py
# Generate custom dataset
python src/data_generation/scripts/generate_dataset.py \
--n_circuits 500 \
--min_gates 2 \
--max_gates 10 \
--n_qubits 3 \
--output_file custom_dataset.jsonl--n_circuits: Number of circuits to generate (default: 100)--min_gates/--max_gates: Gate count range per circuit--n_qubits: Number of qubits (default: 5)--noise_level: Simulation noise level (default: 0.01)
Optimize quantum circuits using OpenRouter AI:
-
Set up API credentials:
# For OpenRouter (default) export OPENROUTER_API_KEY="***" # Or create ~/.api-openrouter file with your key
-
Optimize a circuit:
python -m src.model_training.cli.predict \ --input_circuit "H 0 ; CNOT 0 1 ; H 0"
# Custom examples for in-context learning
python -m src.model_training.cli.predict \
--input_circuit "X 0 ; X 0 ; Y 1" \
--example "H 0 ; CNOT 0 1 ; H 0||CNOT 0 1" \
--example "X 0 ; X 0 ; Y 1||Y 1" \
--timeout 120 \
--verbose
# Override model
python -m src.model_training.cli.predict \
--model "deepseek/deepseek-chat-v3-0324" \
--input_circuit "H 0 ; CNOT 0 1 ; H 0"Create configuration files for model selection:
~/.model-openrouter: Specify OpenRouter model (one line)~/.api-openrouter: OpenRouter API key
Run the test suite to ensure everything works correctly:
# Install test dependencies
pip install -e .[test]
# Run all tests
pytest
# Run specific test suites
pytest src/data_generation/tests/
pytest src/model_training/tests/- Add provider configuration to
src/model_training/config.py - Implement optimization function following the pattern in the existing optimizer
- Add provider to the CLI in
src/model_training/cli/predict.py
- All code follows PEP 8 style guidelines
- Type hints are used throughout the codebase
- Comprehensive error handling and logging
- Extensive test coverage
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
- Support for custom gate sets
- Advanced noise models
- Circuit complexity metrics
- Integration with other quantum frameworks
- Support for additional AI providers (Claude, GPT-4, etc.)
- Automated evaluation metrics
- Reinforcement learning approaches
- Error mitigation strategies
- Batch processing capabilities
- Caching mechanisms
- Async API calls
- Resource optimization
This project is licensed under the MIT-0 License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed information
- Provide sample inputs and expected outputs