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

Single-register arithmetic gates #13371

Merged
merged 17 commits into from
Feb 26, 2025
Merged

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Oct 25, 2024

Summary

Part of #13046: Gates for the single-register arithmetic operations.

Details and comments

I'm opening this PR for people to have a look and for more HLS test cases, but this can probably use some more cleanup. Also all the piecewise gates need an auxiliary qubit, which is currently part of the Gate num_qubits but probably shouldn't be and instead be handled by a synthesis plugin.

Since there's already enough for 1.3 I'd suggest we don't include this.

@Cryoris Cryoris added this to the 2.0.0 milestone Oct 25, 2024
@Cryoris Cryoris marked this pull request as ready for review February 11, 2025 17:43
@Cryoris Cryoris requested a review from a team as a code owner February 11, 2025 17:43
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia

Copy link
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

Is there a plan to add deprecation warnings in the related non-gates classes?
Should it be done as part of this PR?

@coveralls
Copy link

coveralls commented Feb 13, 2025

Pull Request Test Coverage Report for Build 13541552394

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 488 of 539 (90.54%) changed or added relevant lines in 17 files are covered.
  • 2260 unchanged lines in 122 files lost coverage.
  • Overall coverage decreased (-0.4%) to 87.873%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/circuit/library/arithmetic/polynomial_pauli_rotations.py 37 38 97.37%
qiskit/circuit/library/arithmetic/weighted_adder.py 10 11 90.91%
qiskit/circuit/library/arithmetic/piecewise_chebyshev.py 41 43 95.35%
qiskit/synthesis/arithmetic/comparators/compare_2s.py 42 45 93.33%
qiskit/synthesis/arithmetic/weighted_sum.py 70 75 93.33%
qiskit/circuit/library/arithmetic/linear_amplitude_function.py 43 49 87.76%
qiskit/transpiler/passes/synthesis/hls_plugins.py 20 26 76.92%
qiskit/circuit/library/arithmetic/exact_reciprocal.py 18 26 69.23%
qiskit/circuit/library/arithmetic/piecewise_polynomial_pauli_rotations.py 50 58 86.21%
qiskit/circuit/library/arithmetic/quadratic_form.py 59 70 84.29%
Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/basis/basis_translator/basis_search.rs 1 99.31%
crates/qasm2/src/expr.rs 1 94.23%
qiskit/circuit/add_control.py 1 97.78%
qiskit/circuit/controlflow/switch_case.py 1 95.35%
qiskit/circuit/library/arithmetic/exact_reciprocal.py 1 60.98%
qiskit/circuit/library/standard_gates/r.py 1 97.62%
qiskit/circuit/library/standard_gates/rxx.py 1 97.78%
qiskit/circuit/library/standard_gates/rzx.py 1 97.78%
qiskit/circuit/library/standard_gates/u2.py 1 96.88%
qiskit/circuit/random/utils.py 1 94.87%
Totals Coverage Status
Change from base Build 13268699272: -0.4%
Covered Lines: 77530
Relevant Lines: 88230

💛 - Coveralls

@Cryoris
Copy link
Contributor Author

Cryoris commented Feb 13, 2025

Is there a plan to add deprecation warnings in the related non-gates classes?

We cannot deprecate them yet as the alternative has not been available for 1 release. I'd suggest we handle it like the PhaseOracle and add deprecation warnings for 2.1 with removal for 3.0.

Copy link
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

minor misprints

@ShellyGarion
Copy link
Member

You should also add release notes. Could you explain there why gates are better than quantum circuits?

Copy link
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

looks good. I have some comments on the docs.
Also - are there test for exact reciprocal gate? linear pauli rotation gate?
piecewise polynomial pauli rotation gate? polynomial pauli rotation gate

* :class:`.IntegerComparatorGate` (replacing :class:`.IntegerComparator`)
* :class:`.LinearPauliRotationsGate` (replacing :class:`.LinearPauliRotations`)
* :class:`.PiecewiseLinearPauliRotationsGate` (replacing :class:`.PiecewiseLinearPauliRotations`)
* :class:`.PiecewiseChebychevGate` (replacing :class:`.PiecewiseChebychev`)
Copy link
Member

Choose a reason for hiding this comment

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

there is a misprint here. should be "PiecewiseChebyshev" and not "PiecewiseChebychev"

self.breakpoints = breakpoints if breakpoints is not None else [0]

num_compare = 0 if breakpoints is None else int(len(breakpoints) > 1)
super().__init__("PiecewiseChebychev", num_state_qubits + num_compare + 1, [], label)
Copy link
Member

Choose a reason for hiding this comment

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

there is a misprint here. should be "PiecewiseChebyshev" and not "PiecewiseChebychev"

@@ -259,6 +259,7 @@
:template: autosummary/class_no_inherited_members.rst

LinearAmplitudeFunction
LinearAmplitudeFunctionGate
Copy link
Member

Choose a reason for hiding this comment

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

the class "FunctionalPauliRotations" should not be a gate? it's just a base class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the methods it provided are not really necessary anymore now that the objects are not BlueprintCircuits anymore, so it doesn't need a new equivalent 🙂

positive. For the negative case it is assumed that the remaining string represents
:math:`1 - x`. This is because :math:`e^{-2 \pi i x} = e^{2 \pi i (1 - x)}` for
:math:`x \in [0,1)`.
name: The name of the object.
Copy link
Member

Choose a reason for hiding this comment

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

here it should be label and not name

@@ -0,0 +1,17 @@
---
features_circuits:
Copy link
Member

Choose a reason for hiding this comment

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

you should also mention here the synthesis functions (Unary Arithmetic Synthesis) and the HLS plugins (Integer comparators, Sums).


.. autofunction:: synth_integer_comparator_2s
.. autofunction:: synth_integer_comparator_greedy

Copy link
Member

Choose a reason for hiding this comment

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

the function synth_weighted_sum_carry does not appear in the docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be there, see L157 🙂

Copy link
Member

@ShellyGarion ShellyGarion Feb 24, 2025

Choose a reason for hiding this comment

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

Another comment: it seems that the names of these functions do not comply with the naming convention in the synthesis library, which usually include the authors' initials and the year. what do you think?
(this convention is usually useful if there are several synthesis methods of the same object).

- Description
- Auxiliary qubits
* - ``"default"``
- :class:`~.WeightedSumSynthesisDefault`
Copy link
Member

Choose a reason for hiding this comment

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

the link does not work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, this is missing in the toctree, I'll add it 👍🏻

from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import (
LinearPauliRotations,
PolynomialPauliRotations,
PiecewiseLinearPauliRotations,
PiecewiseLinearPauliRotationsGate,
Copy link
Member

Choose a reason for hiding this comment

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

should there be a test for LinearPauliRotationsGate ? PolynomialPauliRotations ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that'd be good, we can extend the tests for the PiecewiseLinearPauliRotationGate to also check others.

@ShellyGarion ShellyGarion added this pull request to the merge queue Feb 26, 2025
Merged via the queue into Qiskit:main with commit 0e824cc Feb 26, 2025
19 checks passed
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.

4 participants