Generating quantum circuits with diffusion models
Project description
genQC · Generative Quantum Circuits
Code repository for generating quantum circuits with diffusion models. [Arxiv] [Demo]
The codebase
The code contained within this repo allows the sampling of pre-trained diffusion models and includes our pipeline to fine-tune and train models from scratch. Pre-trained weights can be found on Hugging Face and can be downloaded automatically via our code (see minimal example). For the CLIP model weights we use the OpenCLIP library, which will download (and cache) the CLIP model on first usage of our pipeline. In case you prefer reading a documentation rather than notebooks or code see [Documentation].
The repo inlcudes:
genQC/
a full release of our used diffusion pipeline.src/examples
examples how to reproduce some figures of the Paper.src/
the source notebooks for nbdev.
Examples
Minimal example
A minimal example to generate a 5 qubit circuit conditioned on a SRV of $[1,1,1,2,2]$. You can try it out on your own with our [Demo], no coding required.
from genQC.pipeline.diffusion_pipeline import DiffusionPipeline
from genQC.inference.infer_srv import generate_srv_tensors, convert_tensors_to_srvs
pipeline = DiffusionPipeline.from_pretrained("Floki00/qc_srv_3to8qubit", "cpu")
pipeline.scheduler.set_timesteps(20)
out_tensor = generate_srv_tensors(pipeline, "Generate SRV: [1,1,2,2,2]", samples=1, system_size=5, num_of_qubits=5, max_gates=16, g=10)
qc_list, _, srv_list = convert_tensors_to_srvs(out_tensor, pipeline.gate_pool)
[INFO]: `genQC.models.unet_qc.QC_Cond_UNet` instantiated from given config on cpu.
[INFO]: `genQC.models.frozen_open_clip.CachedFrozenOpenCLIPEmbedder` instantiated from given config on cpu.
[INFO]: `genQC.models.frozen_open_clip.CachedFrozenOpenCLIPEmbedder`. No save_path` provided. No state dict loaded.
print(f"Circuit is SRV {srv_list[0]}")
qc_list[0].draw("mpl")
Circuit is SRV [1, 1, 2, 2, 2]
Included examples
Example notebooks are provided in the directory src/examples/
.
0_hello_circuit
[doc] [notebook]: How to sample a circuit (conditioned on a SRV)1_editing_and_masking
[doc] [notebook]: Presents editing and masking of circuits2_unitary_compilation
[doc] [notebook]: Compile unitaries and transpile circuits3_dataset_and_fineTune
[doc] [notebook]: How to create a dataset and fine-tune a pre-trained model
Installation
The installation of genQC
is done via pip
within a few minutes,
depending on your downloading speed.
Method 1: pip install
To install genQC
just run:
pip install genQC
Note, this will install missing requirements automatically. You may want
to install some of them manually beforehand, e.g. torch
for specific
cuda support, see
pytorch.org/get-started/locally.
Requirements: genQC
depends on python
(min. version 3.10) and
the libraries: torch
, numpy
, matplotlib
, scipy
, pandas
,
omegaconf
, qiskit
, tqdm
, joblib
, open_clip_torch
,
ipywidgets
, pylatexenc
and huggingface_hub
. All can be installed
with pip
. In src/RELEASES.md
[doc] and
the release descriptions specific tested-on versions are listed.
Method 2: clone the repository
To use the latest GitHub code you can clone the repository by running:
git clone https://github.com/FlorianFuerrutter/genQC.git
cd genQC
The library genQC
is built using jupyter notebooks and
nbdev
. To install the library use
in the clone directory:
pip install -e .
Test installation
You can run the provided 0_hello_circuit
[doc]
[notebook]
example to test your installation. On a computer with a moderate GPU
this inference example notebook should run under half a minute.
License
The code and weights in this repository are licensed under the Apache License 2.0.
BibTeX
We kindly ask you to cite our paper if any of the previous material was useful for your work.
@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},
doi = {https://doi.org/10.1038/s42256-024-00831-9},
vol = {6},
pages = {515-–524},
pages={1--10},
year={2024},
publisher={Nature Publishing Group UK London}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file genqc-0.1.0.tar.gz
.
File metadata
- Download URL: genqc-0.1.0.tar.gz
- Upload date:
- Size: 66.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae23032f243f68a8936cdd1174025dee3a2096841a679a47d79d56f670f4c5fb |
|
MD5 | 38687ca2d3894560398c45193a90fa24 |
|
BLAKE2b-256 | 87194aa28dbc4e8eb24a04ddb9b54e5df3234e413eee49d119fe388e6cb24bfb |
File details
Details for the file genQC-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: genQC-0.1.0-py3-none-any.whl
- Upload date:
- Size: 78.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce5fef8d9c371a6c2c03e3a45198e0326edeacea6ef4d5f5442e91fef324bdbc |
|
MD5 | 7c1c8ca09a6304870e23b7da33485f06 |
|
BLAKE2b-256 | cfa992f5f034f72aa630cb6a5458c0f8b6258c0b417ccac8f46ee12b792ea613 |