qcd

Quantum Circuit Designer: A gymnasium-based set of environments for benchmarking reinforcement learning for quantum circuit design.

https://github.com/philippaltmann/qcd

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.2%) to scientific vocabulary

Keywords

benchmark circuit-design gymnasium quantum-computing reinforcement-learning
Last synced: 6 months ago · JSON representation ·

Repository

Quantum Circuit Designer: A gymnasium-based set of environments for benchmarking reinforcement learning for quantum circuit design.

Basic Info
  • Host: GitHub
  • Owner: philippaltmann
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 1.45 MB
Statistics
  • Stars: 9
  • Watchers: 2
  • Forks: 1
  • Open Issues: 0
  • Releases: 2
Topics
benchmark circuit-design gymnasium quantum-computing reinforcement-learning
Created over 2 years ago · Last pushed over 1 year ago
Metadata Files
Readme License Code of conduct Citation

README.md

Quantum Circuit Designer

arXiv GitHub Release PyPI Version

QCD Overview

Description

This repository contains qcd-gym, a generic gymnasium environment to build quantum circuits gate-by-gate using qiskit, revealing current challenges regarding:

Observations

The observation is comprised of the state of the current circuit, represented by the full complex vector representation $\ket{\Psi}$ or the unitary operator $\boldsymbol{V}(\Sigmat)$ resulting from the current sequence of operations $\Sigmat$, as well as the intended target. While this information is only available in quantum circuit simulators efficiently (on real hardware, $\mathcal{O}(2^\eta)$ measurements would be needed), it depicts a starting point for RL from which future work should extract a sufficient, efficiently obtainable, subset of information. This state representation is sufficient for the definition of an MDP-compliant environment, as operations on this state are required to be reversible.

Actions

We use a $4$-dimensional Box action space $\langle o, q, c, \Phi \rangle = a \in \mathcal{A} = {\Gamma \times \Omega \times \Theta}$ with the following elements:

| Name | Parameter | Type | Description | | --------- | --------------------- |-------| :-------------------------------------- | | Operation | $o \in \Gamma$ |int | specifying operation (see next table) | | Qubit | $q \in[0, \eta)$ |int | specifying qubit to apply the operation | | Control | $c \in[0, \eta)$ |int | specifying a control qubit | | Parameter | $\Phi \in[- \pi,\pi]$ |float| continuous parameter |

The operations $\Gamma$ are defined as:

| o | Operation | Condition | Type | Arguments | Comments | | - | ------------ | ---------- | -------------------- | ---------- | :---------------------------- | | 0 | $\mathbb{Z}$ | $q = c$ | PhaseShift | $q,\Phi$ | Control omitted | | 0 | $\mathbb{Z}$ | $q \neq c$ | ControlledPhaseShift | $q,c,\Phi$ | - | | 1 | $\mathbb{X}$ | $q = c$ | X-Rotation | $q,\Phi$ | Control omitted | | 1 | $\mathbb{X}$ | $q \neq c$ | CNOT | $q,c$ | Parameter omitted | | 2 | $\mathbb{T}$ | | Terminate | | All agruments omitted |

With operations according to the following unversal gate set:

  • CNOT: $$CX_{q,c} = \ket{0}\bra{0}\otimes I + \ket{1}\bra{1}\otimes X$$
  • X-Rotation: $$RX(\Phi) = \exp\left(-i \frac{\Phi}{2} X\right)$$
  • PhaseShift: $$P(\Phi) = \exp\left(i\frac{\Phi}{2}\right) \cdot \exp\left(-i\frac{\Phi}{2} Z\right)$$
  • ControlledPhaseShift: $$CP(\Phi) = I \otimes \ket{0} \bra{0} + P(\Phi) \otimes \ket{1} \bra{1}$$

Reward

The reward is kept $0$ until the end of an episode is reached (either by truncation or termination). To incentivize the use of few operations, a step-cost $\mathcal{C}t$ is applied when exceeding two-thirds of the available operations $\sigma$: $$\mathcal{C}t=\max\left(0,\frac{3}{2\sigma}\left(t-\frac{\sigma}{3}\right)\right)$$

Suitable task reward functions $\mathcal{R}^{\ast}\in[0,1]$ are defined, s.t.: $\mathcal{R}=\mathcal{R}^{\ast}(st,at)-C_t$ if $t$ is terminal, according to the following objectives:

Objectives

State Preparation

The task of this objective is to construct a quantum circuit that generates a desired quantum state. The reward is based on the fidelity between the target an the final state: $$\mathcal{R}^{SP}(st,at) = F(st, \Psi) = |\braket{\psi{\text{env}}|\psi{\text{target}}}|^2 \in [0,1]$$ Currently, the following states are defined: - 'SP-random' (a random state over *maxqubits* ) - 'SP-bell' (the 2-qubit Bell state) - 'SP-ghz<N>' (the <N> qubit GHZ state)

Unitary Composition

The task of this objective is to construct a quantum circuit that implements a desired unitary operation. The reward is based on the Frobenius norm $D = |U - V(\Sigmat)|2$ between the taget unitary $U$ and the final unitary $V$ based on the sequence of operations $\Sigmat = \langle a0, \dots, a_t \rangle$:

$$ R^{UC}(st,at) = 1 - \arctan (D)$$

The following unitaries are currently available for this objective:

  • 'UC-random' (a random unitary operation on max_qubits )
  • 'UC-hadamard' (the single qubit Hadamard gate)
  • 'UC-toffoli' (the 3-qubit Toffoli gate)

Further Objectives

The goal of this implementation is to not only construct any circuit that fulfills a specific objective but to also make this circuit optimal, that is to give the environment further objectives, such as optimizing:

  • Circuit Depth
  • Qubit Count
  • Gate Count
  • Parameter Count
  • Qubit-Connectivity

These circuit optimization objectives can be switched on by the parameter punish when initializing a new environment.

Currently, the only further objective implemented in this environment is the circuit depth, as this is one of the most important features to restrict for NISQ (noisy, intermediate-scale, quantum) devices. This metric already includes gate count and parameter count to some extent. However, further objectives can easily be added within the Reward class of this environment.

Setup

Install the quantum circuit designer environment

sh pip install qcd-gym

The environment can be set up as:

```python import gymnasium as gym

env = gym.make("CircuitDesigner-v0", maxqubits=2, maxdepth=10, objective='SP-bell', rendermode='text') observation, info = env.reset(seed=42); env.actionspace.seed(42)

for _ in range(9): action = env.action_space.sample() # this is where you would insert your policy observation, reward, terminated, truncated, info = env.step(action) if terminated or truncated: observation, info = env.reset()

env.close() ```

The relevant parameters for setting up the environment are:

| Parameter | Type | Explanation | | :----------------- | ------ | ------------------------------------------------------------ | | maxqubits $\eta$ | int | maximal number of qubits available | | maxdepth $\delta$ | int | maximal circuit depth allowed (= truncation criterion) | | objective | str | RL objective for which the circuit is to be built (see Objectives) | | punish | bool | specifier for turning on multi-objectives (see Further Objectives) |

Running benchmarks

Running benchmark experiments requires a full installation including baseline algorithms extending stable_baselines3 and a plotting framework extending plotly: This can be achieved by: sh git clone https://github.com/philippaltmann/QCD.git pip install -e '.[all]'

Specify the intended <Task> as: "objective-qmax_qubits-dmax_depth":

```sh

Run a specific algoritm and task (requires pip install -e '.[train]')

python -m train [A2C | PPO | SAC | TD3] -e

Generate plots from the results folder (requires pip install -e '.[plot]')

python -m plot results -b # plot all runs in results, add random and evo baselines

To train the provided baseline algorithms, use (pip install -e .[all])

./run.sh

Test the circuit designer (requires pip install -e '.[test]')

python -m test ```

Results

Results

Acknowledgements

The research is part of the Munich Quantum Valley, which is supported by the Bavarian state government with funds from the Hightech Agenda Bayern Plus.

Owner

  • Name: Philipp
  • Login: philippaltmann
  • Kind: user
  • Location: Munich
  • Company: LMU Munich

Research Associate @ LMU Munich Working on Collective Intelligence

Citation (CITATION.cff)

cff-version: 1.2.0
title: "qcd-gym"
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Philipp
    family-names: Altmann
    email: philipp@hyphi.co
repository-code: 'https://github.com/philippaltmann/qcd/'
url: 'https://github.com/philippaltmann/qcd/'
abstract: >-
  A gymnasium-based set of environments for benchmarking 
  reinforcement learning for quantum circuit design.
keywords:
  - Reinforcement Learning
  - Quantum Computing
  - Circuit Optimization
  - Architecture Search
license: MIT

GitHub Events

Total
  • Issues event: 1
  • Watch event: 4
  • Fork event: 1
Last Year
  • Issues event: 1
  • Watch event: 4
  • Fork event: 1

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 154
  • Total Committers: 6
  • Avg Commits per committer: 25.667
  • Development Distribution Score (DDS): 0.39
Past Year
  • Commits: 154
  • Committers: 6
  • Avg Commits per committer: 25.667
  • Development Distribution Score (DDS): 0.39
Top Committers
Name Email Commits
Philipp p****n@i****e 94
adelina-b 1****b 55
Michael Kölle m****e@i****e 2
Jonas Stein j****n@i****e 1
Philipp p****p@a****c 1
Philipp p****n@d****o 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 1
  • Total pull requests: 1
  • Average time to close issues: 35 minutes
  • Average time to close pull requests: less than a minute
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 1
  • Average time to close issues: 35 minutes
  • Average time to close pull requests: less than a minute
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • tnvuhai (1)
Pull Request Authors
  • philippaltmann (2)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

setup.py pypi
  • gymnasium ==0.29
  • pennylane-lightning ==0.32.0