Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback function in VQD is defined but never used #8575

Closed
Anthony-Gandon opened this issue Aug 18, 2022 · 0 comments · Fixed by #8576
Closed

Callback function in VQD is defined but never used #8575

Anthony-Gandon opened this issue Aug 18, 2022 · 0 comments · Fixed by #8576
Labels
bug Something isn't working mod: algorithms Related to the Algorithms module

Comments

@Anthony-Gandon
Copy link
Contributor

What should we add?

The Variational Quantum Deflation algorithm has an attribute self._callback which is never used in vqd.solve().
Inspired by the code for the VQE algorithm, the callback should be called in the energy_evaluation() call.
It also seems interesting that the callback also informs the user of the current step (VQD runs k steps of VQE).

Currently, the test test_callback checks the equality of empty lists

history = {'eval_count': [], 'parameters': [], 'mean': [], 'std': []}

The change would consist in adding the following lines during the call of the energy_evaluation(). These lines were taken from the VQE algorithm.

if self._callback is not None:
    variance = np.real(expectation.compute_variance(sampled_expect_op))
    estimator_error = np.sqrt(variance / self.quantum_instance.run_config.shots)
    for i, param_set in enumerate(parameter_sets):
        self._eval_count += 1
        self._callback(self._eval_count, param_set, means[i], estimator_error[i], step)
else:
    self._eval_count += len(means)

Giving

history {
'eval_count': [1, 2, 3, 1, 2, 3],
'parameters': [array([ 3.61186007,  4.19301252,  0.6019852 ,  5.94953681, -3.30704704,
        1.84629318, -5.4660436 ,  0.6984088 ]), array([ 4.61186007,  4.19301252,  0.6019852 ,  5.94953681, -3.30704704,
        1.84629318, -5.4660436 ,  0.6984088 ]), array([ 4.61186007,  5.19301252,  0.6019852 ,  5.94953681, -3.30704704,
        1.84629318, -5.4660436 ,  0.6984088 ]), array([ 3.61186007,  4.19301252,  0.6019852 ,  5.94953681, -3.30704704,
        1.84629318, -5.4660436 ,  0.6984088 ]), array([ 4.61186007,  4.19301252,  0.6019852 ,  5.94953681, -3.30704704,
        1.84629318, -5.4660436 ,  0.6984088 ]), array([ 3.61186007,  5.19301252,  0.6019852 ,  5.94953681, -3.30704704,
        1.84629318, -5.4660436 ,  0.6984088 ])], 
'mean': [-1.0632369218371718, -1.4565924844031897, -1.360034418572368, 37.340083390662826,        48.54340751559681, 28.58589345125128], 
'std': [0.011432088966174363, 0.009556915198516208, 0.013956731222284432, 0.011432088966174363, 0.009556915198516208, 0.015443719747907501], 
'step': [1, 1, 1, 2, 2, 2]
}

@Anthony-Gandon Anthony-Gandon added the type: feature request New feature or request label Aug 18, 2022
@woodsp-ibm woodsp-ibm added bug Something isn't working mod: algorithms Related to the Algorithms module and removed type: feature request New feature or request labels Aug 18, 2022
@mergify mergify bot closed this as completed in #8576 Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mod: algorithms Related to the Algorithms module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants