Time module has no (more) method clock()
DanieL-Zzz opened this issue · comments
Hello,
I am using Python 3.8 and it seems that the time.clock()
method, used in the file alipy/utils/multi_thread.py
(line 122, in __init__()
) does not exist anymore.
I cannot execute the following code given in example:
from sklearn.datasets import load_iris
from alipy.experiment.al_experiment import AlExperiment
X, y = load_iris(return_X_y=True)
al = AlExperiment(X, y, stopping_criteria='num_of_queries', stopping_value=50,)
al.split_AL()
al.set_query_strategy(strategy="QueryInstanceUncertainty", measure='least_confident')
al.set_performance_metric('accuracy_score')
al.start_query(multi_thread=True)
al.plot_learning_curve()
(get the following error:
Traceback (most recent call last):
File "/.../active_learning/main.py", line 46, in <module>
main(sys.argv)
File "/.../active_learning/main.py", line 37, in main
al.start_query(multi_thread=True)
File "/.../.local/lib/python3.8/site-packages/alipy/experiment/al_experiment.py", line 340, in start_query
ace = aceThreading(self._X, self._y, self._train_idx, self._test_idx,
File "/.../.local/lib/python3.8/site-packages/alipy/utils/multi_thread.py", line 112, in __init__
self._start_time = time.clock()
AttributeError: module 'time' has no attribute 'clock'
[edit] But setting multi_thread
parameter to False
solves the issue. However, that means we cannot use multi threading in recent Python version...)
According to the doc of Python 3.5:
Deprecated since version 3.3: The behaviour of this function depends on the platform: use perf_counter() or process_time() instead, depending on your requirements, to have a well defined behaviour.
Is any update planned for compatibility with more recent Python version?
Thank you and best regards!
File "/.../.local/lib/python3.8/site/packages/alipy/utils/multi_thread.py
Just replace the time.clock () with time.perf_counter() solves the issue and works fine.
We can use multithreading in recent python versions but the format of time changes in higher versions of python.
Hi, thank you for reporting this issue. We will fix it ASAP.
I think this issue will be fixed by
Replacing time.clock() with time.perf_counter() in the lines 112,249,250 in
https://github.com/NUAA-AL/ALiPy/blob/master/alipy/utils/multi_thread.py
Replacing time.clock() with time.perf_counter() in the line 135 in https://github.com/NUAA-AL/ALiPy/blob/master/alipy/experiment/stopping_criteria.py
In the test, you may get numpy error,
Make sure you install latest numpy version
pip install numpy==1.20.1
There is error installing cvxpy in windows,
Solution:
Go to url :https://www.lfd.uci.edu/~gohlke/pythonlibs/
Download these 3 wheel files according to your python version and operating system :
scs-2.1.2-cp39-cp39-win_amd64.whl
ecos-2.0.7.post1-cp39-cp39-win_amd64.whl
cvxpy-1.1.10-cp39-cp39-win_amd64.whl
Download and pip install these files and all tests works.