-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚸 Python Bindings for NA State Preparation (#556)
## Description This PR aims to provide python bindings for the state preparation for neutral atoms part of qmap. ## Checklist: <!--- This checklist serves as a reminder of a couple of things that ensure your pull request will be merged swiftly. --> - [x] The pull request only contains commits that are related to it. - [x] I have added appropriate tests and documentation. - [x] I have made sure that all CI jobs on GitHub pass. - [x] The pull request introduces no new warnings and follows the project's style guidelines.
- Loading branch information
Showing
22 changed files
with
702 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"<style>.widget-subarea{display:none;} /*hide widgets as they do not work with sphinx*/</style>\n", | ||
"\n", | ||
"# Neutral Atom Logical State Preparation\n", | ||
"\n", | ||
"All quantum computers are prone to errors.\n", | ||
"This is the motivation of employing error correction during a quantum computation.\n", | ||
"To this end, a (logical) qubit on the algorithmic level is encoded into a shared and highly entangled state of multiple physical qubits.\n", | ||
"Before the actual computation can start, those physical qubits need to be prepared in a state that represents the logical zero state.\n", | ||
"\n", | ||
"For that, we provide tool that takes a state preparation circuit and generates an optimal sequence of operations tailored to the zoned neutral atom architecture.\n", | ||
"Thereby, the circuit consists of one initial layer of Hadamard gates on all qubits that initialize the physical qubits in the plus state.\n", | ||
"Those are followed by a set of entangling (CZ) gates that generate a so-called graph state.\n", | ||
"The final logical state is achieved by applying additional Hadamard gates on selected qubits.\n", | ||
"\n", | ||
"Below we demonstrate how the optimal schedule can be retrieved for the Steane-code, the smallest 2D color code.\n", | ||
"First, we create the state preparation circuit for the Steane-code as a `qiskit.QuantumCircuit`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from qiskit import QuantumCircuit\n", | ||
"\n", | ||
"qc = QuantumCircuit(7)\n", | ||
"qc.h(range(7))\n", | ||
"qc.cz(0, 3)\n", | ||
"qc.cz(0, 4)\n", | ||
"qc.cz(1, 2)\n", | ||
"qc.cz(1, 5)\n", | ||
"qc.cz(1, 6)\n", | ||
"qc.cz(2, 3)\n", | ||
"qc.cz(2, 4)\n", | ||
"qc.cz(3, 5)\n", | ||
"qc.cz(4, 6)\n", | ||
"qc.h(0)\n", | ||
"qc.h(2)\n", | ||
"qc.h(5)\n", | ||
"qc.h(6)\n", | ||
"\n", | ||
"qc.draw(output=\"mpl\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We solve the problem of optimal state preparation with an SMT solver (Z3).\n", | ||
"Therefore, we encode the problem into an SMT-model.\n", | ||
"To construct the SMT model, the solver takes the entangling operations (CZ) as a list of qubit pairs." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mqt.qmap.na import get_ops_for_solver\n", | ||
"\n", | ||
"ops = get_ops_for_solver(qc, \"z\", 1) # We extract the 'Z' gates with '1' control, i.e., CZ gates\n", | ||
"ops" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Now, we are ready to initialize the solver and to generate the optimal sequence of operations.\n", | ||
"The parameters of the solver describe an architecture with two storage zones with each two rows, one zone above the entangling zone and one below.\n", | ||
"The entangling zone itself consists of three rows and the architecture model has three columns.\n", | ||
"Within each interaction site, atoms can be offset by two sites in every direction.\n", | ||
"The considered architecture offers two AOD columns and three AOD rows.\n", | ||
"\n", | ||
"We instruct the solver to generate a sequence consisting of four stages.\n", | ||
"Thereby, we do not fix the number of transfer stages.\n", | ||
"The last two boolean arguments, specify that the solver needs not to maintain the order of operations and must shield idling qubits in the storage zone.\n", | ||
"For further details on the employed abstraction of the 2D plane in the solver, please refer to the corresponding article :cite:labelpar:`stadeOptimalStatePreparation2024`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mqt.qmap.na import NAStatePreparationSolver\n", | ||
"\n", | ||
"solver = NAStatePreparationSolver(3, 7, 2, 3, 2, 2, 2, 2, 2, 4)\n", | ||
"result = solver.solve(ops, 7, 4, None, False, True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"To inspect the result, it can be exported to the human-readable YAML format by invoking the method `result.yaml()`\n", | ||
"In this example, we take another approach and generate code from the result.\n", | ||
"For that, we call the function `generate_code` with the respective arguments." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from mqt.qmap.na import generate_code\n", | ||
"\n", | ||
"code = generate_code(qc, result)\n", | ||
"print(code)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"For further details, please refer to the [reference documentation](library/NAStatePrep.rst)." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ Library | |
Synthesis | ||
SynthesisResults | ||
Visualization | ||
NAStatePrep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Neutral Atom Logical State Preparation | ||
====================================== | ||
|
||
This module provides functionality to generate an optimal operation sequence for zoned neutral atom architectures. | ||
The input must be a circuit of single-qubit gates, followed by a set of entangling gates (CZ) and finally single-qubit gates on selected qubits. | ||
Those circuits arise in the realm of error correction when the initial logical state must be prepared. | ||
|
||
The process is divided into three steps: | ||
1. Extract a list of qubit pairs from the circuit that represents the entangling gates with :code:`get_ops_for_solver` | ||
|
||
.. currentmodule:: mqt.qmap.na | ||
.. autofunction:: get_ops_for_solver | ||
|
||
2. Supply the list of entangling operations to the solver and generate the optimal operation sequence with the :code:`NAStatePreparationSolver`. | ||
For further details on the employed abstraction of the 2D plane in the solver, please refer to the corresponding article :cite:labelpar:`stadeOptimalStatePreparation2024`. | ||
|
||
.. currentmodule:: mqt.qmap.na | ||
.. autoclass:: NAStatePreparationSolver | ||
|
||
3. Generate code from the solver's result with :code:`generate_code` | ||
|
||
.. currentmodule:: mqt.qmap.na | ||
.. autofunction:: generate_code |
Oops, something went wrong.