In [15]:
from evoflow.engine import EvoFlow
from evoflow.ops import Input, RandomMutations1D, UniformCrossover1D
from evoflow.ops import RandomMutations2D, UniformCrossover2D
from evoflow.selection import SelectFittest
from evoflow.fitness import Sum
from evoflow.population import randint_population
from time import time
import tensorflow as tf
import cProfile
import pstats

In [8]:
population_shape = (1000, 10000) 
generations = 5
population = randint_population(population_shape, 1)

profiling


In [3]:
inputs = Input(population_shape)
x = RandomMutations1D(max_gene_value=1)(inputs)
outputs = UniformCrossover1D()(x)
gf = EvoFlow(inputs, outputs, debug=0)
fitness_function = Sum(max_sum_value=10000000)
evolution_strategy = SelectFittest()
gf.compile(evolution_strategy, fitness_function)

In [14]:
def to_profile():
    gf.evolve(population, generations=generations)
# profiling
cProfile.run('to_profile()', 'evoflow.prof')




In [28]:
p = pstats.Stats('evoflow.prof')
p.sort_stats('cumtime').print_stats(20, 'ops')


Fri May 22 15:51:39 2020    evoflow.prof

62242function calls(56389 primitive calls)in 2.610 seconds

   Ordered by: cumulative time
   List reduced from 559 to 20 due to restriction <20>
   List reduced from 20 to 5 due to restriction <'ops'>

   ncalls  tottime  percall  cumtime  percallfilename:lineno(function)
        5   0.047   0.009   1.282   0.256d:\code\evoflow\evoflow\ops\random_mutation.py:74(call)
        5   0.027   0.005   1.082   0.216d:\code\evoflow\evoflow\ops\uniform_crossover.py:56(call)
        5   0.053   0.011   1.055   0.211d:\code\evoflow\evoflow\ops\uniform_crossover.py:62(compute)
       20   0.000   0.000   0.276   0.014C:\Users\elie\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py:937(numpy)
       30   0.000   0.000   0.181   0.006C:\Users\elie\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\math_ops.py:981(binary_op_wrapper)


Out[28]:
<pstats.Stats at 0x18945079898>

performance


In [11]:
# v0.4.1 performance 2.571 sec
start = time()
gf.evolve(population, generations=generations, verbose=1)
evolve_time = time() - start
print("evolve time ", round(evolve_time, 3), "s")


evolve time2.571s