Skip to content

Commit

Permalink
blacked state_preparation.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Hirmay authored Jul 2, 2024
1 parent 1bac836 commit 9fc282e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions qiskit/circuit/library/data_preparation/state_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ class UniformSuperpositionGate(Gate):
This gate is used to create the uniform superposition state
:math:`\frac{1}{\sqrt{M}} \sum_{j=0}^{M-1} |j\rangle` when it acts on an input
state :math:`|0...0\rangle`. Note, that `M` is not required to be
a power of 2, in which case the uniform superposition could be
state :math:`|0...0\rangle`. Note, that `M` is not required to be
a power of 2, in which case the uniform superposition could be
prepared by a single layer of Hadamard gates.
.. note::
This class uses the Shukla-Vedula algorithm [1], which only needs
:math:`O(\log_2 (M))` qubits and :math:`O(\log_2 (M))` gates,
:math:`O(\log_2 (M))` qubits and :math:`O(\log_2 (M))` gates,
to prepare the superposition.
**References:**
Expand All @@ -280,7 +280,7 @@ def __init__(
states have zero amplitudes. Here M need not be an integer power of 2.
num_qubits (int):
A positive integer representing the number of qubits used. If num_qubits is None
A positive integer representing the number of qubits used. If num_qubits is None
or is not specified, then num_qubits is set to ceil(log2(num_superpos_states)).
Raises:
Expand All @@ -299,7 +299,7 @@ def __init__(
super().__init__("USup", num_qubits, [num_superpos_states])

def _define(self):

qc = QuantumCircuit(self._num_qubits)

num_superpos_states = self.params[0]
Expand All @@ -323,14 +323,14 @@ def _define(self):
if l_value[0] > 0: # if num_superpos_states is even
qc.h(range(l_value[0]))
qc.ry(theta, l_value[1])
qc.ch(l_value[1], range(l_value[0],l_value[1]), ctrl_state="0")
qc.ch(l_value[1], range(l_value[0], l_value[1]), ctrl_state="0")

for m in range(1, len(l_value) - 1):
theta = -2 * np.arccos(
np.sqrt(2 ** l_value[m] / (num_superpos_states - m_current_value))
)
qc.cry(theta, l_value[m], l_value[m + 1], ctrl_state="0")
qc.ch(l_value[m + 1], range(l_value[m],l_value[m + 1]), ctrl_state="0")
qc.ch(l_value[m + 1], range(l_value[m], l_value[m + 1]), ctrl_state="0")
m_current_value = m_current_value + 2 ** l_value[m]

self.definition = qc

0 comments on commit 9fc282e

Please sign in to comment.