Você pode simplificar os problemas "produzir um estado" dividindo-os em três partes:
- Prepare a coleção de magnitudes que você precisará, sem se preocupar com a fase ou com qual estado tem qual magnitude.
- Corrija as fases.
- Corrija a encomenda.
3/12−−√1/12−−√
ℓ0|1000...00⟩ℓ0=13/12−−√Ry(θ0)θ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.