I think you are right that these two attributes are supposed to the same. Looking at the git history, optimizer_evals
was used prior to this PR: https://github.com/Qiskit/qiskit-terra/pull/6418 but the usage was removed during the refactoring in that PR.
Prior to #6418, cost_function_evals
was set by _eval_count
which in turn was set by optimizer_evals
.
L460 self._ret.cost_function_evals = self._eval_count
L443 if vqresult.optimizer_evals is not None and self._eval_count >= vqresult.optimizer_evals:
L444 self._eval_count = vqresult.optimizer_evals
in https://github.com/Qiskit/qiskit-terra/blob/5ec42789171b001780239d9e03e5dba4e077aa40/qiskit/algorithms/minimum_eigen_solvers/vqe.py
opt_params, opt_val, num_optimizer_evals = optimizer.optimize(
nparms,
cost_fn,
variable_bounds=bounds,
initial_point=initial_point,
gradient_function=gradient_fn,
)
eval_time = time.time() - start
result = VariationalResult()
result.optimizer_evals = num_optimizer_evals
in https://github.com/Qiskit/qiskit-terra/blob/5ec42789171b001780239d9e03e5dba4e077aa40/qiskit/algorithms/variational_algorithm.py#L229-L239
After #6418, cost_functions_evals
are directly set by optimizer.nfev
and therefore the intermediate optimizer_evals
are no longer used.
opt_result = self.optimizer.minimize(
fun=energy_evaluation, x0=initial_point, jac=gradient, bounds=bounds
)
eval_time = time() - start_time
result = VQEResult()
result.optimal_point = opt_result.x
result.optimal_parameters = dict(zip(self.ansatz.parameters, opt_result.x))
result.optimal_value = opt_result.fun
result.cost_function_evals = opt_result.nfev
https://github.com/Qiskit/qiskit-terra/blob/dd7f9390cf076f9545fa6086de486f2c06764ea5/qiskit/algorithms/minimum_eigen_solvers/vqe.py#L546-L556