-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Deprecate qiskit.extensions
#10725
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
Deprecate qiskit.extensions
#10725
Changes from all commits
29cc524
9e000bb
1afc35c
5fe1a8b
4ffea01
ec48a1b
90ffaf2
3a988da
dd47bde
f9112a3
26e0683
5f672b7
53991db
30f787a
1503f06
ee7d4d3
9d8915b
0f97a95
1013c38
1e7c72e
7b09ab4
3e92ab3
1accd97
80ace24
e2e7807
4bd902b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,9 +66,6 @@ | |
| # user config | ||
| from qiskit import user_config as _user_config | ||
|
|
||
| # The qiskit.extensions.x imports needs to be placed here due to the | ||
| # mechanism for adding gates dynamically. | ||
| import qiskit.extensions | ||
|
Comment on lines
-69
to
-71
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this in conjunction with all the rest of the work on removing uses of import qiskit
qiskit.extensions.CXGatewould have worked without error before, and now it'll say AttributeError: module 'qiskit' has no attribute 'extensions'and require you to do That's minor and we can probably get away with it, but it was a dedicated submodule that was previously automatically imported, so just pointing out that these removals can cause issues. |
||
| import qiskit.circuit.measure | ||
| import qiskit.circuit.reset | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,6 +181,7 @@ | |
| :template: autosummary/class_no_inherited_members.rst | ||
|
|
||
| Diagonal | ||
| DiagonalGate | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would've liked to deprecate this as the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo it should be the circuit that gets removed not the gate, since circuits inherently define an eager synthesis, but that's not important.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, maybe this would best be part of an overhaul to consistently use Gate or Circuits (probably the first) 🙂
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that this is quite confusing. Maybe it's worth to add a comment somewhere about the difference between them, and which one will be deprecated?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we had the plans to deprecate |
||
| MCMT | ||
| MCMTVChain | ||
| Permutation | ||
|
|
@@ -198,6 +199,13 @@ | |
| RVGate | ||
| PauliGate | ||
| LinearFunction | ||
| Isometry | ||
| UnitaryGate | ||
| UCGate | ||
| UCPauliRotGate | ||
| UCRXGate | ||
| UCRYGate | ||
| UCRZGate | ||
|
|
||
| Boolean Logic Circuits | ||
| ====================== | ||
|
|
@@ -324,6 +332,7 @@ | |
| PhaseOracle | ||
| EvolvedOperatorAnsatz | ||
| PauliEvolutionGate | ||
| HamiltonianGate | ||
|
|
||
|
|
||
| N-local circuits | ||
|
|
@@ -360,6 +369,7 @@ | |
| ZFeatureMap | ||
| ZZFeatureMap | ||
| StatePreparation | ||
| Initialize | ||
|
|
||
| Template circuits | ||
| ================= | ||
|
|
@@ -492,6 +502,7 @@ | |
| from .blueprintcircuit import BlueprintCircuit | ||
| from .generalized_gates import ( | ||
| Diagonal, | ||
| DiagonalGate, | ||
| MCMT, | ||
| MCMTVChain, | ||
| Permutation, | ||
|
|
@@ -505,8 +516,16 @@ | |
| RVGate, | ||
| PauliGate, | ||
| LinearFunction, | ||
| Isometry, | ||
| UnitaryGate, | ||
| UCGate, | ||
| UCPauliRotGate, | ||
| UCRXGate, | ||
| UCRYGate, | ||
| UCRZGate, | ||
| ) | ||
|
ShellyGarion marked this conversation as resolved.
|
||
| from .pauli_evolution import PauliEvolutionGate | ||
| from .hamiltonian_gate import HamiltonianGate | ||
| from .boolean_logic import ( | ||
| AND, | ||
| OR, | ||
|
|
@@ -542,7 +561,13 @@ | |
| ExcitationPreserving, | ||
| QAOAAnsatz, | ||
| ) | ||
| from .data_preparation import PauliFeatureMap, ZFeatureMap, ZZFeatureMap, StatePreparation | ||
| from .data_preparation import ( | ||
| PauliFeatureMap, | ||
| ZFeatureMap, | ||
| ZZFeatureMap, | ||
| StatePreparation, | ||
| Initialize, | ||
| ) | ||
| from .quantum_volume import QuantumVolume | ||
| from .fourier_checking import FourierChecking | ||
| from .graph_state import GraphState | ||
|
|
||
|
Cryoris marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2017. | ||
| # | ||
| # This code is licensed under the Apache License, Version 2.0. You may | ||
| # obtain a copy of this license in the LICENSE.txt file in the root directory | ||
| # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
| # | ||
| # Any modifications or derivative works of this code must retain this | ||
| # copyright notice, and modified files need to carry a notice indicating | ||
| # that they have been altered from the originals. | ||
|
|
||
| """ | ||
| Initialize qubit registers to desired arbitrary state. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
| from collections.abc import Sequence | ||
| import typing | ||
|
|
||
| from qiskit.circuit.quantumcircuit import QuantumCircuit | ||
| from qiskit.circuit.quantumregister import QuantumRegister | ||
| from qiskit.circuit.instruction import Instruction | ||
| from .state_preparation import StatePreparation | ||
|
|
||
| if typing.TYPE_CHECKING: | ||
| from qiskit.quantum_info.states.statevector import Statevector | ||
|
|
||
| _EPS = 1e-10 # global variable used to chop very small numbers to zero | ||
|
|
||
|
|
||
| class Initialize(Instruction): | ||
| """Complex amplitude initialization. | ||
|
|
||
| Class that initializes some flexible collection of qubit registers, implemented by calling | ||
| the :class:`~.library.StatePreparation` class. | ||
| Note that ``Initialize`` is an :class:`~.circuit.Instruction` and not a :class:`.Gate` since it | ||
| contains a reset instruction, which is not unitary. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| params: Statevector | Sequence[complex] | str | int, | ||
| num_qubits: int | None = None, | ||
| normalize: bool = False, | ||
| ) -> None: | ||
| r""" | ||
| Args: | ||
| params: The state to initialize to, can be either of the following. | ||
|
|
||
| * Statevector or vector of complex amplitudes to initialize to. | ||
| * Labels of basis states of the Pauli eigenstates Z, X, Y. See | ||
| :meth:`.Statevector.from_label`. Notice the order of the labels is reversed with | ||
| respect to the qubit index to be applied to. Example label '01' initializes the | ||
| qubit zero to :math:`|1\rangle` and the qubit one to :math:`|0\rangle`. | ||
| * An integer that is used as a bitmap indicating which qubits to initialize to | ||
| :math:`|1\rangle`. Example: setting params to 5 would initialize qubit 0 and qubit | ||
| 2 to :math:`|1\rangle` and qubit 1 to :math:`|0\rangle`. | ||
|
|
||
| num_qubits: This parameter is only used if params is an int. Indicates the total | ||
| number of qubits in the `initialize` call. Example: `initialize` covers 5 qubits | ||
| and params is 3. This allows qubits 0 and 1 to be initialized to :math:`|1\rangle` | ||
| and the remaining 3 qubits to be initialized to :math:`|0\rangle`. | ||
| normalize: Whether to normalize an input array to a unit vector. | ||
| """ | ||
| self._stateprep = StatePreparation(params, num_qubits, normalize=normalize) | ||
|
|
||
| super().__init__("initialize", self._stateprep.num_qubits, 0, self._stateprep.params) | ||
|
|
||
| def _define(self): | ||
| q = QuantumRegister(self.num_qubits, "q") | ||
| initialize_circuit = QuantumCircuit(q, name="init_def") | ||
| initialize_circuit.reset(q) | ||
| initialize_circuit.append(self._stateprep, q) | ||
| self.definition = initialize_circuit | ||
|
|
||
| def gates_to_uncompute(self) -> QuantumCircuit: | ||
| """Call to create a circuit with gates that take the desired vector to zero. | ||
|
|
||
| Returns: | ||
| Circuit to take ``self.params`` vector to :math:`|{00\\ldots0}\\rangle` | ||
| """ | ||
| return self._stateprep._gates_to_uncompute() | ||
|
|
||
| @property | ||
| def params(self): | ||
| """Return initialize params.""" | ||
| return self._stateprep.params | ||
|
|
||
| @params.setter | ||
| def params(self, parameters: Statevector | Sequence[complex] | str | int) -> None: | ||
| """Set initialize params.""" | ||
| self._stateprep.params = parameters | ||
|
|
||
| def broadcast_arguments(self, qargs, cargs): | ||
| return self._stateprep.broadcast_arguments(qargs, cargs) |
Uh oh!
There was an error while loading. Please reload this page.