1
$\begingroup$

Assuming I have $n$ qubits and I want to create a superposition out of a subset of integers:$$k∈\{1,...,2^n\},$$ how can I create a circuit that creates a uniform superposition of, for example, $k = 3$ and what would this look like? All the qubits are initialized in the state $|0\rangle$.

$$ |\psi\rangle = \frac{1}{\sqrt{k}}\sum_{j=0}^{k-1}|j\rangle$$

Fixing $k$ to 3, 5, 7, etc. Can someone give me guidance on how to scale this approach?

$\endgroup$
3
  • $\begingroup$ How do you determine which values are in your subset? Is there some sort of easy to computer function? Or is it just an arbitrarily awkward list? Is it a large subset, or a small one? $\endgroup$
    – DaftWullie
    Sep 19, 2023 at 14:46
  • $\begingroup$ The subset follows the summation I posted, e.g. I can pick any number of qubits, say n=3. Then I fix any subset of the bits, e.g. k=3. Based on this, I'd want to create the following state: 1/sqrt(3)*(|000> + |001> + |011>). If I fix k = 5, I build a new circuit to get the following state: 1/sqrt(5)*(|000> + |001> + |010> + |011> + |100>) $\endgroup$
    – letsgetraw
    Sep 19, 2023 at 14:56
  • $\begingroup$ @CraigGidney I appreciate the link but my knowledge of quantum circuits is too little to benefit from understanding this. $\endgroup$
    – letsgetraw
    Sep 20, 2023 at 7:23

1 Answer 1

3
$\begingroup$

Perhaps the easiest way is to find $n=\lceil\log_2(k+1)\rceil$. Take $n$ qubits in the state $|0\rangle$ and apply Hadamard to each of them.

If $k+1$ was a power of 2, you're done! If not, get an ancilla, and implement some logic that flips the ancilla to 1 if the number stored in your set of $n$ qubits is bigger than $k-1$. Finally, measure the ancilla. If it's $|0\rangle$, you're done. This happens with a probability of at least 50%. If not, throw everything away and start again. On average, you require fewer than 2 goes to prepare your state.

How does the logic work for setting the ancilla? Worst case, you've got a list of numbers $k$ to $2^n-1$. For each of them, do an $n$-controlled-not to detect the presence of that specific number, and target the ancilla if that number is present. But you can save quite a lot of logic with a bit of care. For example, if you don't want either $2^n-1$ or $2^n-2$, you can do a multi-controlled-not off the $n-1$ most significant bits, and ignore the least significant bit.

$\endgroup$
2
  • $\begingroup$ link This definitely helps, thanks a lot! Actually, I found another post addressing my question. What I don't understand is how I can determine what angles I have to choose for the rotation. In the link, some (to me) arbitrary angles are chosen to create the superposition I'm looking for. Is there a way to determine them? $\endgroup$
    – letsgetraw
    Sep 20, 2023 at 7:25
  • $\begingroup$ Well you're asking me about a method that is not the method I was suggesting... (mine does not require fancy angles). Nevertheless, what you usually end up doing is grouping terms on a single qubit $|0\rangle|\psi\rangle+|1\rangle|\phi\rangle$. Once you normalise the states, you get coefficients in front of the two terms, and those are basically the values of $\cos\frac{\theta}{2}$ and $\sin\frac{\theta}{2}$ that you're trying to get from a rotation. $\endgroup$
    – DaftWullie
    Sep 20, 2023 at 8:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.