I have a simple parameterized quantum circuit which looks like the image attached. Here is the code used to create it:
from qiskit import QuantumCircuit, Aer, execute
import numpy as np
from qiskit.circuit import ParameterVector, QuantumCircuit
def add_layer(kernel, params, n_qubits):
qubits = list(range(n_qubits))
for i in range(n_qubits):
kernel.rx(params[i], qubits[i])
for i in range(n_qubits):
kernel.ry(params[i + n_qubits], qubits[i])
for i in range(n_qubits):
kernel.rz(params[i + n_qubits*2], qubits[i])
for q1, q2 in zip(qubits[0::2], qubits[1::2]):
kernel.cz(qubits[q1], qubits[q2])
return kernel
n_qubits = 2
n_samples = 5
simulator = Aer.get_backend('statevector_simulator')
n_parameters = n_qubits*3
parameters = np.random.default_rng(13).uniform(low=0, high=1, size = (n_samples,n_parameters))
np.random.seed(1)
p = ParameterVector('p', length = n_parameters)
kernel = QuantumCircuit(n_qubits)
kernel = add_layer(kernel, p, n_qubits)
bc = kernel.bind_parameters({p: parameters[0]})
result = execute(bc, simulator).result().get_statevector()
Currently I am only running this for parameters[0]
but I would like to run this for all 5 samples in parameters. How do I bind all of them?
Moreover, I would like to calculate the Z expectation value of the final qubit from the statevector with a built in method if there is one available.
Thanks for your help.