This repository contains the Quantum Circuit Designer, a generic gymnasium environment to build quantum circuits gate-by-gate using pennylane, revealing current challenges regarding:
- State Preparation (SP): Find a gate sequence that turns some initial state into the target quantum state.
- Unitary Composition (UC): Find a gate sequence that constructs an arbitrary quantum operator.
The observation is defined by the full complex vector representation of the state of the current circuit:
We use a Box
action space
Name | Parameter | Type | Description |
---|---|---|---|
Operation | int |
specifying operation (see next table) | |
Qubit | int |
specifying qubit to apply the operation | |
Control | int |
specifying a control qubit | |
Parameter | float |
continuous parameter |
The operations
o | Operation | Condition | Type | Arguments | Comments |
---|---|---|---|---|---|
0 | Meassurement | Control and Parameter omitted | |||
1 | PhaseShift | Control omitted | |||
1 | ControlledPhaseShift | - | |||
2 | X-Rotation | Control omitted | |||
2 | CNOT | Parameter omitted | |||
3 | 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}$$
The reward is kept
Suitable task reward functions
The objective of this challenge 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:
'SP-random'
(a random state over max_qubits )'SP-bell'
(the 2-qubit Bell state)'SP-ghz<N>'
(the<N>
qubit GHZ state)
The objective of this challenge is to construct a quantum circuit that implements a desired unitary operation.
The reward is based on the Frobenius norm
The following unitaries are currently available for this challenge:
'UC-random'
(a random unitary operation on max_qubits )'UC-hadamard'
(the single qubit Hadamard gate)'UC-toffoli'
(the 3-qubit Toffoli gate)
See Outlook for more challenges to come.
The goal of this implementation is to not only construct any circuit that fulfills a specific challenge but to also make this circuit optimal, that is to give the environment further objectives, such as optimizing:
- Circuit Depth
- Qubit Count
- Gate Count (or: 2-qubit 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 (see Outlook).
Install the quantum circuit designer environment
pip install qcd-gym
The environment can be set up as:
import gymnasium as gym
env = gym.make("CircuitDesigner-v0", max_qubits=2, max_depth=10, challenge='SP-bell', render_mode='text', verbose=True)
observation, info = env.reset(seed=42); env.action_space.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 |
---|---|---|
max_qubits |
int |
maximal number of qubits available |
max_depth |
int |
maximal circuit depth allowed (= truncation criterion) |
challenge | str |
RL challenge for which the circuit is to be built (see Challenges) |
punish | bool |
specifier for turning on multi-objectives (see Further Objectives) |
Running benchmark experiments requires a full installation including baseline algorithms extending stable_baselines3 and a plotting framework extending plotly: This can be achieved by:
git clone https://github.com/philippaltmann/QCD.git
pip install -e '.[all]'
Specify the intended <Challenge> as: "challenge
-qmax_qubits
-dmax_depth
":
# Run a specific algoritm and challenge (requires `pip install -e '.[train]'`)
python -m train [A2C | PPO | SAC | TD3] -e <Challenge>
# Generate plots from the `results` folder (requires `pip install -e '.[plot]'`)
python -m plot results
# To train the provided baseline algorithms, use (pip install -e .[all])
./run
# Test the circuit designer (requires `pip install -e '.[test]'`)
python -m circuit_designer.test
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.