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

Bug using SNOBFIT in combination with UCCSD (VQE) / misleading function signature of optimizer SNOBFIT #8580

Closed
cpossel opened this issue Aug 18, 2022 · 2 comments · Fixed by #8638
Labels
good first issue Good for newcomers mod: algorithms Related to the Algorithms module

Comments

@cpossel
Copy link
Contributor

cpossel commented Aug 18, 2022

When running a VQE algorithm with ansatz UCCSD the following error message shows up:

[...]
 File "C:\Users\poc\Anaconda3\envs\qiskit\lib\site-packages\qiskit_nature\algorithms\pes_samplers\bopes_sampler.py", line 175, in sample
    self._raw_results = self._run_points(points)
  File "C:\Users\poc\Anaconda3\envs\qiskit\lib\site-packages\qiskit_nature\algorithms\pes_samplers\bopes_sampler.py", line 201, in _run_points
    raw_result = self._run_single_point(point)  # dict of results
  File "C:\Users\poc\Anaconda3\envs\qiskit\lib\site-packages\qiskit_nature\algorithms\pes_samplers\bopes_sampler.py", line 259, in _run_single_point
    result = self._state_solver.solve(self._problem, aux_ops_current_step)
  File "C:\Users\poc\Anaconda3\envs\qiskit\lib\site-packages\qiskit_nature\algorithms\ground_state_solvers\ground_state_eigensolver.py", line 91, in solve
    raw_mes_result = self._solver.compute_minimum_eigenvalue(main_operator, aux_ops)  # type: ignore
  File "C:\Users\poc\Anaconda3\envs\qiskit\lib\site-packages\qiskit\algorithms\minimum_eigen_solvers\vqe.py", line 530, in compute_minimum_eigenvalue
    opt_result = self.optimizer.minimize(
  File "C:\Users\poc\Anaconda3\envs\qiskit\lib\site-packages\qiskit\algorithms\optimizers\snobfit.py", line 96, in minimize
    if abs(theta) > bounds[idx][0]:
TypeError: '>' not supported between instances of 'float' and 'NoneType'

In case of ansatz EfficientSU2 the code runs fine, only with UCCSD I get the error.

I tracked down the error to be caused by missing parameter bounds. The function signature of the optimizer's minimize function (``) suggests that None is a valid value. But the code never handles None-type input (neither `None` nor the nested list/tuple with `None` values).

So, I propose one of the following changes:

  • Change the signature of the minimize method (still not easy to read for a user)
  • Catch the Nones in the input bounds and add a more verbose error message that optimizer SNOBFIT requires parameter bounds
  • Artificially add bounds for the optimizer. Basically the parameter can only be varied from 0 to 2pi so one could catch the None input and change it to these bounds. Though I'm not aware of the side effects this approach might have... Here it might be useful to ask also someone from qiskit nature whether it could be resolved within the UCCSD ansatz (though it would not solve the initial problem with the misleading signature/missing error message).

Any fixes (or suggestions therefore) are highly appreciated.

@jakelishman jakelishman added the mod: algorithms Related to the Algorithms module label Aug 18, 2022
@Cryoris Cryoris added the good first issue Good for newcomers label Aug 25, 2022
@Cryoris
Copy link
Contributor

Cryoris commented Aug 25, 2022

Thanks for reporting this!

If SNOBFIT requires bounds then I think the optimizer should raise an error if they are not passed. The interface is dictated by the Optimizer class so we can't really change that, and adding default bounds is very restrictive (e.g. [0,2pi] is not valid as soon as the circuit contains e.g. a gate like Ry(0.0001 * theta)).

@cpossel
Copy link
Contributor Author

cpossel commented Aug 30, 2022

@Cryoris Based on your comment I added a more concise error message in #8638
This resolves the problem at hand in the SNOBFIT code but actually there is still an open question: When I use ansatz EfficientSU2, all parameter bounds are set to (-pi, pi) allowing proper usage of optimizer SNOBFIT. On the other hand with ansatz UCCSD all parameter bounds are set to (None, None).
So, maybe someone with more insight into the ansatzes might have a look at it and can tell why those two ansatzes treat SNOBFIT so differently.

@javabster javabster moved this to Tagged but unassigned in Contributor Monitoring Sep 12, 2022
@mergify mergify bot closed this as completed in #8638 Sep 14, 2022
Repository owner moved this from Tagged but unassigned to Done in Contributor Monitoring Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers mod: algorithms Related to the Algorithms module
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants