In [1]:
from stack import *
my_stack = load('io_files/saved_stack_200_alt.txt')
my_pump  = incident_wp(my_stack)
#my_pump.add_packet(100,[1550.0,1600.0])
#my_pump.add_packet(100,[1600.5,1650.5])

my_pump.add_packet(200,[1625.5,1675.5])
my_pump.add_packet(200,[1575.25,1625.25],type='uniform',height=0.0001)
my_pump.add_packet(200,[1525,1575])
my_pump.apply_shaping(focus_mask(my_pump,0,component=0))

Nmodes=600

In [4]:
jtar = 190
pplsize = 50
elitesize = 10
ztar = my_stack.get_location(jtar) + my_stack.get_layerlength(jtar)/2.0
search = genetic_search(my_pump,jtar,resolution=12,pplsize=pplsize,elitesize=elitesize)

In [5]:
print('fitness_score() runtime for one individual:')
%timeit search.fitness_score(search.new_indv())
print('')

print('focus-outside score:',np.sum(my_pump.get_2PS(ztar)[:,1][Nmodes/3:2*Nmodes/3]))

seed = map(cmath.phase,focus_mask(my_pump,jtar,component=0))
my_pump.apply_shaping(focus_mask(my_pump,jtar,component=0))
print('best score with best resolution:',np.sum(my_pump.get_2PS(ztar)[:,1][Nmodes/3:2*Nmodes/3]))
my_pump.apply_shaping(focus_mask(my_pump,0,component=0))


fitness_score() runtime for one individual:
10 loops, best of 3: 34.2 ms per loop

('focus-outside score:', 77.145285838807936)
('best score with best resolution:', 1557.121120933655)

In [5]:
search.pplinit(seed=seed)

In [6]:
data = DataFrame(columns=range(pplsize))
Ngen = 40
for j in range(1,Ngen+1): 
      data.loc[j] = search.generation_scores()
      search.evolve([0.1,0.2,0.9],[0.5,0.1,0.9])#[0.8,0.5,0.2]
      print(j,end='-')


1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-

In [7]:
print('final top score:',search.fitness_score(search.topbreed()))
pyplot.figure(figsize=(18,5))
for j in range(1,len(data.index)+1): pyplot.plot(data.loc[j],'-o')
pyplot.show()


final top score: 4570.64436925
.
.
.

In [15]:
"""
gmask = genetic_mask(my_pump,jtar,resolution=20,pplsize=100,elitesize=20,Ngen=50)
my_pump.apply_shaping(gmask)
print(np.sum(my_pump.get_2PS(ztar)[:,1][Nmodes/3:2*Nmodes/3]))
my_pump.apply_shaping(conjugate(gmask))
"""


Out[15]:
'\ngmask = genetic_mask(my_pump,jtar,resolution=20,pplsize=100,elitesize=20,Ngen=50)\nmy_pump.apply_shaping(gmask)\nprint(np.sum(my_pump.get_2PS(ztar)[:,1][Nmodes/3:2*Nmodes/3]))\nmy_pump.apply_shaping(conjugate(gmask))\n'

In [7]:
#np.save('io_files/gmask@10-05nm.npy',gmask)
.
.
.

In [23]:
"""
# testing mutation
indv0 = search.new_indv()
indv1 = deepcopy(indv0)
search.mutate(indv0,[0.25,0.2,0.8])
pyplot.figure(figsize=(18,5))
pyplot.plot(indv0,'-bo');pyplot.plot(indv1,'-ro');pyplot.show()
"""


Out[23]:
"\n# testing mutation\nindv0 = search.new_indv()\nindv1 = deepcopy(indv0)\nsearch.mutate(indv0,[0.25,0.2,0.8])\npyplot.figure(figsize=(18,5))\npyplot.plot(indv0,'-bo');pyplot.plot(indv1,'-ro');pyplot.show()\n"

In [22]:
"""
# testing reproduction
indv0 = search.new_indv()
indv1 = search.new_indv()
child1,child2= search.reproduce('a',[indv0,indv1])
pyplot.figure(figsize=(18,5))
pyplot.plot(indv0,'-b');pyplot.plot(indv1,'-r');pyplot.plot(child2,'-go')
pyplot.axis([20,40,0,1]);pyplot.show()
"""


Out[22]:
"\n# testing reproduction\nindv0 = search.new_indv()\nindv1 = search.new_indv()\nchild1,child2= search.reproduce('a',[indv0,indv1])\npyplot.figure(figsize=(18,5))\npyplot.plot(indv0,'-b');pyplot.plot(indv1,'-r');pyplot.plot(child2,'-go')\npyplot.axis([20,40,0,1]);pyplot.show()\n"

In [20]:
"""
import pandas; from pandas import *
df = pandas.read_csv('io_files/genetics-mutant-A.txt',index_col=0)
pyplot.figure(figsize=(18,5))
#for j in range(len(df.index)):pyplot.plot(df.loc[j],'-o')
pyplot.plot(df.loc[0],'-o')
pyplot.plot(df.loc[len(df.index)-1],'-o')
pyplot.plot(df.loc[len(df.index)-20],'-o')
#pyplot.plot(df['39'])
pyplot.show()
"""


Out[20]:
"\nimport pandas; from pandas import *\ndf = pandas.read_csv('io_files/genetics-mutant-A.txt',index_col=0)\npyplot.figure(figsize=(18,5))\n#for j in range(len(df.index)):pyplot.plot(df.loc[j],'-o')\npyplot.plot(df.loc[0],'-o')\npyplot.plot(df.loc[len(df.index)-1],'-o')\npyplot.plot(df.loc[len(df.index)-20],'-o')\n#pyplot.plot(df['39'])\npyplot.show()\n"

In [ ]: