1
$\begingroup$

I am using amplitude encoding to encode my features in a quantum circuit. With this I expect to encode e.g. 32 features in five qubits.

For the encoding I use qiskit's StateVectorCircuit. I expect to receive the same state vector when using the StateVectorCircuit with the 'statevector_simulator' as I put in.

However, I experienced, that the sign of the real part (I don't use complex numbers) doesn't matches.

Here is a small example:

state_vector = [-1/2, -1/2, -1/2, -1/2]

state_vector_circuit = StateVectorCircuit(state_vector).construct_circuit()

job = execute(state_vector_circuit, Aer.get_backend('statevector_simulator'), optimization_level=0)
result = job.result()

outputstate = result.get_statevector(state_vector_circuit)

print(outputstate)
print(state_vector)

Running this code, I receive the following output, where the second line is the expected one:

[0.5+0.j 0.5+0.j 0.5+0.j 0.5+0.j]
[-0.5, -0.5, -0.5, -0.5]

Measuring the circuit will have the same results. However, I don't want to measure it immediately instead I have this circuit as an input for my Quantum Neural Network. And, in this case I guess the sign matters.

Where is the wrong sign coming from? Is it the StateVectorCircuit or the 'statevector_simulator'? And more importantly is there a way from preventing this?

On the other hand, I figured I could use only positive amplitudes. However, I feel this would be a limitation.

Edit: I created an example jupyter notebook on my GitHub page: StateVectorCircuitTest.ipynb

$\endgroup$
1
$\begingroup$

Your target state and the state that you get only differ by a total factor of $-1$. In other words, if $|\psi\rangle$ is the state that you get and $|\psi_{t}\rangle$ is the target state, we have:

$$ |\psi\rangle = (-1)\times|\psi_{t}\rangle = -|\psi_{t}\rangle. $$ Such a overall factor is known as a global phase. People think of it as a phase, because we can write $-1 = e^{i\phi}$ for $\phi=\pi$. Note that we're not only considering global phases when $\phi$ is equal to $\pi$, but $\phi$ can be anything between $0$ and $2\pi$.

We don't care about global phases, because whenever we try to retrieve information (i.e. a measurement) from a state the global phase cannot play a role. Therefore, we normally just disregard the global phase, and we set the first entry in our statevector to a real, positive value.

The sign difference between elements in your statevector, however, does play a vital role. We call this the relative phase, as it is a phase of one element of the statevector relative to the other. Also note that if you limit yourself to only real elements (thereby setting any relative phase $\phi_{rel}$ to $0$ or $\pi$), you severely limit the quantum advantage that you can attain.

| improve this answer | |
$\endgroup$
  • $\begingroup$ But is it the StateVectorCircuit or the 'statevector_simulator', which is setting the first entry to a real, positive value and can I prevent this from happening? Trying my example above with [-1/2, 1/2, 1/2, -1/2] I get [1/2, -1/2, -1/2, 1/2], which is exactly what you wrote! $\endgroup$ – Daniel Müssig Jun 18 at 12:13
  • $\begingroup$ My guess would be that it happens as soon as you make anything 'quantum' out of it - so in the line where you specify the StateVectorCircuit. I also don't expect you to be able to prevent this from happening - if you check the source code (qiskit.org/documentation/_modules/qiskit/aqua/circuits/…) you can see that upon initialization of the StateVectorCircuit object the internal state_vector proprty is normalized. This normalization is probably deleting the global phase. $\endgroup$ – JSdJ Jun 18 at 12:35
  • $\begingroup$ Furthermore, there is not really a circuit that you can device to actually get such a 'negative' statevector - the operations that we can perform on qubits just don't respect global phases, overall. $\endgroup$ – JSdJ Jun 18 at 12:37
  • $\begingroup$ I've found, that the following circuit creates the desired state, also with the 'statevector_simulator'. So, it seems the StateVectorCircuit is the 'problem'. $\endgroup$ – Daniel Müssig Jun 18 at 13:00
  • 1
    $\begingroup$ Nice work! Btw, in the circuit that you've linked, the entangling gate is not necessary (it actually does nothing), so you can omit it. So this circuit actually also does the trick, but no 'real' quantum computer would actually implement the first three gates. $\endgroup$ – JSdJ Jun 18 at 13:15
0
$\begingroup$

If your circuit is a component of a larger circuit then global phase may matter. See relevant discussions in https://github.com/Qiskit/qiskit-aer/issues/353 and https://github.com/Qiskit/qiskit-terra/issues/3083.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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