I have the following code where I’m trying to encode a vector of 4 features into a 2-qubit quantum state on the qiskit.aer simulator backend.
import pennylane as qml from pennylane import numpy as np import pennylane_qiskit as pqis import math,qiskit dev = qml.device('qiskit.aer', wires=2, backend = 'statevector_simulator') x = np.array([0.53896774,0.79503606,0.27826503,0.]) # n qubits to encode 2^n features #x = np.array([1,0,0,0]) @qml.qnode(dev) def test(x): qml.QubitStateVector(x,wires = [0,1]) return qml.expval(qml.PauliZ(0)) print(test(x))
This outputs the following error:
QiskitError: 'Sum of amplitudes-squared does not equal one.'
I have obviously checked that this is True:
math.isclose(sum(np.absolute(x) ** 2), 1.0,abs_tol=1e-7)
could it be qiskit’s tolerance eps value?
Qiskit version 0.9.0
Pennylane qiskit plugin 0.5.1
Also I’m getting the expectation value of the Pauli Z opeartor of the first qubit , but I’m rather interested on the marginal probabilities of quantum state, is there a way to extract that from the quantum node dev?
Thank you very much pennylane community!