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

Minor fixes for new adder and multiplier gates classes #13530

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions qiskit/circuit/library/arithmetic/adders/adder.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,5 @@ def _define(self):
"""Populates self.definition with a decomposition of this gate."""
from qiskit.synthesis.arithmetic import adder_ripple_c04

# In the case of a full adder, this method does not use any ancilla qubits
self.definition = adder_ripple_c04(self.num_state_qubits, kind="full")
Cryoris marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion qiskit/transpiler/passes/synthesis/hls_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,9 @@ def run(self, high_level_object, coupling_map=None, target=None, qubits=None, **
return decomposition

# The QFT-based adder does not require ancilla qubits and should always succeed
return HalfAdderSynthesisD00.run(high_level_object, coupling_map, target, qubits, **options)
return HalfAdderSynthesisD00().run(
high_level_object, coupling_map, target, qubits, **options
)


class HalfAdderSynthesisC04(HighLevelSynthesisPlugin):
Expand Down
19 changes: 9 additions & 10 deletions releasenotes/notes/fix-adder-gates-39cf3d5f683e8880.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
---
features_transpiler:
- |
Added :class:`.FullAdderSynthesisDefault` plugin that chooses the best decomposition
for :class:`.FullAdderGate` based on the number of clean ancilla qubits
available.
- |
Improved :class:`.HalfAdderSynthesisDefault` and :class:`.ModularAdderSynthesisDefault`
plugins for :class:`.HalfAdderGate` and :class:`.ModularAdderGate` respectively,
choosing the best decomposition based on the number of clean ancilla qubits available.
fixes:
- |
Adding default definitions for :class:`.FullAdderGate`, :class:`.HalfAdderGate`,
Added default definitions for :class:`.FullAdderGate`, :class:`.HalfAdderGate`,
:class:`.ModularAdderGate` and :class:`.MultiplierGate` gates, allowing to
contruct :class:`qiskit.quantum_info.Operator`\s from quantum circuits
Cryoris marked this conversation as resolved.
Show resolved Hide resolved
containing these gates.
- |
Fixed the number of clean ancilla qubits required by
:class:`.FullAdderSynthesisV95`, :class:`.HalfAdderSynthesisV95`, and
:class:`.ModularAdderSynthesisV95` plugins.
- |
Added missing :class:`.FullAdderSynthesisDefault` plugin that chooses the best
decomposition for :class:`.FullAdderGate` based on the number of clean ancilla qubits
available.
- |
Fixed :class:`.HalfAdderSynthesisDefault` and :class:`.ModularAdderSynthesisDefault`
plugins, for :class:`.HalfAdderGate` and :class:`.ModularAdderGate` respectively,
to choose the best decomposition based on the number of clean ancilla qubits available.
51 changes: 51 additions & 0 deletions test/python/circuit/library/test_adders.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,57 @@ def test_plugins_when_do_not_apply(self):
synth = hls(circuit)
self.assertEqual(synth.count_ops(), {"ModularAdder": 1})

def test_default_plugins(self):
"""Tests covering different branches in the default synthesis plugins.."""
with self.subTest(name="HalfAdderTest1"):
adder = HalfAdderGate(3)
circuit = QuantumCircuit(9)
circuit.append(adder, range(7))
hls = HighLevelSynthesis()
_ = hls(circuit)
Cryoris marked this conversation as resolved.
Show resolved Hide resolved
with self.subTest(name="HalfAdderTest2"):
adder = HalfAdderGate(4)
circuit = QuantumCircuit(12)
circuit.append(adder, range(9))
hls = HighLevelSynthesis()
_ = hls(circuit)
with self.subTest(name="HalfAdderTest3"):
adder = HalfAdderGate(4)
circuit = QuantumCircuit(9)
circuit.append(adder, range(9))
hls = HighLevelSynthesis()
_ = hls(circuit)
with self.subTest(name="FullAdderTest1"):
adder = FullAdderGate(4)
circuit = QuantumCircuit(10)
circuit.append(adder, range(10))
hls = HighLevelSynthesis()
_ = hls(circuit)
with self.subTest(name="FullAdderTest2"):
adder = FullAdderGate(1)
circuit = QuantumCircuit(10)
circuit.append(adder, range(4))
hls = HighLevelSynthesis()
_ = hls(circuit)
with self.subTest(name="ModularAdderTest1"):
adder = ModularAdderGate(4)
circuit = QuantumCircuit(8)
circuit.append(adder, range(8))
hls = HighLevelSynthesis()
_ = hls(circuit)
with self.subTest(name="ModularAdderTest2"):
adder = ModularAdderGate(6)
circuit = QuantumCircuit(12)
circuit.append(adder, range(12))
hls = HighLevelSynthesis()
_ = hls(circuit)
with self.subTest(name="ModularAdderTest3"):
adder = ModularAdderGate(6)
circuit = QuantumCircuit(16)
circuit.append(adder, range(12))
hls = HighLevelSynthesis()
_ = hls(circuit)


if __name__ == "__main__":
unittest.main()
Loading