kstaats / karoo_gp

A Genetic Programming platform for Python with TensorFlow for wicked-fast CPU and GPU support.
Other
159 stars 61 forks source link

Methodically changing code to be suitable for Python 3 #7

Closed shirishr closed 6 years ago

shirishr commented 7 years ago

Hello, I am working with Python 3.5 I have methodically made changes to karoo_gp_base_class.py, karoo_gp_main.py and karoo_gp_server.py to be compatible with Python 3. I have now reached an error that I am unsure how to fix: (After accepting all default options for a run of karoo_gp_main I get)

Traceback (most recent call last): File "karoo_gp_main.py", line 210, in gp.fx_fitness_gym(gp.population_a) # generate expression, evaluate fitness, compare fitness File "C:\Users\shiri\Documents\karoo_gp-master\karoo_gp_base_class.py", line 1351, in fx_fitness_gym print ('\n\033[36m ', len(self.fittest_dict.keys()), 'trees\033[1m', np.sort(self.fittest_dict.keys()), '\033[0,0m\033[36moffer the highest fitness scores.\033[0,0m') File "C:\Anaconda3\envs\py35\lib\site-packages\numpy\core\fromnumeric.py", line 822, in sort a.sort(axis=axis, kind=kind, order=order) numpy.core._internal.AxisError: axis -1 is out of bounds for array of dimension 0

Please advise how to fix this issue

kstaats commented 7 years ago

Shirish,

To begin, allow me to offer many thanks and praise for your effort. This is something I have dreaded, as I have no experience in Python 3 and knew it would be a bit of a challenge. Your effort is much appreciated.

I am pleased to see that the error you have encountered is truly a non-critical one, as it is simply the sorting of the trees into a numeric order prior to printing them to screen. Even if this fails (but surely there is a solution), we simply revert to printing them in their current order.

After this fails (if you are using iPython such that the variables are retained in memory) print the dictionary gp.fittest_dict.keys() to screen. The sort function in line 1351 is re-organizing what is presented to screen based upon the Tree ID (column 0).

It should look something like this (ignore the actual values):

In [2]: gp.fittest_dict Out[2]: {1: 3b, 2: a + b + c, 3: 3b, 4: 3b, 5: 3b, 6: 3b, 7: 3b, 8: 3b, 9: 3b, ...

If yes, then something has changed in Numpy sort.

If no, then that dictionary is not being built properly.

Hope this helps!

And I don't know if you noticed, but a few days ago Karoo was updated with a vastly expanded list of supported operators (adding trig, Boolean). Ultimately, we'll need to roll those changes into your branch.

Thank you!

kai

On 07/08/2017 02:29 AM, Shirish (Sam) Ranade wrote:

Hello, I am working with Python 3.5

I have methodically made changes to karoo_gp_base_class.py, karoo_gp_main.py and karoo_gp_server.py to be compatible with Python 3.

I have now reached an error that I am unsure how to fix: (After accepting all default options for a run of karoo_gp_main I get) > Traceback (most recent call last): File "karoo_gp_main.py", line 210, in gp.fx_fitness_gym(gp.population_a) # generate expression, evaluate fitness, compare fitness File "C:\Users\shiri\Documents\karoo_gp-master\karoo_gp_base_class.py", line 1351, in fx_fitness_gym print ('\n\033[36m ', len(self.fittest_dict.keys()), 'trees\033[1m', np.sort(self.fittest_dict.keys()), '\033[0,0m\033[36moffer the highest fitness scores.\033[0,0m') File "C:\Anaconda3\envs\py35\lib\site-packages\numpy\core\fromnumeric.py", line 822, in sort a.sort(axis=axis, kind=kind, order=order) numpy.core._internal.AxisError: axis -1 is out of bounds for array of dimension 0

Please advise how to fix this issue

shirishr commented 7 years ago

Thank you Kai, 💯 Maybe I should update my copy of Karoo with v4 and then work on compability with Python 3. Due to some unfortunate support related issues I am forced to work with Python 3.5. (Tensorflow is available only for PY3.5 on windows platform 😭

kstaats commented 7 years ago

If you don't mind switching to v4.0, that would be splendid.

You'll find very little change to the overall application. A number of new lines added at the very top, to define the new TF functions, which shifted all the lines numbers down a bit. So what you have done so far, if copy/pasted, will work just fine.

Again, thank you!

And do not hesitate to reach out for assistance. I am not a Python expert, but my code I know fairly well :)

On 07/08/2017 12:42 PM, Shirish (Sam) Ranade wrote:

Thank you Kai, 💯 Maybe I should update my copy of Karoo with v4 and then work on compability with Python 3. Due to some unfortunate support related issues I am forced to work with Python 3.5. (Tensorflow is available only for PY3.5 on windows platform 😭

kstaats commented 6 years ago

I am going to close this issue as another user Jesse has automated a means to update Karoo to Python 3.x. I'll circle back to him with request to provide the latest build of Karoo with the latest 3.x support.

isildirik commented 6 years ago

Having been to Andrew's meetup speech today, I am keen to try the library. I wonder when you'll merge Jesse's PR?

kstaats commented 6 years ago

Having been to Andrew's meetup speech today, I am keen to try the library. I wonder when you'll merge Jesse's PR?

I appreciate your interest in Karoo GP, thank you.

Jesse's branch is for Python 3.6. I am yet developing for 2.7. It is my experience that we will need to maintain both a 2.7 and 3.6 branch as the two are not interchangeable. While the print functions are backward compatible, a quick test demonstrates that the replacement of a raw_input to the 3.6 compliant input breaks things.

I will reach out to Jesse with request for a 3.6 update once I push the new version I am working on.

Cheers, kai

isildirik commented 6 years ago

Thanks kai. I'll check again later then.