qiskit-community / qiskit-algorithms

A library of quantum algorithms for Qiskit.
https://qiskit-community.github.io/qiskit-algorithms/
Apache License 2.0
89 stars 43 forks source link

Inclusion of the new efficient algorithm for preparing uniform quantum superposition states. #146

Closed Hirmay closed 4 months ago

Hirmay commented 5 months ago

What should we add?

Recently a novel efficient algorithm was proposed for preparation of uniform quantum superposition states, which was published in Quantum Information Processing journal. The algorithm tries to solve the problem of preparation of a uniform superposition state of the form

$$ | \psi> = \frac{1}{\sqrt{M}} \sum_{j=0}^{M-1} |j>, $$

where $M$ denotes the number of distinct states in the superposition state and $2 ≤ M ≤ 2^n$ . They also show that the superposition state can be efficiently prepared, using a deterministic approach, with a gate complexity and circuit depth of only $O(log_2 M)$ for all $M$. This demonstrates an exponential reduction in gate complexity in comparison with other existing deterministic approaches (including qiskit's) in the literature for the general case of this problem. Another advantage of the proposed approach is that it requires only $n =\lceil log 2 M \rceil$ qubits. Furthermore, neither ancilla qubits nor any quantum gates with multiple controls are needed in their approach for creating the uniform superposition state $|\psi>$.

Below I have provided the implementation of this algorithm.

import numpy as np
from qiskit import QuantumCircuit , QuantumRegister
""" Input: A positive integer M with 2 < M < 2^n, M not equal to 2^r for any natural number r.
Output: A quantum circuit that creates the uniform superposition state: 
$\frac{1}{\sqrt{M}} \sum_{j=0}^{M-1} \ket{j} $. Number of qubits: Using n = np.ceil(np.log2(M)), creates the uniform superposition state with the least number of qubits. 
"""
def uniform_superposition(M, n):
    N = [int(x) for x in list(np.binary_repr(M))][::-1]
    k = len(N)
    L = [index for (index ,item) in enumerate(N) if item ==1] #Locations of '1's
    qreg = QuantumRegister(n, 'q')
    quantum_circuit = QuantumCircuit(qreg)
    quantum_circuit.x(qreg[L[1:k]])
    Mcurrent = 2**(L[0])
    theta = -2*np.arccos(np.sqrt(Mcurrent/M))
    if L[0]>0: #if M is even
        quantum_circuit.h(qreg[0:L[0]])
    quantum_circuit.ry(theta , qreg[L[1]])
    quantum_circuit.ch(qreg[L[1]], qreg[L[0]:L[1]], ctrl_state='0')
    for m in range(1,len(L) -1):
        theta = -2*np.arccos(np.sqrt (2**L[m]/ (M- Mcurrent)))
        quantum_circuit.cry(theta , qreg[L[m]], qreg[L[m+1]], ctrl_state='0')
        quantum_circuit.ch(qreg[L[m+1]], qreg[L[m]:L[m+1]], ctrl_state='0')
        Mcurrent = Mcurrent + 2**(L[m])
    return quantum_circuit

The research paper used for creating this algorithm. -- [An efficient quantum algorithm for preparation of uniform quantum superposition states][1] [1]: Shukla, A., Vedula, P. An efficient quantum algorithm for preparation of uniform quantum superposition states. Quantum Inf Process 23, 38 (2024). https://doi.org/10.1007/s11128-024-04258-4

woodsp-ibm commented 5 months ago

Looks interesting - Qiskit has some state preparation logic eg in the circuit library here https://github.com/Qiskit/qiskit/tree/main/qiskit/circuit/library/data_preparation where perhaps it might suited to make it available via Qiskit. Maybe open an issue there to see if there's interest at that level in having something like this functionality in the circuit library.

Hirmay commented 5 months ago

Thanks for the suggestion, @woodsp-ibm. I'll add an issue there. Do you want me to tag you there? Something along the lines of, According to @ woodsp-ibm, if there's interest, it could be added to the circuit library, since it already some state preparation logic example.

woodsp-ibm commented 4 months ago

Thanks, I'dd add a cross-ref to the issue you created, as I suggested, in Qiskit which is

Me adding the reference will show up in the Qiskit issue so people following the link can see this conversation here. So there should be no need to directly comment there about my suggesting this above

Hirmay commented 4 months ago

Sounds good, thank you! Should I close this Issue here then?

woodsp-ibm commented 4 months ago

As this has been raised now on Qiskit for potential inclusion into the circuit library, where it seems more applicable I am going to close this issue here now.