Skip to content

Commit

Permalink
Remove qiskit.extensions (Qiskit#11488)
Browse files Browse the repository at this point in the history
* Delete ``qiskit-extensions`` for 1.0

* add reno

* black

* rm deprecate qc methods + extensions mod

* Update reno, remove dangling TeX file

* Lint and latex test

* Try fix docstring, detailed reno

* Update plot barrier test

Snapshot instruction has been removed

* Skip Aer tests that rely on Qiskit/qiskit-aer#2023

* Fix barrier image

* Revert "Skip Aer tests that rely on Qiskit/qiskit-aer#2023"

This reverts commit 5dbe66d.
  • Loading branch information
Cryoris authored Jan 17, 2024
1 parent de7a0b1 commit 27761bd
Show file tree
Hide file tree
Showing 30 changed files with 202 additions and 1,403 deletions.
6 changes: 0 additions & 6 deletions docs/apidoc/extensions.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/apidoc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ API Reference
converters
assembler
dagcircuit
extensions
passmanager
providers_basicaer
providers
Expand Down
113 changes: 1 addition & 112 deletions qiskit/circuit/library/data_preparation/state_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from qiskit.exceptions import QiskitError
from qiskit.circuit.quantumcircuit import QuantumCircuit
from qiskit.circuit.quantumregister import QuantumRegister, Qubit
from qiskit.circuit.quantumregister import QuantumRegister
from qiskit.circuit.gate import Gate
from qiskit.circuit.library.standard_gates.x import CXGate, XGate
from qiskit.circuit.library.standard_gates.h import HGate
Expand Down Expand Up @@ -413,114 +413,3 @@ def _multiplex(self, target_gate, list_of_angles, last_cnot=True):
circuit.append(CXGate(), [msb, lsb])

return circuit


def prepare_state(self, state, qubits=None, label=None, normalize=False):
r"""Prepare qubits in a specific state.
This class implements a state preparing unitary. Unlike
:class:`qiskit.extensions.Initialize` it does not reset the qubits first.
Args:
state (str or list or int or Statevector):
* Statevector: Statevector to initialize to.
* str: 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`.
* list: vector of complex amplitudes to initialize to.
* int: 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`.
qubits (QuantumRegister or Qubit or int):
* QuantumRegister: A list of qubits to be initialized [Default: None].
* Qubit: Single qubit to be initialized [Default: None].
* int: Index of qubit to be initialized [Default: None].
* list: Indexes of qubits to be initialized [Default: None].
label (str): An optional label for the gate
normalize (bool): Whether to normalize an input array to a unit vector.
Returns:
qiskit.circuit.Instruction: a handle to the instruction that was just initialized
Examples:
Prepare a qubit in the state :math:`(|0\rangle - |1\rangle) / \sqrt{2}`.
.. code-block::
import numpy as np
from qiskit import QuantumCircuit
circuit = QuantumCircuit(1)
circuit.prepare_state([1/np.sqrt(2), -1/np.sqrt(2)], 0)
circuit.draw()
output:
.. parsed-literal::
┌─────────────────────────────────────┐
q_0: ┤ State Preparation(0.70711,-0.70711) ├
└─────────────────────────────────────┘
Prepare from a string two qubits in the state :math:`|10\rangle`.
The order of the labels is reversed with respect to qubit index.
More information about labels for basis states are in
:meth:`.Statevector.from_label`.
.. code-block::
import numpy as np
from qiskit import QuantumCircuit
circuit = QuantumCircuit(2)
circuit.prepare_state('01', circuit.qubits)
circuit.draw()
output:
.. parsed-literal::
┌─────────────────────────┐
q_0: ┤0 ├
│ State Preparation(0,1) │
q_1: ┤1 ├
└─────────────────────────┘
Initialize two qubits from an array of complex amplitudes
.. code-block::
import numpy as np
from qiskit import QuantumCircuit
circuit = QuantumCircuit(2)
circuit.prepare_state([0, 1/np.sqrt(2), -1.j/np.sqrt(2), 0], circuit.qubits)
circuit.draw()
output:
.. parsed-literal::
┌───────────────────────────────────────────┐
q_0: ┤0 ├
│ State Preparation(0,0.70711,-0.70711j,0) │
q_1: ┤1 ├
└───────────────────────────────────────────┘
"""

if qubits is None:
qubits = self.qubits
elif isinstance(qubits, (int, np.integer, slice, Qubit)):
qubits = [qubits]

num_qubits = len(qubits) if isinstance(state, int) else None

return self.append(
StatePreparation(state, num_qubits, label=label, normalize=normalize), qubits
)


QuantumCircuit.prepare_state = prepare_state
Loading

0 comments on commit 27761bd

Please sign in to comment.