fgerzer / apsis

Other
25 stars 4 forks source link

Python3 support #123

Closed stmax82 closed 8 years ago

stmax82 commented 9 years ago

I tried to run the example from the tutorial: http://apsis.readthedocs.org/en/latest/tutorials/usage/base.html

The line:

from apsis.assistants.lab_assistant import PrettyLabAssistant

fails with the error:

NameError: name 'basestring' is not defined

Happens on Python 3.4 / Windows 8 x64.

Here's the complete stacktrace:

NameError                                 Traceback (most recent call last)
<ipython-input-4-5ebfc9d2bcac> in <module>()
----> 1 from apsis.assistants.lab_assistant import PrettyLabAssistant

C:\Anaconda3\lib\site-packages\apsis\assistants\lab_assistant.py in <module>()
      1 __author__ = 'Frederik Diehl'
      2 
----> 3 from apsis.assistants.experiment_assistant import BasicExperimentAssistant, PrettyExperimentAssistant
      4 import matplotlib.pyplot as plt
      5 from apsis.utilities.plot_utils import create_figure, _polish_figure, plot_lists, write_plot_to_file

C:\Anaconda3\lib\site-packages\apsis\assistants\experiment_assistant.py in <module>()
      3 from apsis.models.experiment import Experiment
      4 from apsis.models.candidate import Candidate
----> 5 from apsis.utilities.optimizer_utils import check_optimizer
      6 from apsis.utilities.file_utils import ensure_directory_exists
      7 import matplotlib.pyplot as plt

C:\Anaconda3\lib\site-packages\apsis\utilities\optimizer_utils.py in <module>()
      3 from apsis.optimizers.random_search import RandomSearch
      4 from apsis.optimizers.optimizer import Optimizer
----> 5 from apsis.optimizers.bayesian_optimization import SimpleBayesianOptimizer
      6 
      7 AVAILABLE_OPTIMIZERS = {"RandomSearch": RandomSearch, "BayOpt": SimpleBayesianOptimizer}

C:\Anaconda3\lib\site-packages\apsis\optimizers\bayesian_optimization.py in <module>()
      7 from apsis.models.candidate import Candidate
      8 from apsis.optimizers.bayesian.acquisition_functions import *
----> 9 from apsis.utilities.import_utils import import_if_exists
     10 import GPy
     11 import logging

C:\Anaconda3\lib\site-packages\apsis\utilities\import_utils.py in <module>()
      1 from apsis.utilities.logging_utils import get_logger
      2 
----> 3 logger = get_logger("apsis.utils.import_utils")
      4 
      5 def import_if_exists(module_name):

C:\Anaconda3\lib\site-packages\apsis\utilities\logging_utils.py in get_logger(module, specific_log_name)
     39 
     40     #if logger is already given as a string take directly. otherwise compute.
---> 41     if isinstance(module, basestring):
     42         new_logger_name = module
     43     else:

NameError: name 'basestring' is not defined
fgerzer commented 9 years ago

Hi stmax82,

the main problem is that apsis does not support python 3. Of course, as I realized when checking the documentation, that's not stated anywhere. My apologies for that! I've updated the documentation and readme to clearly state it (see 05da0611551b5eb11aec6efd97023919d44b1efd). We have not worked on python 3 compatibility since GPy, which we use for bayesian optimization, hadn't supported python 3 when we began writing apsis. Apparently, they do now; with the upcoming changes to the architecture python 3 compatibility is not a priority for now. I'll change this issue to 'python 3 support' and will come back to it. In the meantime, you can use apsis with python 2. While we don't support Windows officially - and I have only tested it on Win7 - the only required change is that you have to initialize the LabAssistant with write_directory_base pointing to some existing directory; the default assumes Linux-like path structures.

assistant = PrettyLabAssistant(write_directory_base=YOUR_PATH)

would be the corresponding change to the tutorial. 4fe26d34205976c87265ce9e696d8d536fc4dac1 has fixed this for the next version (see server_client branch), which I've already tested on Windows 7, but which still needs additional documentation and more tests.

Thanks for the report, and apologies again for not stating that apsis doesn't support python3. No, I don't know how we could miss that :-)

fgerzer commented 8 years ago

With the merge of server_client the client now also works with Python3. This should close this issue, as you can use the client in your python3 program, and run the server with python2.