You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running VQD with primitives, the program fails to validate parameter values when calculating fidelities for k > 2. The ground and first excited states are found successfully, but when the algorithm gets to the second excited state, the sampler used for the fidelity fails to validate the parameters when VQD passes the parameters to the run() method of ComputeUncompute. This seems to have slipped past unit tests because those for VQD only test for k=1 and k=2.
How can we reproduce the issue?
The following code reproduces the issue:
from qiskit.algorithms.eigensolvers import VQD
from qiskit.algorithms.state_fidelities import ComputeUncompute
from qiskit.primitives import Estimator, Sampler
from qiskit.algorithms.optimizers import COBYLA
from qiskit.circuit.library import RealAmplitudes
from qiskit.quantum_info import Pauli
from qiskit_aer import AerSimulator
backend = AerSimulator(method='statevector')
qubit_op = Pauli('ZZ')
ansatz = RealAmplitudes(2)
cobyla = COBYLA()
estimator = Estimator()
sampler = Sampler()
fidelity = ComputeUncompute(sampler=sampler)
betas = [2, 2]
def print_intermediate_result(eval_count, params, estimated_value, estimation_metadata, current_step):
print(f'eval count: {eval_count}, energy: {estimated_value}, step: {current_step}')
vqd_instance = VQD(estimator=estimator,
fidelity=fidelity,
ansatz=ansatz,
optimizer=cobyla,
k=3,
betas=betas,
initial_point=None,
callback=print_intermediate_result)
result = vqd_instance.compute_eigenvalues(operator=qubit_op)
print(result.eigenvalues)
This produces the following traceback:
capi_return is NULL
Call-back cb_calcfc_in__cobyla__user__routines failed.
Traceback (most recent call last):
File "/home/joel/Desktop/electronic-structure-methods/test/VQD/VQD_ bugtest.py", line 32, in <module>
result = vqd_instance.compute_eigenvalues(operator=qubit_op)
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/site-packages/qiskit/algorithms/eigensolvers/vqd.py", line 256, in compute_eigenvalues
opt_result = self.optimizer.minimize(
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/site-packages/qiskit/algorithms/optimizers/scipy_optimizer.py", line 148, in minimize
raw_result = minimize(
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/site-packages/scipy/optimize/_minimize.py", line 705, in minimize
res = _minimize_cobyla(fun, x0, args, constraints, callback=callback,
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/site-packages/scipy/optimize/_cobyla_py.py", line 34, in wrapper
return func(*args, **kwargs)
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/site-packages/scipy/optimize/_cobyla_py.py", line 273, in _minimize_cobyla
xopt, info = cobyla.minimize(calcfc, m=m, x=np.copy(x0), rhobeg=rhobeg,
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/site-packages/scipy/optimize/_cobyla_py.py", line 261, in calcfc
f = fun(np.copy(x), *args)
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/site-packages/qiskit/algorithms/eigensolvers/vqd.py", line 363, in evaluate_energy
costs = fidelity_job.result().fidelities
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/site-packages/qiskit/primitives/primitive_job.py", line 50, in result
return self._future.result()
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/concurrent/futures/_base.py", line 438, in result
return self.__get_result()
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/concurrent/futures/_base.py", line 390, in __get_result
raise self._exception
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/site-packages/qiskit/algorithms/state_fidelities/compute_uncompute.py", line 141, in _run
job = self._sampler.run(circuits=circuits, parameter_values=values, **opts.__dict__)
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/site-packages/qiskit/primitives/base/base_sampler.py", line 172, in run
parameter_values = self._validate_parameter_values(
File "/home/joel/miniconda3/envs/Qiskit-0390/lib/python3.9/site-packages/qiskit/primitives/base/base_primitive.py", line 108, in _validate_parameter_values
raise TypeError("Invalid parameter values, expected Sequence[Sequence[float]].")
TypeError: Invalid parameter values, expected Sequence[Sequence[float]].
What should happen?
Algorithm completes successfully.
Any suggestions?
I am still looking into why this occurs, but my guess is that because the fidelity for the first excited state is computed successfully, there might be some error in the arguments that VQD passes to the run() method of ComputeUncompute on line 357 of vqd.py that is only problematic when len(prev_circs) > 1.
The text was updated successfully, but these errors were encountered:
Environment
What is happening?
When running
VQD
with primitives, the program fails to validate parameter values when calculating fidelities for k > 2. The ground and first excited states are found successfully, but when the algorithm gets to the second excited state, the sampler used for the fidelity fails to validate the parameters whenVQD
passes the parameters to therun()
method ofComputeUncompute
. This seems to have slipped past unit tests because those forVQD
only test for k=1 and k=2.How can we reproduce the issue?
The following code reproduces the issue:
This produces the following traceback:
What should happen?
Algorithm completes successfully.
Any suggestions?
I am still looking into why this occurs, but my guess is that because the fidelity for the first excited state is computed successfully, there might be some error in the arguments that
VQD
passes to therun()
method ofComputeUncompute
on line 357 ofvqd.py
that is only problematic whenlen(prev_circs)
> 1.The text was updated successfully, but these errors were encountered: