I need to repeatedly input one random quantum state after another into a quantum circuit that has been designed and assigned parameters, and these quantum states will be used as input. I have tried
Statevector()
Custom()
https://qiskit.org/documentation/stable/0.19/stubs/qiskit.aqua.components.initial_states.Custom.html
initialize()
, but I found Although these functions can generate new state vectors, they cannot be inserted into already designed quantum circuits, resulting in the same circuit results every time. How should I design it? The three functions mentioned above lack the inplace property and cannot generate a new circuit copy.
{ParameterVectorElement(aa[0]): 0.2379597082677889, ParameterVectorElement(aa[1]): 1.4010239667773599, ParameterVectorElement(aa[2]): 0.10401258494998716, ParameterVectorElement(aa[3]): 0.3326296026269176, ParameterVectorElement(bb[0]): 1.6443757859109702, ParameterVectorElement(bb[1]): 0.8877583818970967, ParameterVectorElement(bb[2]): 0.07150986168780663, ParameterVectorElement(bb[3]): 1.720576457948209, ParameterVectorElement(cc[0]): 1.9974865102845014, ParameterVectorElement(cc[1]): 1.4917958623436192, ParameterVectorElement(cc[2]): 0.7199744574903324, ParameterVectorElement(cc[3]): 2.635969165530908}
WARNING:qiskit.aqua.components.initial_states.custom:The provided state_vector is ignored in favor of the provided custom circuit.
ParameterView([]) [0.00449711 0. 0. ... 0. 0. 0. ]
C:\Users\15691\AppData\Local\Temp\ipykernel_347040\162399.py:121: DeprecationWarning: The return type of saved density matrices has been changed from a `numpy.ndarray` to a `qiskit.quantum_info.DensityMatrix` as of qiskit-aer 0.10. Accessing numpy array attributes is deprecated and will result in an error in a future release. To continue using saved result objects as arrays you can explicitly cast them using `np.asarray(object)`.
t = np.array(density_matrix.real)
[[0.09660034 0.09656075 0.11104839 0.11262035 0.09307498 0.09300402
0.10599975 0.10750024]
[0.09656075 0.0984683 0.11262035 0.11646331 0.09300402 0.0948085
0.10750024 0.11116849]
[0.11104839 0.11262035 0.1565212 0.16014388 0.10599975 0.10750024
0.14853878 0.15202993]
[0.11262035 0.11646331 0.16014388 0.16699589 0.10750024 0.11116849
0.15202993 0.15858678]
[0.09307498 0.09300402 0.10599975 0.10750024 0.09142649 0.09132274
0.10308861 0.10454789]
[0.09300402 0.0948085 0.10750024 0.11116849 0.09132274 0.09306052
0.10454789 0.10811539]
[0.10599975 0.10750024 0.14853878 0.15202993 0.10308861 0.10454789
0.14355167 0.14698168]
[0.10750024 0.11116849 0.15202993 0.15858678 0.10454789 0.10811539
0.14698168 0.15337558]]
{ParameterVectorElement(aa[0]): 0.2379597082677889, ParameterVectorElement(aa[1]): 1.4010239667773599, ParameterVectorElement(aa[2]): 0.10401258494998716, ParameterVectorElement(aa[3]): 0.3326296026269176, ParameterVectorElement(bb[0]): 1.6443757859109702, ParameterVectorElement(bb[1]): 0.8877583818970967, ParameterVectorElement(bb[2]): 0.07150986168780663, ParameterVectorElement(bb[3]): 1.720576457948209, ParameterVectorElement(cc[0]): 1.9974865102845014, ParameterVectorElement(cc[1]): 1.4917958623436192, ParameterVectorElement(cc[2]): 0.7199744574903324, ParameterVectorElement(cc[3]): 2.635969165530908}
WARNING:qiskit.aqua.components.initial_states.custom:The provided state_vector is ignored in favor of the provided custom circuit.
ParameterView([]) [0.01146697 0. 0. ... 0. 0. 0. ]
[[0.09660034 0.09656075 0.11104839 0.11262035 0.09307498 0.09300402
0.10599975 0.10750024]
[0.09656075 0.0984683 0.11262035 0.11646331 0.09300402 0.0948085
0.10750024 0.11116849]
[0.11104839 0.11262035 0.1565212 0.16014388 0.10599975 0.10750024
0.14853878 0.15202993]
[0.11262035 0.11646331 0.16014388 0.16699589 0.10750024 0.11116849
0.15202993 0.15858678]
[0.09307498 0.09300402 0.10599975 0.10750024 0.09142649 0.09132274
0.10308861 0.10454789]
[0.09300402 0.0948085 0.10750024 0.11116849 0.09132274 0.09306052
0.10454789 0.10811539]
[0.10599975 0.10750024 0.14853878 0.15202993 0.10308861 0.10454789
0.14355167 0.14698168]
[0.10750024 0.11116849 0.15202993 0.15858678 0.10454789 0.10811539
0.14698168 0.15337558]]
{ParameterVectorElement(aa[0]): 0.2379597082677889, ParameterVectorElement(aa[1]): 1.4010239667773599, ParameterVectorElement(aa[2]): 0.10401258494998716, ParameterVectorElement(aa[3]): 0.3326296026269176, ParameterVectorElement(bb[0]): 1.6443757859109702, ParameterVectorElement(bb[1]): 0.8877583818970967, ParameterVectorElement(bb[2]): 0.07150986168780663, ParameterVectorElement(bb[3]): 1.720576457948209, ParameterVectorElement(cc[0]): 1.9974865102845014, ParameterVectorElement(cc[1]): 1.4917958623436192, ParameterVectorElement(cc[2]): 0.7199744574903324, ParameterVectorElement(cc[3]): 2.635969165530908}
WhileLoopOp
orForLoopOp
, andrandom_statevector
, for the task, will make your life easier. and run the circuit with.run(qc)
$\endgroup$