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

Remove qiskit.extensions #11488

Merged
merged 13 commits into from
Jan 17, 2024
6 changes: 0 additions & 6 deletions docs/apidoc/extensions.rst
Cryoris marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

111 changes: 0 additions & 111 deletions qiskit/circuit/library/data_preparation/state_preparation.py
Original file line number Diff line number Diff line change
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
Loading