Skip to content

Quantum Circuit Synthesis using Diffusion Model

Notifications You must be signed in to change notification settings

hmisra/QCSynthesis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quantum Circuit Synthesis with Diffusion Models

This repository contains code for synthesizing quantum circuits using diffusion models, based on the work presented in Quantum circuit synthesis with diffusion models by Florian Fürrutter, Gorka Muñoz-Gil & Hans J. Briegel.

Overview

The code provides functionality to:

  • Synthesize quantum circuits corresponding to a given unitary matrix using a diffusion model
  • Evaluate circuit accuracy through unitary infidelity metrics
  • Filter and select better quantum circuits
  • Sample circuits using noise models

Installation

  1. Clone this repository:
git clone https://github.com/yourusername/qc_synthesis.git
cd qc_synthesis
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install core dependencies:
pip install -r requirements.txt
  1. Install CUDA Quantum (cudaq): CUDA Quantum is NVIDIA's quantum computing SDK. Follow the official installation guide for your platform.

For example, on Ubuntu:

# Add NVIDIA repository
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"

# Install CUDA Quantum
sudo apt-get update
sudo apt-get install -y cuda-quantum
  1. Install genQC: genQC is the quantum circuit synthesis package from the paper's authors. Install it from their repository:
pip install git+https://github.com/Floki00/genQC.git@main#egg=genQC

Note: If the above URL is not correct (as it's a placeholder), please refer to the paper or contact the authors for the correct repository location.

Usage

Here's a basic example of synthesizing a quantum circuit:

import numpy as np
from qc_synthesis.pipeline import DiffusionPipeline
from qc_synthesis.utils import get_unitary, infidelity

# Define target unitary
U = np.array([
    [ 0.70710678,  0.        ,  0.        , 0.        ,  0.70710678,  0.        , 0.        ,  0.        ],
    [ 0.        , -0.70710678,  0.        , 0.        ,  0.        , -0.70710678, 0.        ,  0.        ],
    [-0.70710678,  0.        ,  0.        , 0.        ,  0.70710678,  0.        , 0.        ,  0.        ],
    [ 0.        ,  0.70710678,  0.        , 0.        ,  0.        , -0.70710678, 0.        ,  0.        ],
    [ 0.        ,  0.        ,  0.70710678, 0.        ,  0.        ,  0.        , 0.        ,  0.70710678],
    [ 0.        ,  0.        ,  0.        , 0.70710678,  0.        ,  0.        , 0.70710678,  0.        ],
    [ 0.        ,  0.        , -0.70710678, 0.        ,  0.        ,  0.        , 0.        ,  0.70710678],
    [ 0.        ,  0.        ,  0.        ,-0.70710678,  0.        ,  0.        , 0.70710678,  0.        ]
])

# Initialize pipeline
pipeline = DiffusionPipeline.from_pretrained("Floki00/qc_unitary_3qubit")

# Generate circuits
circuits = pipeline.generate_circuits(U, num_samples=128)

# Evaluate circuits
best_circuit = circuits.get_best_circuit()
print(f"Best circuit infidelity: {best_circuit.get_infidelity()}")
print(best_circuit.draw())

Project Structure

qc_synthesis/
├── src/
│   └── qc_synthesis/
│       ├── models/          # Neural network models
│       ├── pipeline/        # Circuit generation pipeline
│       └── utils/           # Utility functions
├── tests/                   # Unit tests
├── docs/                    # Documentation
├── requirements.txt         # Project dependencies
└── README.md               # This file

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use this code in your research, please cite:

@article{furrutter2024quantum,
  title={Quantum circuit synthesis with diffusion models},
  author={F{\"u}rrutter, Florian and Mu{\~n}oz-Gil, Gorka and Briegel, Hans J},
  journal={Nature Machine Intelligence},
  volume={6},
  pages={515--524},
  year={2024}
}

Troubleshooting

Common Issues

  1. CUDA Quantum Installation

    • Make sure you have NVIDIA drivers installed
    • Check CUDA compatibility with your GPU
    • Try running nvidia-smi to verify GPU access
  2. genQC Installation

    • If you encounter issues with the git installation, try downloading the source and installing locally:
      git clone https://github.com/Floki00/genQC.git
      cd genQC
      pip install -e .
    • Make sure you have all genQC dependencies installed
  3. GPU Issues

    • The diffusion model requires GPU access for efficient operation
    • If no GPU is available, the code will fall back to CPU but will be much slower
    • Check GPU memory usage with nvidia-smi if you encounter out-of-memory errors

About

Quantum Circuit Synthesis using Diffusion Model

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages