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