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

Move PendingDeprecations to Deprecations in the circuit library #13604

Open
wants to merge 43 commits into
base: main
Choose a base branch
from

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Dec 24, 2024

Summary

The circuit library modernization from #13046 introduced some pending deprecations that this PR is moving to deprecations.

reno is still missing.

@Cryoris
Copy link
Contributor

Cryoris commented Feb 7, 2025

We could just have a single reno for the deprecation of BlueprintCircuit and mention the deprecation of all subclasses therein. That would be a bit cleaner for the users than having multiple 🙂

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of this, this LGTM but it seems to only miss the catches in the tests 🙂

@1ucian0 1ucian0 changed the base branch from stable/1.4 to main February 10, 2025 13:19
@1ucian0 1ucian0 linked an issue Feb 15, 2025 that may be closed by this pull request
@1ucian0 1ucian0 self-assigned this Feb 20, 2025
@1ucian0 1ucian0 added this to the 2.0.0 milestone Feb 20, 2025
@1ucian0
Copy link
Member Author

1ucian0 commented Feb 20, 2025

Most of the problems are coming from an internal call to a deprecated method:

qiskit/circuit/library/standard_gates/x.py", line 1148, in __init__
    num_ancilla_qubits = self.__class__.get_num_ancilla_qubits(num_ctrl_qubits)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

There is also some issues with BlueprintCircuit subclasses. From @Cryoris :

There's currently 5 subclasses:
QFT and NLocal are already deprecated
all others should be taken care of by #13371

Still working on the rest.

@1ucian0 1ucian0 added the on hold Can not fix yet label Feb 20, 2025
@1ucian0 1ucian0 marked this pull request as ready for review March 4, 2025 16:40
@1ucian0 1ucian0 requested review from a team as code owners March 4, 2025 16:40
@qiskit-bot
Copy link
Collaborator

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

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia
  • @levbishop
  • @mtreinish
  • @nkanazawa1989
  • @t-imamichi

@1ucian0 1ucian0 modified the milestones: 2.0.0, 2.1.0 Mar 4, 2025
@coveralls
Copy link

coveralls commented Mar 4, 2025

Pull Request Test Coverage Report for Build 13919787623

Details

  • 99 of 111 (89.19%) changed or added relevant lines in 11 files are covered.
  • 18 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.01%) to 88.073%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/circuit/quantumcircuit.py 36 41 87.8%
qiskit/circuit/library/standard_gates/x.py 28 35 80.0%
Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/unitary_synthesis.rs 1 94.69%
qiskit/circuit/quantumcircuit.py 1 93.78%
crates/qasm2/src/lex.rs 4 92.48%
crates/qasm2/src/parse.rs 12 97.15%
Totals Coverage Status
Change from base Build 13905217637: -0.01%
Covered Lines: 72650
Relevant Lines: 82488

💛 - Coveralls

Copy link
Member

@alexanderivrii alexanderivrii left a comment

Choose a reason for hiding this comment

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

Thanks for the massive effort. I am definitely looking forward to not see BlueprintCircuit and MCXGrayCode in Qiskit 3.0. I have left some questions and comments in-place.

Comment on lines +267 to +275

with warnings.catch_warnings(action="ignore", category=DeprecationWarning):
circuit.mcx(
[q_state, qr_sum[j], qr_carry[j - 1]],
qr_carry[j],
qr_control,
mode="v-chain",
)

Copy link
Member

Choose a reason for hiding this comment

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

Do I understand correctly that we need catch_warnings here because we are deprecating the argument mode in QuantumCircuit.mcx(...)? On the other hand, do we really need this -- as the whole class WeightedAdder is being deprecated? Note that these are only questions, I am not asking for any actual changes.

Comment on lines +346 to +347
with warnings.catch_warnings(action="ignore", category=DeprecationWarning):
self.append(circuit.to_gate(), self.qubits)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to catch_warnings here?

Comment on lines +79 to 85
since="1.4",
additional_msg=(
"Use qiskit.circuit.library.QFTGate or qiskit.synthesis.qft.synth_qft_full instead, "
"for access to all previous arguments.",
),
pending=True,
)
def __init__(
Copy link
Member

Choose a reason for hiding this comment

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

Do I understand correctly that technically we do not need this deprecation message -- as we are deprecating the base BlueprintCircuit class?

Comment on lines -46 to -53
since="1.3",
since="1.4",
additional_msg=(
"Use the adder gates provided in qiskit.circuit.library.arithmetic instead. "
"The gate type depends on the adder kind: fixed, half, full are represented by "
"ModularAdderGate, HalfAdderGate, FullAdderGate, respectively. For different adder "
"implementations, see https://docs.quantum.ibm.com/api/qiskit/synthesis.",
),
pending=True,
Copy link
Member

Choose a reason for hiding this comment

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

Some other similar deprecation messages include the argument

removal_timeline="in Qiskit 3.0",

Would it be more consistent to add a similar argument here and other similar messages?

Comment on lines -154 to +153
num_variable_qubits: The qubits of which the AND is computed. The result will be written
num_variable_qubits: The qubits of which the OR is computed. The result will be written
Copy link
Member

Choose a reason for hiding this comment

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

nice catch (better late than never) 😄

Comment on lines +4860 to +4861
else:
self.compose(synth_mcx_n_clean_m15(len(control_qubits)), inplace=True)
Copy link
Member

Choose a reason for hiding this comment

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

same concern about correctness here

Comment on lines +5716 to +5724
@deprecate_arg(
name="mode",
since="2.0",
additional_msg=(
"Instead, add a generic MCXGate to the circuit and specify the synthesis method "
"via the ``hls_config`` in the transpilation. Alternatively, specific decompositions "
"are available at https://qisk.it/mcx."
),
)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we also deprecate the argument ancilla_qubits?

Comment on lines +25 to +26
* :class:`.QuantumVolume` ``-->`` :func:`.quantum_volume`
* :class:`.EvolvedOperatorAnsatz` ``-->`` :func:`.evolved_operator_ansatz`
Copy link
Member

Choose a reason for hiding this comment

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

Should we also mention the deprecation of MCX variants in the release notes, as well as arguments to QuantumCircuit.mcx(...)?

Comment on lines -775 to +791
MCXVChain(num_ctrl_qubits, True),
for synth_circuit in [
synth_mcx_n_dirty_i15(num_ctrl_qubits),
synth_mcx_n_clean_m15(num_ctrl_qubits),
synth_mcx_1_clean_b95(num_ctrl_qubits),
synth_mcx_gray_code(num_ctrl_qubits),
synth_mcx_noaux_v24(num_ctrl_qubits),
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this test? Previously we checked that adding custom MCX variants worked correctly, but now we are checking correctness of synthesis methods, and this does not seem the right place to do that, do you agree?

corrected = np.zeros(2 ** (num_ctrl_qubits + 1), dtype=complex)
for i, statevector_amplitude in enumerate(statevector):
i = int(bin(i)[2:].zfill(circuit.num_qubits)[gate.num_ancilla_qubits :], 2)
i = int(bin(i)[2:].zfill(circuit.num_qubits)[num_ancillas:], 2)
corrected[i] += statevector_amplitude
statevector = corrected
np.testing.assert_array_almost_equal(statevector.real, reference)

@data(5, 10, 15)
def test_mcxvchain_dirty_ancilla_cx_count(self, num_ctrl_qubits):
Copy link
Member

Choose a reason for hiding this comment

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

More tests that can be removed (I think) especially given #13961. Or actually shouldn't we keep the original test with the MCXVChain gate, that was deprecated but not yet removed? (The same comment applies to other changes in this file).

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.

Deprecate BlueprintCircuit in 2.0 Deprecate in 1.4 the pending deprecations from the 1.* cycle
5 participants