-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
High-level-synthesis for permutations (#9157)
* Adding permutation synthesis algorithm for LNN * release notes * Checking that the synthesized permutation adheres to the LNN connectivity and has depth guaranteed by the algorithm * Adding tests for 15 qubits Co-authored-by: Nir Gavrielov <nirgavrielov@gmail.com> * Changing Permutation to be a Gate rather than QuantumCircuit * Adding the property pattern to Permutation class * fixing assert * improving description message for _get_ordered_swap * applying suggestions from code review * minor * attempt to fix docstring * Another attempt to fix docsting * another attempt to fix docstring * temporarily simplifying docstring to see if this passes docs build * adding blank line * another attempt * Restoring docstring * removing extra line * adding __array__ method for permutation + tests * HLS permutation plugin based on the original synthesis algorithm for permutations * speeding up _get_ordered_swap based on review comments * Adding depth-2 synthesis algorithm for permutations for all-to-all connectivity; including tests and plugin * release notes * Adding example to release notes * Update documentation of Permutation * add missing import * drawing decomposed circuit with permutations * forgot parenthesis * restoring qasm for circuits containing Permutations * Adding permutation method to QuantumCircuit * Adding test for quantum circuit with permutations * pylint * adding inverse() method to permutations * qpy support for permutations * tests for quantum circuits with permutations * checking depth bound on the ACG method * Adding tests for new Permutation functionality * black * Following review, keeping the old Permutation quantum circuit for backward compatibility, and naming the new permutation gate class as PermutationGate * additional fixes * updating release notes * docs fix * Removing permutation method from QuantumCircuit * Adding QPY test for circuits with permutation gates * Update qiskit/circuit/quantumcircuit.py Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * Set default qasm name override to None Co-authored-by: Nir Gavrielov <nirgavrielov@gmail.com> Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d9b1a4b
commit 179c29c
Showing
17 changed files
with
593 additions
and
29 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
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
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,90 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2022. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""Synthesis algorithm for Permutation gates for full-connectivity.""" | ||
|
||
from qiskit.circuit.quantumcircuit import QuantumCircuit | ||
from .permutation_utils import ( | ||
_get_ordered_swap, | ||
_inverse_pattern, | ||
_pattern_to_cycles, | ||
_decompose_cycles, | ||
) | ||
|
||
|
||
def synth_permutation_basic(pattern): | ||
"""Synthesize a permutation circuit for a fully-connected | ||
architecture using sorting. | ||
More precisely, if the input permutation is a cycle of length ``m``, | ||
then this creates a quantum circuit with ``m-1`` SWAPs (and of depth ``m-1``); | ||
if the input permutation consists of several disjoint cycles, then each cycle | ||
is essentially treated independently. | ||
Args: | ||
pattern (Union[list[int], np.ndarray]): permutation pattern, describing | ||
which qubits occupy the positions 0, 1, 2, etc. after applying the | ||
permutation. That is, ``pattern[k] = m`` when the permutation maps | ||
qubit ``m`` to position ``k``. As an example, the pattern ``[2, 4, 3, 0, 1]`` | ||
means that qubit ``2`` goes to position ``0``, qubit ``4`` goes to | ||
position ``1``, etc. | ||
Returns: | ||
QuantumCircuit: the synthesized quantum circuit. | ||
""" | ||
# This is the very original Qiskit algorithm for synthesizing permutations. | ||
|
||
num_qubits = len(pattern) | ||
qc = QuantumCircuit(num_qubits) | ||
|
||
swaps = _get_ordered_swap(pattern) | ||
|
||
for swap in swaps: | ||
qc.swap(swap[0], swap[1]) | ||
|
||
return qc | ||
|
||
|
||
def synth_permutation_acg(pattern): | ||
"""Synthesize a permutation circuit for a fully-connected | ||
architecture using the Alon, Chung, Graham method. | ||
This produces a quantum circuit of depth 2 (measured in the number of SWAPs). | ||
This implementation is based on the Theorem 2 in the paper | ||
"Routing Permutations on Graphs Via Matchings" (1993), | ||
available at https://www.cs.tau.ac.il/~nogaa/PDFS/r.pdf. | ||
Args: | ||
pattern (Union[list[int], np.ndarray]): permutation pattern, describing | ||
which qubits occupy the positions 0, 1, 2, etc. after applying the | ||
permutation. That is, ``pattern[k] = m`` when the permutation maps | ||
qubit ``m`` to position ``k``. As an example, the pattern ``[2, 4, 3, 0, 1]`` | ||
means that qubit ``2`` goes to position ``0``, qubit ``4`` goes to | ||
position ``1``, etc. | ||
Returns: | ||
QuantumCircuit: the synthesized quantum circuit. | ||
""" | ||
|
||
num_qubits = len(pattern) | ||
qc = QuantumCircuit(num_qubits) | ||
|
||
# invert pattern (Qiskit notation is opposite) | ||
cur_pattern = _inverse_pattern(pattern) | ||
cycles = _pattern_to_cycles(cur_pattern) | ||
swaps = _decompose_cycles(cycles) | ||
|
||
for swap in swaps: | ||
qc.swap(swap[0], swap[1]) | ||
|
||
return qc |
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
Oops, something went wrong.