-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Arithmetic circuit library: multipliers #6470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
100 commits
Select commit
Hold shift + click to select a range
09699ad
Implement initial draft of ripple-carry adder circuit
mantcep 5c6d2a8
Switch to ancilla register for ancilla qubits
mantcep 425a8ce
Remove padding for simpler implementation
mantcep e843300
Add small fixes from review
mantcep 334bff1
Add initial unit tests
mantcep f62f6be
Switch carry out from ancilla to usual register
mantcep 0bae830
Update __init__ docstring with raises
mantcep c774707
Add suggestions from review; Clean-up
mantcep beaaf9d
Add additional test for ripple-carry adder
mantcep 3412e70
Merge branch 'master' into qft-adder
mantcep a193b95
Implement initial QFT adder circuit
mantcep f31a548
Fix QFT adder carry out; Switch to non-modular as default
mantcep 88d1273
Expand adder tests with QFT adder
mantcep 4359bc8
Rename test_adder.py -> test_adders.py
mantcep 0cbe476
Include additional QFT adder documentation
mantcep 7c1a750
Fix typos
mantcep be646c0
Implement ripple-carry adder circuit (#11)
mantcep e86916e
Merge branch 'master' into adders
Cryoris 40e7e50
Merge with adders branch
mantcep 6a7dd78
Fix documentation math
mantcep 4d48def
Add non-modular test as default
mantcep 8ba44cd
Remove duplicate file after merge
mantcep be569a3
Implement QFT adder (#22)
mantcep ea1d5f1
Merge branch 'adders' of https://github.com/Cryoris/qiskit-terra into…
mantcep b2dab3f
Implemented classical adder in QFT paper (#13)
ManjulaGandhi 38a759f
unify tests
Cryoris 8768780
inject base class ``Adder``
Cryoris ccee887
add reno
Cryoris d74b1d6
fix lint
Cryoris a544a2e
Merge branch 'master' into adders
Cryoris 53ab793
Merge branch 'adders' of https://github.com/Cryoris/qiskit-terra into…
mantcep 11da532
Merge branch 'master' into adders
Cryoris e62e233
Implement initial classical multiplier
mantcep a62efb9
Implement test for multipliers
mantcep 89cc44f
Update docstring
mantcep 599af6f
fix trailing whitespace in line beginning
Cryoris 0abbaa4
rework docstrings for less duplication
Cryoris 9147cbb
Change instructions to gates in adder circuits
mantcep 2d71e34
Generalize multiplier for any adder
mantcep a29bf1f
Expand multiplier test with all adders
mantcep b3532b3
Merge branch 'adders' of https://github.com/Cryoris/qiskit-terra into…
mantcep 10dbbdc
Fix pylint errors
mantcep e95d660
Merge branch 'main' into adders
Cryoris cff6fc9
Implement review suggestions
mantcep f0bdb97
several updates
Cryoris 335b2ce
lint
Cryoris a0cc65c
rename classical to plain, make plain modular
Cryoris a635799
Implement initial QFT multiplier draft
mantcep ed4fed6
Update QFT multiplier docstring
mantcep 17db640
Merge with cryoris/adders branch
mantcep c5d224a
Create common multiplier class
mantcep 89535de
Renamed PlainAdder to VBERippleCarryAdder (#29)
ManjulaGandhi ac5463e
rename modular->fixed point
Cryoris 5e93a37
add author names to adders
Cryoris 1b096ec
add comment on how the test works
Cryoris ba9e100
Merge branch 'main' into adders
Cryoris b5079b8
black
Cryoris f43fdbd
Fix common multiplier errors
mantcep d052626
Merge branch 'adders' of https://github.com/Cryoris/qiskit-terra into…
mantcep 95fd92c
Update classical multiplier default adder name
mantcep 951605f
Fix QFT multiplier registers
mantcep 53c5ac1
Implement tests for multipliers
mantcep 6f99f35
Fix lint
mantcep 7a41f92
Add black formatter changes
mantcep 9a5dca5
Switch to adder object instead of type
mantcep 5552354
Update classical multiplier drawing
mantcep 0713ccd
Switch to PhaseGate in QFT multiplier
mantcep 4a0c81f
Rename multipliers
mantcep 0713eab
Implement modulo in QFT multiplier
mantcep ab3b8e7
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into mu…
mantcep 3e72e12
Update to half adder in cumulative multiplier
mantcep 8b57eab
Make number of output qubits optional
mantcep 9c2cc7f
Implement modular cumulative multiplier
mantcep 1c3aae8
Add test for modular multiplication
mantcep 498255a
Fix wrong parameter name
mantcep 73d9f42
Expand common multiplier class with checks; Add more tests for multip…
mantcep 978e09f
Add black and lint changes
mantcep dd3a16d
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into mu…
mantcep acb3dd6
Add releasenote
mantcep 08e4d22
Merge branch 'main' into multipliers
mantcep b811887
Attempt cyclic import fix
mantcep 8fbda52
Attempt to fix cyclic import once more
mantcep 833c12e
Update qiskit/circuit/library/arithmetic/multipliers/hrs_cumulative_m…
mantcep 190233a
Update qiskit/circuit/library/arithmetic/multipliers/hrs_cumulative_m…
mantcep a45f2f2
Update qiskit/circuit/library/arithmetic/multipliers/hrs_cumulative_m…
mantcep a304715
Update qiskit/circuit/library/arithmetic/multipliers/multiplier.py
mantcep 388afbd
Update qiskit/circuit/library/arithmetic/multipliers/hrs_cumulative_m…
mantcep 06fb379
Add additional test cases
mantcep e135f6b
Include circuit diagram for QFT multiplier
mantcep 2fb0889
Update docstring as suggested
mantcep e9fd830
Move num_result_qubits logic to parent class
mantcep 4b499ea
Switch to NotImplementedError for cumulative multiplier
mantcep e9fe77e
Add black changes
mantcep 0c602ae
Update Multiplier class docstring
mantcep 6ce3dd8
Add lint changes
mantcep ddbf4b5
Update qiskit/circuit/library/arithmetic/multipliers/multiplier.py
mantcep 3b4624f
Update qiskit/circuit/library/arithmetic/multipliers/multiplier.py
mantcep 07e7edf
Add black and pylint fixes
mantcep f97706e
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into mu…
mantcep 1324858
Merge branch 'main' into multipliers
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,16 @@ | ||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2017, 2021. | ||
| # | ||
| # 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. | ||
|
|
||
| """The multiplier circuit library.""" | ||
|
|
||
| from .hrs_cumulative_multiplier import HRSCumulativeMultiplier | ||
| from .rg_qft_multiplier import RGQFTMultiplier |
134 changes: 134 additions & 0 deletions
134
qiskit/circuit/library/arithmetic/multipliers/hrs_cumulative_multiplier.py
This file contains hidden or 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,134 @@ | ||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2017, 2021. | ||
| # | ||
| # 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. | ||
|
|
||
| """Compute the product of two qubit registers using classical multiplication approach.""" | ||
|
|
||
| from typing import Optional | ||
| from qiskit.circuit import QuantumRegister, AncillaRegister, QuantumCircuit | ||
|
|
||
| from .multiplier import Multiplier | ||
|
|
||
|
|
||
| class HRSCumulativeMultiplier(Multiplier): | ||
| r"""A multiplication circuit to store product of two input registers out-of-place. | ||
|
|
||
| Circuit uses the approach from [1]. As an example, a multiplier circuit that | ||
| performs a non-modular multiplication on two 3-qubit sized registers with | ||
| the default adder is as follows (where ``Adder`` denotes the | ||
| ``CDKMRippleCarryAdder``): | ||
|
|
||
| .. parsed-literal:: | ||
|
|
||
| a_0: ────■───────────────────────── | ||
| │ | ||
| a_1: ────┼─────────■─────────────── | ||
| │ │ | ||
| a_2: ────┼─────────┼─────────■───── | ||
| ┌───┴────┐┌───┴────┐┌───┴────┐ | ||
| b_0: ┤0 ├┤0 ├┤0 ├ | ||
| │ ││ ││ │ | ||
| b_1: ┤1 ├┤1 ├┤1 ├ | ||
| │ ││ ││ │ | ||
| b_2: ┤2 ├┤2 ├┤2 ├ | ||
| │ ││ ││ │ | ||
| out_0: ┤3 ├┤ ├┤ ├ | ||
| │ ││ ││ │ | ||
| out_1: ┤4 ├┤3 ├┤ ├ | ||
| │ Adder ││ Adder ││ Adder │ | ||
| out_2: ┤5 ├┤4 ├┤3 ├ | ||
| │ ││ ││ │ | ||
| out_3: ┤6 ├┤5 ├┤4 ├ | ||
| │ ││ ││ │ | ||
| out_4: ┤ ├┤6 ├┤5 ├ | ||
| │ ││ ││ │ | ||
| out_5: ┤ ├┤ ├┤6 ├ | ||
| │ ││ ││ │ | ||
| aux_0: ┤7 ├┤7 ├┤7 ├ | ||
| └────────┘└────────┘└────────┘ | ||
|
|
||
| Multiplication in this circuit is implemented in a classical approach by performing | ||
| a series of shifted additions using one of the input registers while the qubits | ||
| from the other input register act as control qubits for the adders. | ||
|
|
||
| **References:** | ||
|
|
||
| [1] Häner et al., Optimizing Quantum Circuits for Arithmetic, 2018. | ||
| `arXiv:1805.12445 <https://arxiv.org/pdf/1805.12445.pdf>`_ | ||
|
|
||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| num_state_qubits: int, | ||
| num_result_qubits: Optional[int] = None, | ||
| adder: Optional[QuantumCircuit] = None, | ||
| name: str = "HRSCumulativeMultiplier", | ||
| ) -> None: | ||
| r""" | ||
| Args: | ||
| num_state_qubits: The number of qubits in either input register for | ||
| state :math:`|a\rangle` or :math:`|b\rangle`. The two input | ||
| registers must have the same number of qubits. | ||
| num_result_qubits: The number of result qubits to limit the output to. | ||
| If number of result qubits is :math:`n`, multiplication modulo :math:`2^n` is performed | ||
| to limit the output to the specified number of qubits. Default | ||
| value is ``2 * num_state_qubits`` to represent any possible | ||
| result from the multiplication of the two inputs. | ||
| adder: Half adder circuit to be used for performing multiplication. The | ||
| CDKMRippleCarryAdder is used as default if no adder is provided. | ||
| name: The name of the circuit object. | ||
| Raises: | ||
| NotImplementedError: If ``num_result_qubits`` is not default and a custom adder is provided. | ||
| """ | ||
| super().__init__(num_state_qubits, num_result_qubits, name=name) | ||
|
|
||
| if self.num_result_qubits != 2 * num_state_qubits and adder is not None: | ||
| raise NotImplementedError("Only default adder is supported for modular multiplication.") | ||
|
|
||
| # define the registers | ||
| qr_a = QuantumRegister(num_state_qubits, name="a") | ||
| qr_b = QuantumRegister(num_state_qubits, name="b") | ||
| qr_out = QuantumRegister(self.num_result_qubits, name="out") | ||
| self.add_register(qr_a, qr_b, qr_out) | ||
|
|
||
| # prepare adder as controlled gate | ||
| if adder is None: | ||
| from qiskit.circuit.library.arithmetic.adders import CDKMRippleCarryAdder | ||
|
|
||
| adder = CDKMRippleCarryAdder(num_state_qubits, kind="half") | ||
|
|
||
| # get the number of helper qubits needed | ||
| num_helper_qubits = adder.num_ancillas | ||
|
|
||
| # add helper qubits if required | ||
| if num_helper_qubits > 0: | ||
| qr_h = AncillaRegister(num_helper_qubits, name="helper") # helper/ancilla qubits | ||
| self.add_register(qr_h) | ||
|
|
||
| # build multiplication circuit | ||
| for i in range(num_state_qubits): | ||
| excess_qubits = max(0, num_state_qubits + i + 1 - self.num_result_qubits) | ||
| if excess_qubits == 0: | ||
| num_adder_qubits = num_state_qubits | ||
| adder_for_current_step = adder | ||
| else: | ||
| num_adder_qubits = num_state_qubits - excess_qubits + 1 | ||
| adder_for_current_step = CDKMRippleCarryAdder(num_adder_qubits, kind="fixed") | ||
| controlled_adder = adder_for_current_step.to_gate().control(1) | ||
| qr_list = ( | ||
| [qr_a[i]] | ||
| + qr_b[:num_adder_qubits] | ||
| + qr_out[i : num_state_qubits + i + 1 - excess_qubits] | ||
| ) | ||
| if num_helper_qubits > 0: | ||
| qr_list.extend(qr_h[:]) | ||
| self.append(controlled_adder, qr_list) | ||
101 changes: 101 additions & 0 deletions
101
qiskit/circuit/library/arithmetic/multipliers/multiplier.py
This file contains hidden or 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,101 @@ | ||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2017, 2021. | ||
| # | ||
| # 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. | ||
|
|
||
| """Compute the product of two equally sized qubit registers.""" | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from qiskit.circuit import QuantumCircuit | ||
|
|
||
|
|
||
| class Multiplier(QuantumCircuit): | ||
| r"""Compute the product of two equally sized qubit registers into a new register. | ||
|
|
||
| For two input registers :math:`|a\rangle_n`, :math:`|b\rangle_n` with :math:`n` qubits each | ||
| and an output register with :math:`2n` qubits, a multiplier performs the following operation | ||
|
|
||
| .. math:: | ||
|
|
||
| |a\rangle_n |b\rangle_n |0\rangle_{t} \mapsto |a\rangle_n |b\rangle_n |a \cdot b\rangle_t | ||
|
|
||
| where :math:`t` is the number of bits used to represent the result. To completely store the result | ||
| of the multiplication without overflow we need :math:`t = 2n` bits. | ||
|
|
||
| The quantum register :math:`|a\rangle_n` (analogously :math:`|b\rangle_n` and | ||
| output register) | ||
|
|
||
| .. math:: | ||
|
|
||
| |a\rangle_n = |a_0\rangle \otimes \cdots \otimes |a_{n - 1}\rangle, | ||
|
|
||
| for :math:`a_i \in \{0, 1\}`, is associated with the integer value | ||
|
|
||
| .. math:: | ||
|
|
||
| a = 2^{0}a_{0} + 2^{1}a_{1} + \cdots + 2^{n - 1}a_{n - 1}. | ||
|
|
||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| num_state_qubits: int, | ||
| num_result_qubits: Optional[int] = None, | ||
| name: str = "Multiplier", | ||
| ) -> None: | ||
| """ | ||
| Args: | ||
| num_state_qubits: The number of qubits in each of the input registers. | ||
| num_result_qubits: The number of result qubits to limit the output to. | ||
| Default value is ``2 * num_state_qubits`` to represent any possible | ||
| result from the multiplication of the two inputs. | ||
| name: The name of the circuit. | ||
| Raises: | ||
| ValueError: If ``num_state_qubits`` is smaller than 1. | ||
| ValueError: If ``num_result_qubits`` is smaller than ``num_state_qubits``. | ||
| ValueError: If ``num_result_qubits`` is larger than ``2 * num_state_qubits``. | ||
| """ | ||
| if num_state_qubits < 1: | ||
| raise ValueError("The number of qubits must be at least 1.") | ||
|
|
||
| if num_result_qubits is None: | ||
| num_result_qubits = 2 * num_state_qubits | ||
|
|
||
| if num_result_qubits < num_state_qubits: | ||
| raise ValueError( | ||
| "Number of result qubits is smaller than number of input state qubits." | ||
| ) | ||
| if num_result_qubits > 2 * num_state_qubits: | ||
| raise ValueError( | ||
| "Number of result qubits is larger than twice the number of input state qubits." | ||
| ) | ||
|
|
||
| super().__init__(name=name) | ||
| self._num_state_qubits = num_state_qubits | ||
| self._num_result_qubits = num_result_qubits | ||
|
|
||
| @property | ||
| def num_state_qubits(self) -> int: | ||
| """The number of state qubits, i.e. the number of bits in each input register. | ||
|
|
||
| Returns: | ||
| The number of state qubits. | ||
| """ | ||
| return self._num_state_qubits | ||
|
|
||
| @property | ||
| def num_result_qubits(self) -> int: | ||
| """The number of result qubits to limit the output to. | ||
|
|
||
| Returns: | ||
| The number of result qubits. | ||
| """ | ||
| return self._num_result_qubits |
97 changes: 97 additions & 0 deletions
97
qiskit/circuit/library/arithmetic/multipliers/rg_qft_multiplier.py
This file contains hidden or 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,97 @@ | ||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2017, 2021. | ||
| # | ||
| # 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. | ||
|
|
||
| """Compute the product of two qubit registers using QFT.""" | ||
|
|
||
| from typing import Optional | ||
| import numpy as np | ||
|
|
||
| from qiskit.circuit import QuantumRegister | ||
| from qiskit.circuit.library.standard_gates import PhaseGate | ||
| from qiskit.circuit.library.basis_change import QFT | ||
|
|
||
| from .multiplier import Multiplier | ||
|
|
||
|
|
||
| class RGQFTMultiplier(Multiplier): | ||
| r"""A QFT multiplication circuit to store product of two input registers out-of-place. | ||
|
|
||
| Multiplication in this circuit is implemented using the procedure of Fig. 3 in [1], where | ||
| weighted sum rotations are implemented as given in Fig. 5 in [1]. QFT is used on the output | ||
| register and is followed by rotations controlled by input registers. The rotations | ||
| transform the state into the product of two input registers in QFT base, which is | ||
| reverted from QFT base using inverse QFT. | ||
|
Cryoris marked this conversation as resolved.
|
||
| As an example, a circuit that performs a modular QFT multiplication on two 2-qubit | ||
| sized input registers with an output register of 2 qubits, is as follows: | ||
|
|
||
| .. parsed-literal:: | ||
|
|
||
| a_0: ────────────────────────────────────────■───────■──────■──────■──────────────── | ||
| │ │ │ │ | ||
| a_1: ─────────■───────■───────■───────■──────┼───────┼──────┼──────┼──────────────── | ||
| │ │ │ │ │ │ │ │ | ||
| b_0: ─────────┼───────┼───────■───────■──────┼───────┼──────■──────■──────────────── | ||
| │ │ │ │ │ │ │ │ | ||
| b_1: ─────────■───────■───────┼───────┼──────■───────■──────┼──────┼──────────────── | ||
| ┌──────┐ │P(4π) │ │P(2π) │ │P(2π) │ │P(π) │ ┌───────┐ | ||
| out_0: ┤0 ├─■───────┼───────■───────┼──────■───────┼──────■──────┼───────┤0 ├ | ||
| │ qft │ │P(2π) │P(π) │P(π) │P(π/2) │ iqft │ | ||
| out_1: ┤1 ├─────────■───────────────■──────────────■─────────────■───────┤1 ├ | ||
| └──────┘ └───────┘ | ||
|
|
||
| **References:** | ||
|
|
||
| [1] Ruiz-Perez et al., Quantum arithmetic with the Quantum Fourier Transform, 2017. | ||
| `arXiv:1411.5949 <https://arxiv.org/pdf/1411.5949.pdf>`_ | ||
|
|
||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| num_state_qubits: int, | ||
| num_result_qubits: Optional[int] = None, | ||
| name: str = "RGQFTMultiplier", | ||
| ) -> None: | ||
| r""" | ||
| Args: | ||
| num_state_qubits: The number of qubits in either input register for | ||
| state :math:`|a\rangle` or :math:`|b\rangle`. The two input | ||
| registers must have the same number of qubits. | ||
| num_result_qubits: The number of result qubits to limit the output to. | ||
| If number of result qubits is :math:`n`, multiplication modulo :math:`2^n` is performed | ||
| to limit the output to the specified number of qubits. Default | ||
| value is ``2 * num_state_qubits`` to represent any possible | ||
| result from the multiplication of the two inputs. | ||
| name: The name of the circuit object. | ||
|
|
||
| """ | ||
| super().__init__(num_state_qubits, num_result_qubits, name=name) | ||
|
|
||
| # define the registers | ||
| qr_a = QuantumRegister(num_state_qubits, name="a") | ||
| qr_b = QuantumRegister(num_state_qubits, name="b") | ||
| qr_out = QuantumRegister(self.num_result_qubits, name="out") | ||
| self.add_register(qr_a, qr_b, qr_out) | ||
|
|
||
| # build multiplication circuit | ||
| self.append(QFT(self.num_result_qubits, do_swaps=False).to_gate(), qr_out[:]) | ||
|
|
||
| for j in range(1, num_state_qubits + 1): | ||
| for i in range(1, num_state_qubits + 1): | ||
| for k in range(1, self.num_result_qubits + 1): | ||
| lam = (2 * np.pi) / (2 ** (i + j + k - 2 * num_state_qubits)) | ||
| self.append( | ||
| PhaseGate(lam).control(2), | ||
| [qr_a[num_state_qubits - j], qr_b[num_state_qubits - i], qr_out[k - 1]], | ||
| ) | ||
|
|
||
| self.append(QFT(self.num_result_qubits, do_swaps=False).inverse().to_gate(), qr_out[:]) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.