您可以通过将它们分为三个部分来简化“产生状态”问题:
- 准备所需的量值集合,而不必担心相位或哪个状态具有哪个量值。
- 修复阶段。
- 修正顺序。
现在考虑哈迪状态。我们需要达到什么程度?我们需要一个实例3/12−−√ 和的三个实例 1/12−−√。我们可以通过保持不间断的“剩余振幅”状态来一次制造一个。
我们从处于一个状态的所有振幅开始,向左激励, ℓ0|1000...00⟩ where ℓ0=1. What we want to do is move the excitation rightward while leaving behind the desired magnitudes. So to start we want to leave behind the magnitude 3/12−−√. We can do that with a controlled Ry(θ0) operation, where the control is the leftmost qubit and the target is the qubit just to its right. By picking just the right value for θ, this will result in the state 3/12−−√|1000...00⟩+ℓ1|1100...00⟩. We then CNOT the second qubit back onto the first qubit to get to ℓ1|1000...00⟩+3/12−−√|0100...00⟩. Next we want to pull off 1/12−−√. We perform another Ry controlled by the leftmost qubit followed by a backwards CNOT, but this time with the target is the qubit third from the left. By picking the perfect θ1 we will produce the state ℓ2|1000...00⟩+3/12−−√|0100...00⟩+1/12−−√ℓ2|0010...00⟩. And you just keep doing this until you've got all the amplitudes you need, conveniently addressed by individual qubits being excited.
Now you want to fix any incorrect phases produced by the Y rotations. For the Hardy state this is easy, because all the phases are positive. In general you target each qubit position k with an Rz(ϕk) operation with appropriately chosen ϕk values, and that will get the phases right.
Now we want to get the ordering right. The easiest way to do this is to have some extra qubits that are your output qubits and, for each of the qubits we've prepared so far and each of the output qubits, either add a CNOT between the two or don't. For example, if the state with amplitude 3/12−−√ is supposed to be a |11⟩, then we need to CNOT from our leftmost qubit onto both of the output qubits. Then we need to uncompute the leftmost qubit by using a many-controlled NOT operation. There should be one control for each output qubit, and the control's type (qubit-must-be-on vs qubit-must-be-off) is determined by whether or not you toggled the qubit.
Applying these steps produces an inefficient, but correct, circuit for creating a Hardy state. You can open the circuit in Quirk:
If you want to produce a state without using so much workspace, the task gets harder. But you can still follow the magnitudes then phases then ordering pattern. Also, there are cleverer ways to prepare magnitude sets that have nice patterns. For example, when only one amplitude is different from the others, one round of partial amplitude amplification may be enough to prepare the state.