Skip to content

Conversation

@dwierichs
Copy link
Contributor

@dwierichs dwierichs commented Jan 10, 2026

Context:
Currently, OutMultiplier is implemented via doubly-controlled sequences of PhaseAdders and QFTs.

Description of the Change:
Implement the "textbook" variant of multiplication as performed by hand. This uses SemiAdders instead.

Benefits:
Significantly cheaper quantum cost of OutMultiplier, as long as num_y_wires zeroed auxiliary wires are available.
See below for an example.

Possible Drawbacks:
N/A

Related GitHub Issues:

import pennylane as qml
from pennylane.templates.subroutines.arithmetic.out_multiplier import _out_multiplier_decomposition, _out_multiplier_with_adders

qml.decomposition.enable_graph()
k = 4
x_wires = list(range(k))
y_wires = list(range(k, 2*k))
out_wires = list(range(2*k, 4*k))
work_wires = list(range(4*k, 5*k))

gate_set_phase_adder = {
    "QFT",
    "Adjoint(QFT)",
    "C(PhaseShift)",
    "CNOT",
    "PauliX",
}

gate_set_adder = {
    "Toffoli",
    "TemporaryAND",
    "Adjoint(TemporaryAND)",
    "CNOT", 
    "Hadamard",
}

@qml.transforms.decompose(gate_set=gate_set_phase_adder)
@qml.qnode(qml.device("null.qubit", wires=5*k))
def func_phase_adder(k):
    _out_multiplier_decomposition(x_wires, y_wires, out_wires, work_wires=work_wires, mod=None)

@qml.transforms.decompose(gate_set=gate_set_adder)
@qml.qnode(qml.device("null.qubit", wires=5*k))
def func_adder(k):
    _out_multiplier_with_adders(x_wires, y_wires, out_wires, work_wires=work_wires, mod=None)
>>> print("Resources for phase-adder implementation:")
>>> print(qml.specs(func_phase_adder)(k)["resources"].gate_types)
>>> print("Resources for adder implementation:")
>>> print(qml.specs(func_adder)(k)["resources"].gate_types)
Resources for phase-adder implementation:
{'QFT': 1, '2C(PhaseShift)': 2025, 'Adjoint(QFT)': 1}
Resources for adder implementation:
{'TemporaryAND': 16, 'CNOT': 72, 'Toffoli': 20, 'Adjoint(TemporaryAND)': 16}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants