zenbot icon indicating copy to clipboard operation
zenbot copied to clipboard

genetic algorithm, syntax error in main.py

Open trivalik opened this issue 7 years ago • 6 comments

I wanna tell you that my python finds syntax errors:

   File "main.py", line 32`
     print(colored(f"Mating function is ", 'blue') + colored(Andividual.mate, 'green'))`
Traceback (most recent call last):
  File "main.py", line 9, in <module>
    from evaluation import evaluate_zen, Andividual
  File "/mnt/c/Users/Trivalik/Repos/zenbot/scripts/genetic_algo/evaluation.py", line 55
    return colored(f"{self.cmdline}  {super(Andividual, self).__repr__()}", 'grey')

I removed the f before the string on line 32 and 33, then it was working. Anyway there are still other f in py files arround. Not sure what this f means. I tried python2 and 3!

trivalik avatar Jan 20 '18 22:01 trivalik

Seconded! The f"" thing is lame. It's an abbreviated form of the .format command on strings (or maybe equivalent to string.Template), but I have no idea which interpreters can deal with it.

BrannonKing avatar Jan 21 '18 04:01 BrannonKing

I got it work. f-string are supported since python3.6. Install for ubuntu 16.04:

sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6 python3-tk
python3.6 -m pip install deap scoop termcolor numpy networkx matplotlib names

Newer ubuntu version come already with this python version. Anyway I got this warning:

/home/triv/.local/lib/python3.6/site-packages/deap/tools/_hypervolume/pyhv.py:33: ImportWarning: Falling back to the python version of hypervolume module. Expect this to be very slow.
  "module. Expect this to be very slow.", ImportWarning)
/usr/lib/python3.6/importlib/_bootstrap.py:219: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  return f(*args, **kwds)
/usr/lib/python3.6/importlib/_bootstrap_external.py:426: ImportWarning: Not importing directory /home/triv/.local/lib/python3.6/site-packages/mpl_toolkits: missing __init__
  _warnings.warn(msg.format(portions[0]), ImportWarning)

Any hints?

Edit:

I got additional an error about apt_pkg, solved by:

sudo apt-get remove --purge python3-apt
sudo apt-get install python3-apt

Any way I got additional to the above:

Traceback (most recent call last):
  File "main.py", line 51, in <module>
    res = main(INSTRUMENT, TOTAL_DAYS, popsize, strategy)
  File "main.py", line 34, in main
    res = evolve(evaluate, Andividual, popsize)
  File "/mnt/c/Users/Trivalik/Repos/zenbot/scripts/genetic_algo/evolution/__init__.py", line 18, in evolve
    return algorithm(cls, popsize, futures.map, evaluate, select, breed, mutate, stats, history, hof)
  File "/mnt/c/Users/Trivalik/Repos/zenbot/scripts/genetic_algo/evolution/core.py", line 17, in algorithm
    evaluate_group(would_be,map,evaluate)
  File "/mnt/c/Users/Trivalik/Repos/zenbot/scripts/genetic_algo/evolution/core.py", line 37, in evaluate_group
    fitnesses = map(evaluate, [ind.cmdline for ind in invalid_ind])
  File "/mnt/c/Users/Trivalik/Repos/zenbot/scripts/genetic_algo/evolution/core.py", line 37, in <listcomp>
    fitnesses = map(evaluate, [ind.cmdline for ind in invalid_ind])
  File "/mnt/c/Users/Trivalik/Repos/zenbot/scripts/genetic_algo/evaluation.py", line 102, in cmdline
    result = ' '.join([base] + self.params)
  File "/mnt/c/Users/Trivalik/Repos/zenbot/scripts/genetic_algo/evaluation.py", line 96, in params
    params = [format(key, value) for key, value in self.compress()]
  File "/mnt/c/Users/Trivalik/Repos/zenbot/scripts/genetic_algo/evaluation.py", line 85, in compress
    output = dict(self.convert(param, value) for param, value in normalized.items())
  File "/mnt/c/Users/Trivalik/Repos/zenbot/scripts/genetic_algo/evaluation.py", line 85, in <genexpr>
    output = dict(self.convert(param, value) for param, value in normalized.items())
  File "/mnt/c/Users/Trivalik/Repos/zenbot/scripts/genetic_algo/evaluation.py", line 196, in convert
    raise ValueError(colored(f"I don't understand {param} please add it to evaluation.py", 'red'))

trivalik avatar Jan 21 '18 12:01 trivalik

Hi there I got at the same error travlik has: "I don't understand wavetrend_channel_length please add it to evaluation.py" So I removed the complete wavetrend strategy folder

Then tried again then got this: "I don't understand bollinger_size please add it to evaluation.py" Unfortunately removing the bollinger folder got the same error. Used inother strategy as well?

I get the impression that genetic_algo is pretty outdated. Am I wrong?

kbfifi avatar Jan 21 '18 18:01 kbfifi

ValueError: I don't understand mama_fastlimit please add it to evaluation.py

I am running python 3.7.2 so I don't have incompatibilities with f-strings. Still not sure where im supposed to add that to evaluation.py

miqueet avatar Dec 13 '19 21:12 miqueet

I also got this error, as I understand so far, some parameters from the different strategies must be processed first in the convert function https://github.com/DeviaVir/zenbot/blob/30526361406d5b94b123cb1fb470b3d9790250ed/scripts/genetic_algo/evaluation.py#L108

Since the genetic algorithm was introduced by @arpheno https://github.com/DeviaVir/zenbot/pull/299 3 years ago, a lot of strategies and parameters have been added/changed and the convert() function hasn't been updated.

As a quick solution I'm working on making a list of the unsupported strategies to disable them and fix the errors.

LuisAlejandro avatar Dec 05 '20 16:12 LuisAlejandro

I gave up with the genetic_algo and started using the genetic_backtester as it is in a more decent state

LuisAlejandro avatar Dec 08 '20 05:12 LuisAlejandro