Closed philiplunel closed 5 years ago
Both wavefunctions are equivalent. When using cheat, one needs to take into account the ordering of qubits (which is arbitrary and changed in our case because of the flush()
) which is given in c[0], checkout the documentation of cheat
I would suggest to use instead the helper functions introduced in the simulator tutorial which allow you to specify the binary state and order of qubits for which you want to know an amplitude.
No need to call flush() before StatePreparation
and hence not calling it can produce better optimized code and is the suggested approach. But there is nothing wrong with calling flush.
Besides:
del q
, the compiler deallocates qubits automatically.Thanks, I missed that.
No problem, I am happy to help out.
Hi,
I was using the
StatePreparation()
command on 4 qubits setting up a specific state. When I accessed the wave function afterwards I would get something different than what I prepared and when if flush before theStatePreparation()
it seems to work fine. See the following programswhich outputs
which seemed weird since the |0010> state is now not prepared and instead the |0001> state is.
When I flush (uncomment it in the code above) before doing the
StatePreparation()
I get as outputas expected. What causes this and should one always flush before using the
StatePreparation()
command?Edit: btw I know projectq views the binary representation reversed i.e. '1000' is the first state and '0001' the eighth, but I mean with |0010> the |2> state and with |0001> the |1> state and thus the third and second value respectivaly of the list the cheating algorithm.