# genQC · Generative Quantum Circuits
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
<p align="left">
<a><img src="https://badgen.net/badge/icon/awesome?icon=awesome&label" alt="awesome"></a>
<a><img src="https://badgen.net/badge/generative/models/orange" alt="generative-models"></a>
<a><img src="https://badgen.net/badge/diffusion/models/pink" alt="diffusion-models"></a>
<a><img src="https://img.shields.io/badge/python-3.10-red" alt="python-3.10"></a>
<a href="https://doi.org/10.5281/zenodo.10282060"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.10282060.svg" alt="DOI"></a>
</p>
Code repository for generating quantum circuits with diffusion models.
[\[Arxiv\]](https://arxiv.org/abs/2311.02041)
[\[Demo\]](https://huggingface.co/spaces/Floki00/genQC)
![](https://github.com/FlorianFuerrutter/genQC/blob/main/src/assets/inference.png?raw=true)
## 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](https://huggingface.co/collections/Floki00/generative-quantum-circuits-6550e926c67f60a368b02bc3)
and can be downloaded automatically via our code (see minimal example).
For the CLIP model weights we use the
[OpenCLIP](https://github.com/mlfoundations/open_clip) 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\]](https://florianfuerrutter.github.io/genQC/).
The repo inlcudes:
1. `genQC/` a full release of our used diffusion pipeline.
2. `src/examples` examples how to reproduce some figures of the
[Paper](https://arxiv.org/abs/2311.02041).
3. `src/` the source notebooks for
[nbdev](https://github.com/fastai/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\]](https://huggingface.co/spaces/Floki00/genQC), no coding
required.
``` python
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.
``` python
print(f"Circuit is SRV {srv_list[0]}")
qc_list[0].draw("mpl")
```
Circuit is SRV [1, 1, 2, 2, 2]
![](https://github.com/FlorianFuerrutter/genQC/blob/main/index_files/figure-commonmark/cell-3-output-2.png?raw=true)
#### Included examples
Example notebooks are provided in the directory `src/examples/`.
- `0_hello_circuit`
[\[doc\]](https://florianfuerrutter.github.io/genQC/examples/hello_circuit.html)
[\[notebook\]](https://github.com/FlorianFuerrutter/genQC/blob/main/src/examples/0_hello_circuit.ipynb):
How to sample a circuit (conditioned on a SRV)
- `1_editing_and_masking`
[\[doc\]](https://florianfuerrutter.github.io/genQC/examples/editing_and_masking.html)
[\[notebook\]](https://github.com/FlorianFuerrutter/genQC/blob/main/src/examples/1_editing_and_masking.ipynb):
Presents editing and masking of circuits
- `2_unitary_compilation`
[\[doc\]](https://florianfuerrutter.github.io/genQC/examples/unitary_compilation.html)
[\[notebook\]](https://github.com/FlorianFuerrutter/genQC/blob/main/src/examples/2_unitary_compilation.ipynb):
Compile unitaries and transpile circuits
- `3_dataset_and_fineTune`
[\[doc\]](https://florianfuerrutter.github.io/genQC/examples/dataset_and_finetune.html)
[\[notebook\]](https://github.com/FlorianFuerrutter/genQC/blob/main/src/examples/3_dataset_and_fineTune.ipynb):
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:
``` sh
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](https://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\]](https://florianfuerrutter.github.io/genQC/RELEASES.html) 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:
``` sh
git clone https://github.com/FlorianFuerrutter/genQC.git
cd genQC
```
The library `genQC` is built using jupyter notebooks and
[`nbdev`](https://github.com/fastai/nbdev). To install the library use
in the clone directory:
``` sh
pip install -e .
```
#### Test installation
You can run the provided `0_hello_circuit`
[\[doc\]](https://florianfuerrutter.github.io/genQC/examples/hello_circuit.html)
[\[notebook\]](https://github.com/FlorianFuerrutter/genQC/blob/main/src/examples/0_hello_circuit.ipynb)
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](https://github.com/FlorianFuerrutter/genQC/blob/main/LICENSE.txt).
## BibTeX
We kindly ask you to cite our paper if any of the previous material was
useful for your work.
``` latex
@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}
}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/FlorianFuerrutter/genQC",
"name": "genQC",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "quantum-information diffusion-models generative-models",
"author": "Florian Fuerrutter",
"author_email": "f.fuerrutter@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/87/19/4aa28dbc4e8eb24a04ddb9b54e5df3234e413eee49d119fe388e6cb24bfb/genqc-0.1.0.tar.gz",
"platform": null,
"description": "# genQC \u00b7 Generative Quantum Circuits\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n<p align=\"left\">\n<a><img src=\"https://badgen.net/badge/icon/awesome?icon=awesome&label\" alt=\"awesome\"></a>\n<a><img src=\"https://badgen.net/badge/generative/models/orange\" alt=\"generative-models\"></a>\n<a><img src=\"https://badgen.net/badge/diffusion/models/pink\" alt=\"diffusion-models\"></a>\n<a><img src=\"https://img.shields.io/badge/python-3.10-red\" alt=\"python-3.10\"></a>\n<a href=\"https://doi.org/10.5281/zenodo.10282060\"><img src=\"https://zenodo.org/badge/DOI/10.5281/zenodo.10282060.svg\" alt=\"DOI\"></a>\n</p>\n\nCode repository for generating quantum circuits with diffusion models.\n[\\[Arxiv\\]](https://arxiv.org/abs/2311.02041)\n[\\[Demo\\]](https://huggingface.co/spaces/Floki00/genQC)\n\n![](https://github.com/FlorianFuerrutter/genQC/blob/main/src/assets/inference.png?raw=true)\n\n## The codebase\n\nThe code contained within this repo allows the sampling of pre-trained\ndiffusion models and includes our pipeline to fine-tune and train models\nfrom scratch. Pre-trained weights can be found on [Hugging\nFace](https://huggingface.co/collections/Floki00/generative-quantum-circuits-6550e926c67f60a368b02bc3)\nand can be downloaded automatically via our code (see minimal example).\nFor the CLIP model weights we use the\n[OpenCLIP](https://github.com/mlfoundations/open_clip) library, which\nwill download (and cache) the CLIP model on first usage of our pipeline.\nIn case you prefer reading a documentation rather than notebooks or code\nsee [\\[Documentation\\]](https://florianfuerrutter.github.io/genQC/).\n\nThe repo inlcudes:\n\n1. `genQC/` a full release of our used diffusion pipeline.\n2. `src/examples` examples how to reproduce some figures of the\n [Paper](https://arxiv.org/abs/2311.02041).\n3. `src/` the source notebooks for\n [nbdev](https://github.com/fastai/nbdev).\n\n## Examples\n\n#### Minimal example\n\nA minimal example to generate a 5 qubit circuit conditioned on a SRV of\n$[1,1,1,2,2]$. You can try it out on your own with our\n[\\[Demo\\]](https://huggingface.co/spaces/Floki00/genQC), no coding\nrequired.\n\n``` python\nfrom genQC.pipeline.diffusion_pipeline import DiffusionPipeline\nfrom genQC.inference.infer_srv import generate_srv_tensors, convert_tensors_to_srvs\n\npipeline = DiffusionPipeline.from_pretrained(\"Floki00/qc_srv_3to8qubit\", \"cpu\")\npipeline.scheduler.set_timesteps(20) \n\nout_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) \nqc_list, _, srv_list = convert_tensors_to_srvs(out_tensor, pipeline.gate_pool)\n```\n\n [INFO]: `genQC.models.unet_qc.QC_Cond_UNet` instantiated from given config on cpu.\n [INFO]: `genQC.models.frozen_open_clip.CachedFrozenOpenCLIPEmbedder` instantiated from given config on cpu.\n [INFO]: `genQC.models.frozen_open_clip.CachedFrozenOpenCLIPEmbedder`. No save_path` provided. No state dict loaded.\n\n``` python\nprint(f\"Circuit is SRV {srv_list[0]}\")\nqc_list[0].draw(\"mpl\")\n```\n\n Circuit is SRV [1, 1, 2, 2, 2]\n\n![](https://github.com/FlorianFuerrutter/genQC/blob/main/index_files/figure-commonmark/cell-3-output-2.png?raw=true)\n\n#### Included examples\n\nExample notebooks are provided in the directory `src/examples/`.\n\n- `0_hello_circuit`\n [\\[doc\\]](https://florianfuerrutter.github.io/genQC/examples/hello_circuit.html)\n [\\[notebook\\]](https://github.com/FlorianFuerrutter/genQC/blob/main/src/examples/0_hello_circuit.ipynb):\n How to sample a circuit (conditioned on a SRV)\n- `1_editing_and_masking`\n [\\[doc\\]](https://florianfuerrutter.github.io/genQC/examples/editing_and_masking.html)\n [\\[notebook\\]](https://github.com/FlorianFuerrutter/genQC/blob/main/src/examples/1_editing_and_masking.ipynb):\n Presents editing and masking of circuits\n- `2_unitary_compilation`\n [\\[doc\\]](https://florianfuerrutter.github.io/genQC/examples/unitary_compilation.html)\n [\\[notebook\\]](https://github.com/FlorianFuerrutter/genQC/blob/main/src/examples/2_unitary_compilation.ipynb):\n Compile unitaries and transpile circuits\n- `3_dataset_and_fineTune`\n [\\[doc\\]](https://florianfuerrutter.github.io/genQC/examples/dataset_and_finetune.html)\n [\\[notebook\\]](https://github.com/FlorianFuerrutter/genQC/blob/main/src/examples/3_dataset_and_fineTune.ipynb):\n How to create a dataset and fine-tune a pre-trained model\n\n## Installation\n\nThe installation of `genQC` is done via `pip` within a few minutes,\ndepending on your downloading speed.\n\n#### Method 1: pip install\n\nTo install `genQC` just run:\n\n``` sh\npip install genQC\n```\n\nNote, this will install missing requirements automatically. You may want\nto install some of them manually beforehand, e.g.\u00a0`torch` for specific\ncuda support, see\n[pytorch.org/get-started/locally](https://pytorch.org/get-started/locally/).\n\n**Requirements:** `genQC` depends on `python` (min. version 3.10) and\nthe libraries: `torch`, `numpy`, `matplotlib`, `scipy`, `pandas`,\n`omegaconf`, `qiskit`, `tqdm`, `joblib`, `open_clip_torch`,\n`ipywidgets`, `pylatexenc` and `huggingface_hub`. All can be installed\nwith `pip`. In `src/RELEASES.md`\n[\\[doc\\]](https://florianfuerrutter.github.io/genQC/RELEASES.html) and\nthe release descriptions specific tested-on versions are listed.\n\n#### Method 2: clone the repository\n\nTo use the latest GitHub code you can clone the repository by running:\n\n``` sh\ngit clone https://github.com/FlorianFuerrutter/genQC.git\ncd genQC\n```\n\nThe library `genQC` is built using jupyter notebooks and\n[`nbdev`](https://github.com/fastai/nbdev). To install the library use\nin the clone directory:\n\n``` sh\npip install -e .\n```\n\n#### Test installation\n\nYou can run the provided `0_hello_circuit`\n[\\[doc\\]](https://florianfuerrutter.github.io/genQC/examples/hello_circuit.html)\n[\\[notebook\\]](https://github.com/FlorianFuerrutter/genQC/blob/main/src/examples/0_hello_circuit.ipynb)\nexample to test your installation. On a computer with a moderate GPU\nthis inference example notebook should run under half a minute.\n\n## License\n\nThe code and weights in this repository are licensed under the [Apache\nLicense\n2.0](https://github.com/FlorianFuerrutter/genQC/blob/main/LICENSE.txt).\n\n## BibTeX\n\nWe kindly ask you to cite our paper if any of the previous material was\nuseful for your work.\n\n``` latex\n@article{furrutter2024quantum,\n title={Quantum circuit synthesis with diffusion models},\n author={F{\\\"u}rrutter, Florian and Mu{\\~n}oz-Gil, Gorka and Briegel, Hans J},\n journal={Nature Machine Intelligence},\n doi = {https://doi.org/10.1038/s42256-024-00831-9},\n vol = {6},\n pages = {515-\u2013524},\n pages={1--10},\n year={2024},\n publisher={Nature Publishing Group UK London}\n}\n```\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "Generating quantum circuits with diffusion models",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/FlorianFuerrutter/genQC"
},
"split_keywords": [
"quantum-information",
"diffusion-models",
"generative-models"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cfa992f5f034f72aa630cb6a5458c0f8b6258c0b417ccac8f46ee12b792ea613",
"md5": "7c1c8ca09a6304870e23b7da33485f06",
"sha256": "ce5fef8d9c371a6c2c03e3a45198e0326edeacea6ef4d5f5442e91fef324bdbc"
},
"downloads": -1,
"filename": "genQC-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7c1c8ca09a6304870e23b7da33485f06",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 78779,
"upload_time": "2024-08-26T20:27:49",
"upload_time_iso_8601": "2024-08-26T20:27:49.132445Z",
"url": "https://files.pythonhosted.org/packages/cf/a9/92f5f034f72aa630cb6a5458c0f8b6258c0b417ccac8f46ee12b792ea613/genQC-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "87194aa28dbc4e8eb24a04ddb9b54e5df3234e413eee49d119fe388e6cb24bfb",
"md5": "38687ca2d3894560398c45193a90fa24",
"sha256": "ae23032f243f68a8936cdd1174025dee3a2096841a679a47d79d56f670f4c5fb"
},
"downloads": -1,
"filename": "genqc-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "38687ca2d3894560398c45193a90fa24",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 66760,
"upload_time": "2024-08-26T20:27:51",
"upload_time_iso_8601": "2024-08-26T20:27:51.377903Z",
"url": "https://files.pythonhosted.org/packages/87/19/4aa28dbc4e8eb24a04ddb9b54e5df3234e413eee49d119fe388e6cb24bfb/genqc-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-26 20:27:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "FlorianFuerrutter",
"github_project": "genQC",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "genqc"
}