jcmgray / quimb

A python library for quantum information and many-body calculations including tensor networks.
http://quimb.readthedocs.io
Other
488 stars 108 forks source link

TNOptimizer not recognizing certain optimization methods #82

Closed JustinS6626 closed 3 years ago

JustinS6626 commented 3 years ago

First of all, thanks again for all of your help so far. This is another issue related to the circuit optimization task that I have been working on for a while. Right now, I am trying to experiment with different optimizer methods, such as Adam and SGD. When I try to use these methods, I get a message like this:

File "/usr/local/lib/python3.8/dist-packages/quimb/tensor/optimize.py", line 946, in optimize_basinhopping self.res = basinhopping( File "/usr/local/lib/python3.8/dist-packages/scipy/optimize/_basinhopping.py", line 680, in basinhopping bh = BasinHoppingRunner(x0, wrapped_minimizer, take_step_wrapped, File "/usr/local/lib/python3.8/dist-packages/scipy/optimize/_basinhopping.py", line 72, in __init__ minres = minimizer(self.x) File "/usr/local/lib/python3.8/dist-packages/scipy/optimize/_basinhopping.py", line 284, in __call__ return self.minimizer(self.func, x0, **self.kwargs) File "/usr/local/lib/python3.8/dist-packages/scipy/optimize/_minimize.py", line 646, in minimize raise ValueError('Unknown solver %s' % method) ValueError: Unknown solver sgd

I get the same error for 'adam' as well. I was therefore wondering what the correct method would be to call these optimizer algorithms so that my optimizer object will recognize them.

jcmgray commented 3 years ago

Yes this is because the adam and sgd etc. methods are custom optimizers not built in to scipy. I think optimize_basinhopping just needs to be updated here:

https://github.com/jcmgray/quimb/blob/56e2c5d5b6ca937d31c5675e8cf4823d9f80a8bf/quimb/tensor/optimize.py#L946-L959

with method=self.optimizer changed to method=self._method. Do you want to try that fix and maybe submit a PR with the change if it works?

JustinS6626 commented 3 years ago

Thank you very much for getting back to be about that. I will try the modification and submit a PR if it works. Right now, however, there is an import error in the current github revision: import quimb.tensor as qtn ModuleNotFoundError: No module named 'quimb.tensor'

jcmgray commented 3 years ago

There doesn't seem to be any problems with a fresh install of the github version of quimb, I suspect you have a broken installation / uninstallation of quimb somehow - try uninstalling and then deleting the folder entirely from the site_packages folder of your environment and then reinstalling.

jcmgray commented 3 years ago

Should be fixed by https://github.com/jcmgray/quimb/commit/6738d16be50862df36476c7a78723ef59b0e874d.