Skip to content
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

Arithmetic circuit library: Adders #6164

Merged
merged 29 commits into from
May 21, 2021
Merged

Arithmetic circuit library: Adders #6164

merged 29 commits into from
May 21, 2021

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Apr 6, 2021

Summary

Part of qiskit-advocate/qamp-spring-21#12 with @mantcep and @ManjulaGandhi.

Add a new circuit library submodule to perform classical addition of two equally-sized
qubit registers including:

Details and comments

Example:

from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import RippleCarryAdder
from qiskit.quantum_info import Statevector

# a encodes |01> = 1
a = QuantumCircuit(2)
a.x(0)

# b encodes |10> = 2
b = QuantumCircuit(2)
b.x(1)

# adder on 2-bit numbers
adder = RippleCarryAdder(2)

# add the state preparations to the front of the circuit
adder.compose(a, [0, 1], inplace=True, front=True)
adder.compose(b, [2, 3], inplace=True, front=True)

# simulate and get the state of all qubits
sv = Statevector(adder)
counts = sv.probabilities_dict()
state = list(counts.keys())[0]  # we only have a single state

# skip the input carry (first bit) and the register |a> (last two bits)
result = state[1:-2]
print(result)  # '011' = 3 = 1 + 2

mantcep and others added 9 commits March 28, 2021 17:21
* Implement initial draft of ripple-carry adder circuit

* Switch to ancilla register for ancilla qubits

* Remove padding for simpler implementation

* Add small fixes from review

* Add initial unit tests

Co-authored-by: Julien Gacon <[email protected]>

* Switch carry out from ancilla to usual register

* Update __init__ docstring with raises

* Add suggestions from review; Clean-up

Co-authored-by: Julien Gacon <[email protected]>

* Add additional test for ripple-carry adder

Co-authored-by: Julien Gacon <[email protected]>
* Implement initial draft of ripple-carry adder circuit

* Switch to ancilla register for ancilla qubits

* Remove padding for simpler implementation

* Add small fixes from review

* Add initial unit tests

Co-authored-by: Julien Gacon <[email protected]>

* Switch carry out from ancilla to usual register

* Update __init__ docstring with raises

* Add suggestions from review; Clean-up

Co-authored-by: Julien Gacon <[email protected]>

* Add additional test for ripple-carry adder

* Implement initial QFT adder circuit

Co-authored-by: Julien Gacon <[email protected]>

* Fix QFT adder carry out; Switch to non-modular as default

* Expand adder tests with QFT adder

* Rename test_adder.py -> test_adders.py

* Include additional QFT adder documentation

* Fix typos

* Fix documentation math

Co-authored-by: Julien Gacon <[email protected]>

* Add non-modular test as default

Co-authored-by: Julien Gacon <[email protected]>

* Remove duplicate file after merge

Co-authored-by: Julien Gacon <[email protected]>
* empty

* empty

* Implemented classical adder in QFT paper

* Implemented classical adder in QFT paper

* fix classicaladd imports

* fix missing imports

* Added the tests part for ClassicalAdd

* move cin to bottom

* Updated the documentation and test parts for ClassicalAdder

* Updated init files

* Deleted adder folder from the git repository

* Deleted test_classicaladd.py

* Deleted old classicaladder file

* Deleted __init__.py file from repository

* Updated classical_adder file

Co-authored-by: Cryoris <[email protected]>
Co-authored-by: Julien Gacon <[email protected]>
@Cryoris Cryoris requested a review from a team as a code owner April 6, 2021 12:55
@Cryoris Cryoris added the Changelog: New Feature Include in the "Added" section of the changelog label Apr 6, 2021
Cryoris added 5 commits April 20, 2021 09:08
* modular RippleCarryAdder
* test that ancillas are uncomputed
* fix ClassicalAdder ancilla uncompute
* replace all to_instruction by to_gate
Copy link
Member

@ajavadia ajavadia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes on naming:

  • The classical adder has been called "Plain Adder" here - fig 2. I think that's better than "classical" because many adders are classical circuits (it is just called "classical" in Draper's paper to contrast it with the quantum-ness of QFT).

  • It is customary for these adders to be referred to by their author's names. So for example the ripple-carry one you have here is often referred to as Cuccaro's adder or CDKM adder (there are other ripple carry adders e.g. VBE adder or TTK adder). Similarly the QFT one is often referred to as Draper's adder. Although I like the idea of a descriptive name also. How about
    CuccaroRippleCarryAdder and DraperQFTAdder?

test/python/circuit/library/test_adders.py Outdated Show resolved Hide resolved
test/python/circuit/library/test_adders.py Outdated Show resolved Hide resolved
test/python/circuit/library/test_adders.py Outdated Show resolved Hide resolved
qiskit/circuit/library/arithmetic/adders/qft_adder.py Outdated Show resolved Hide resolved
ajavadia
ajavadia previously approved these changes May 20, 2021
@mergify mergify bot merged commit 9efd63d into Qiskit:main May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants