Code repository for generating quantum circuits with diffusion models. [Paper] [Demo]
All weights and functions are contained within this repo. 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:
saves/
the configs and weights of the pre-trained models.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.
A minimal example to generate a 5 qubit circuit conditioned on a SRV of
from genQC.pipeline.diffusion_pipeline import DiffusionPipeline
from genQC.inference.infer_srv import generate_srv_tensors, convert_tensors_to_srvs
model_path = "../saves/qc_unet_config_SRV_3to8_qubit/"
pipeline = DiffusionPipeline.from_config_file(model_path, "cpu")
pipeline.scheduler.set_timesteps(20)
out_tensor = generate_srv_tensors(pipeline, "Generate SRV: [1,1,1,2,2]", samples=1, system_size=5, num_of_qubits=5, max_gates=16, g=7.5)
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"is SRV {srv_list[0]}")
qc_list[0].draw("mpl", style="clifford")
is SRV [1, 1, 1, 2, 2]
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
The installation of genQC is done via pip
within a few minutes,
depending on your downloading speed.
git clone https://github.com/FlorianFuerrutter/genQC.git
cd genQC
This library is build using jupyter notebooks and nbdev. To install the library use in the clone directory:
pip install -e .
Note, this will install missing requirements automatically. You may want to install some of them manually beforehand, e.g. pytorch for specific cuda support, see pytorch.org/get-started/locally.
Requirements: genQC
depends on python
(min. version 3.9) and the
libraries: torch
, numpy
, matplotlib
, scipy
, pandas
,
omegaconf
, qiskit
, tqdm
, joblib
, open_clip_torch
, ipywidgets
and pylatexenc
. All can be installed with pip
. In src/RELEASES.md
[doc]
and the release descriptions specific tested-on versions are listed.
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.
The code and weights in this repository are released under the MIT License.
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}
}