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

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

Closed
Hirmay opened this issue Feb 7, 2024 · 9 comments · Fixed by #12112
Closed
Assignees
Labels
type: feature request New feature or request

Comments

@Hirmay
Copy link
Contributor

Hirmay commented Feb 7, 2024

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

If there's interest, it could be added to the circuit library, since it already some state preparation logic example.

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

@Hirmay
Copy link
Contributor Author

Hirmay commented Mar 12, 2024

Should I close the issue @woodsp-ibm , because it does not seem people are interested unfortunately.

@woodsp-ibm
Copy link
Member

@Hirmay Is this something you would want to contribute an implementation is it's wanted?

@jakelishman @mtreinish I had suggested the author create this as a feature request here - they had done so originally in qiskit algorithms but to me this looked more fundamental something perhaps that circuit library could have, analogous to the StatePreparation there. Do you think this is something that would be of interest here, assuming an implementation was consistent with other library circuits, rather than perhaps just the function shown above. or should they just go ahead and close this off.

@Hirmay
Copy link
Contributor Author

Hirmay commented Mar 12, 2024

Certainly, it would be interesting to contribute an implementation that aligns with other library circuits. However, having someone with experience in these matters join me could expedite the process.

@jakelishman
Copy link
Member

This is the kind of thing I'd usually think of Julien (@Cryoris) to supervise, but since he's on leave for the time being, I can try and do my best Julien impression.

I think this equal-superpositions creation could have a sensible place in qiskit.circuit.library.data_preparation. It's a specialised sort of state preparation, so by analogy to the general StatePreparation class, I think this could be accepted into the circuit library as a Gate called EqualSuperposition or something similar, with the algorithm here as the base _define method.

@Hirmay
Copy link
Contributor Author

Hirmay commented Mar 16, 2024

Hi @jakelishman, could you please advise on my next steps? Should I proceed with modifying the code to create a Gate called EqualSuperposition, or should I wait for @Cryoris?

@woodsp-ibm
Copy link
Member

woodsp-ibm commented Mar 16, 2024

@Hirmay my suggestion, given its not a whole lot of code, and probably relatively quick to do something based on what you had done, would be to take a shot at it and create some code as suggested. Take a look at StatePreparation as a reference for how things are done like that. You can do a PR and mark it Draft, to indicate its not yet ready. Having concrete code to look at will enable someone to give more relevant feedback and it will help you understand what is there, and if not, it's likely to be something more specific that's easier to address. If it turns out fine it would need unit test(s) - you could already add some at this draft stage to show things working. And eventually it would need a release note - but that can come later once its more ready.

Does that sound ok?

@Hirmay
Copy link
Contributor Author

Hirmay commented Mar 17, 2024

Okay, @woodsp-ibm, sounds good! Thanks for your helpful suggestion!

@Cryoris
Copy link
Contributor

Cryoris commented Jun 5, 2024

@jakelishman's impression is on point, thanks for opening the PR @Hirmay ! 🙂

@Hirmay
Copy link
Contributor Author

Hirmay commented Jun 5, 2024

Pleasure is all mine, @Cryoris! In the PR done under the guidance of Steve, I have incorporated all the changes that Jake suggested, but he is currently on a vacation. If you get time, can you please review the PR? Otherwise, I'll wait for Jake to return.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants