kmc.electrodes[cf.Q] = Q[k] * V_high kmc.update_V() kmc.simulate_discrete(prehops=500, hops=5000) output[k] = kmc.current[cf.output] outputArray[i, j] = output fitness += cf.Fitness(output, cf.target) genePool.fitness[j] = fitness / avg fitnessArray[i, j] = genePool.fitness[j] # Status print print("Generation nr. " + str(i + 1) + " completed") print("Highest fitness: " + str(max(genePool.fitness))) # Evolve to the next generation genePool.NextGen() # Save experiment filepath = SaveLib.createSaveDirectory(cf.filepath, cf.name) SaveLib.saveExperiment(filepath, geneArray=geneArray, fitnessArray=fitnessArray, outputArray=outputArray, target=cf.target, P=P, Q=Q) domain = kmc_dn_utils.visualize_basic(kmc) plt.figure() plt.plot(output) plt.show()
outputArray[i, :, :] = outputTemp fitnessArray[i, :] = genePool.fitness # Update main figure PlotBuilder.updateMainFigEvolution(mainFig, geneArray, fitnessArray, outputArray, i + 1, t, cf.amplification*target, output, w) # Save generation SaveLib.saveExperiment(saveDirectory, geneArray = geneArray, outputArray = outputArray, fitnessArray = fitnessArray, t = t, x = x, amplified_target = cf.amplification*target) # Evolve to the next generation genePool.NextGen() PlotBuilder.finalMain(mainFig) InstrumentImporter.reset(0, 0)
print("Generation nr. " + str(i + 1) + " completed; took " + str(end - start) + " sec.") print("Highest fitness: " + str(max(genePool.fitness))) # Save generation data geneArray[i, :, :] = genePool.pool outputArray[i, :, :] = outputTemp fitnessArray[i, :] = genePool.fitness # # Update main figure # PlotBuilder.updateMainFigEvolution(mainFig, # geneArray, # fitnessArray, # outputArray, # i + 1, # t, # cf.amplification*target, # output, # w) # Save generation SaveLib.saveExperiment(saveDirectory, genes=geneArray, output=outputArray, fitness=fitnessArray) # Evolve to the next generation genePool.NextGen() PlotBuilder.finalMain(mainFig)
P = [0, 1, 0, 1] Q = [0, 0, 1, 1] w = [1, 1, 1, 1] kmc.electrodes[cf.output, 3] = 0 # Initialize arrays to save experiment geneArray = np.zeros((cf.generations, cf.genomes, cf.genes)) currentArray = np.zeros((cf.generations, cf.genomes, 8, 4 * cf.avg)) voltageArray = np.zeros((cf.generations, cf.genomes, 8, 4 * cf.avg)) fitnessArray = np.zeros((cf.generations, cf.genomes)) filepath = SaveLib.createSaveDirectory(cf.filepath, cf.name) # Save experiment (also copies files) SaveLib.saveExperiment(filepath, geneArray=geneArray, fitnessArray=fitnessArray, currentArray=currentArray, voltageArray=voltageArray, target=cf.target, P=P, Q=Q) for i in range(cf.generations): geneArray[i] = genePool.pool for j in range(cf.genomes): if (i == 0 and j == 1): tic = time.time() if (i == 0 and j == 2): print( f'Estimated time: {(time.time()-tic)*cf.generations*cf.genomes/3600} h' ) # Set the Voltages for k in cf.controls:
# Initialize instruments ivvi = InstrumentImporter.IVVIrack.initInstrument(dac_step=500, dac_delay=0.001) nr_blocks = len(cf.input1) * len(cf.input2) blockSize = int(len(voltages) / nr_blocks) assert len( voltages ) == blockSize * nr_blocks, 'Nr of gridpoints not divisible by nr_blocks!!' #main acquisition loop for j in range(nr_blocks): print('Getting Data for block ' + str(j) + '...') start_block = time.time() InstrumentImporter.IVVIrack.setControlVoltages(ivvi, voltages[j * blockSize, :]) time.sleep(1) #extra delay to account for changing the input voltages for i in range(blockSize): IVVIrack.setControlVoltages(ivvi, voltages[j * blockSize + i, :]) time.sleep(0.01) #tune this to avoid transients data[j * blockSize + i, -cf.samples:] = InstrumentImporter.nidaqIO.IO( np.zeros(cf.samples), cf.samples / cf.acqTime) end_block = time.time() print('CV-sweep over one input state took ' + str(end_block - start_block) + ' sec.') #SAVE DATA following conventions for NN training SaveLib.saveExperiment(saveDirectory, data=data, filename='training_NN_data') InstrumentImporter.reset(0, 0)
for index, control in enumerate(cf.controls): kmc.electrodes[control, 3] = (1-cf.gene[index])*cf.controlrange[0] \ + cf.gene[index]*cf.controlrange[1] # Obtain device response output = np.zeros((cf.n_voltage, cf.n_voltage, 8, cf.avg)) for ii in range(cf.n_voltage): for jj in range(cf.n_voltage): # Time estimate if (ii == 0 and jj == 0): starttime = time.time() if (ii == 0 and jj == 1): eta = (time.time() - starttime) * cf.avg * cf.n_voltage**2 print(f'Estimated time remaining: {eta} s, or {eta/3600} h') # Set input voltages kmc.electrodes[cf.P] = cf.inputaxis[ii] kmc.electrodes[cf.Q] = cf.inputaxis[jj] kmc.update_V() # Prestabilize the system kmc.python_simulation(prehops=cf.prehops) for kk in range(cf.avg): kmc.python_simulation(hops=cf.hops) output[ii, jj, :, kk] = kmc.current SaveLib.saveExperiment(saveDirectory, output=output, inputaxis=cf.inputaxis) print('All done!')
kmc.static_electrodes[0, 3] = P[k] * (cf.inputrange[0] * (1 - cf.gene[-1]) + cf.gene[-1] * cf.inputrange[1]) kmc.static_electrodes[1, 3] = Q[k] * (cf.inputrange[0] * (1 - cf.gene[-1]) + cf.gene[-1] * cf.inputrange[1]) else: kmc.static_electrodes[0, 3] = P[k] * cf.inputrange kmc.static_electrodes[1, 3] = Q[k] * cf.inputrange kmc.update_V() if (cf.use_go): kmc.go_simulation(hops=0, prehops=cf.prehops, goSpecificFunction='wrapperSimulateRecord') else: kmc.python_simulation(prehops=cf.prehops) for l in range(cf.avg): if (cf.use_go): kmc.go_simulation(hops=cf.hops, goSpecificFunction='wrapperSimulateRecord') else: kmc.python_simulation(hops=cf.hops) output[:, k * cf.avg + l] = kmc.current # Save experiment SaveLib.saveExperiment(saveDirectory, output=output) print('All done!')
# Load the information from the config class. config = config.experiment_config() # Initialize save directory. saveDirectory = SaveLib.createSaveDirectory(config.filepath, config.name) # Define the device input using the function in the config class. Input = config.Sweepgen(config.v_high, config.v_low, config.n_points, config.direction) # Measure using the device specified in the config class. if config.device == 'nidaq': Output = InstrumentImporter.nidaqIO.IO(Input, config.fs) elif config.device == 'adwin': adwin = InstrumentImporter.adwinIO.InitInstrument() Output = InstrumentImporter.adwinIO.IO(adwin, Input, config.fs) else: print('specify measurement device') # Save the Input and Output SaveLib.saveExperiment(saveDirectory, input=Input, output=Output) # Plot the IV curve. plt.figure() plt.plot(Input[0:len(Output)], Output) plt.show() # Final reset InstrumentImporter.reset(0, 0)
if (ii == 1): dt = time.time() - starttime print(f'Estimated remaining time: {dt*len(cf.kT)} s, or \ {dt*len(cf.kT)/3600} h') # Set the temperature kmc.kT = cf.kT[ii] # Update constant quantities that depend on I_0 and ab kmc.calc_E_constant() kmc.calc_transitions_constant() for jj in range(len(cf.voltages)): # Set voltage kmc.electrodes[0] = cf.voltages[jj] kmc.update_V() # Prestabilize the system kmc.python_simulation(prehops=cf.prehops) # Get current for kk in range(cf.avg): kmc.python_simulation(hops=cf.hops) output[ii, :, jj, kk] = kmc.current SaveLib.saveExperiment(saveDirectory, kT=cf.kT, output=output, voltages=cf.voltages) print('All done!')
P = [0, 1, 0, 1] Q = [0, 0, 1, 1] w = [1, 1, 1, 1] kmc.electrodes[cf.output] = 0 # Set control voltages and electrode 0 to high for index, control in enumerate(cf.controls): kmc.electrodes[control, 3] = (1-cf.gene[index])*cf.controlrange[0] \ + cf.gene[index]*cf.controlrange[1] kmc.electrodes[cf.P, 3] = cf.inputrange if cf.allzero: kmc.electrodes[:, 3] = 0 kmc.update_V() # Obtain IV curve by sweeping electrode 1 currentlist = np.zeros((cf.avg, 8, cf.n_voltage)) for i in range(cf.avg): currentlist[i] = kmc_dn_utils.IV(kmc, cf.sweep_electrode, cf.voltagelist, hops=cf.hops, prehops=cf.prehops) SaveLib.saveExperiment(saveDirectory, V=cf.voltagelist, I=currentlist) plt.figure() plt.plot(cf.voltagelist, currentlist[0, cf.output]) plt.show()
# Obtain device response electrode_occupation = np.zeros((4, cf.avg, 8, cf.hops)) time = np.zeros((4, cf.avg, cf.hops)) traffic = np.zeros( (4, cf.avg, kmc.transitions.shape[0], kmc.transitions.shape[0])) for k in range(4): if (k == 0): starttime = timelib.time() if (k == 1): print(f'Time remaining: {(timelib.time()-starttime)*3}') # Set input voltages kmc.electrodes[cf.P] = P[k] * cf.inputrange kmc.electrodes[cf.Q] = Q[k] * cf.inputrange kmc.update_V() # Prestabilize the system kmc.simulate_discrete(hops=cf.prehops) for l in range(cf.avg): kmc.simulate_discrete(hops=cf.hops, record_current=True) electrode_occupation[k, l] = kmc.electrode_occupation time[k, l] = kmc.time traffic[k, l] = kmc.traffic SaveLib.saveExperiment(saveDirectory, electrode_occupation=electrode_occupation, time=time, traffic=traffic)
# Update constant quantities that depend on I_0 and ab kmc.calc_E_constant() kmc.calc_transitions_constant() # Initialize starting occupation kmc.place_charges_random() start_occupation = kmc.occupation.copy() # Obtain device response currents = kmc_dn_utils.IV(kmc, cf.bias_electrode, voltagelist, prehops=prehops, hops=hops, printETA=True) output = currents[1].copy() # Save output and kmc object outputs[ii] = output kmc.saveSelf(filepath + '/kmc_objects/' + '{0:03}'.format(ii) + '.kmc') # Save experiment SaveLib.saveExperiment( filepath, outputs=outputs, voltagelist=voltagelist, ) print('All done!')
kT = cf.kT prehops = cf.prehops hops = cf.hops kmc.kT = kT # Initialize arrays to save experiment geneArray = np.zeros((cf.generations, cf.genomes, cf.genes)) outputArray = np.zeros((cf.generations, cf.genomes, len(voltagelist))) fitnessArray = np.zeros((cf.generations, cf.genomes)) filepath = SaveLib.createSaveDirectory(cf.filepath, cf.name) # Save experiment (also copies files) SaveLib.saveExperiment( filepath, geneArray=geneArray, fitnessArray=fitnessArray, outputArray=outputArray, voltagelist=voltagelist, target=target, ) for i in range(cf.generations): geneArray[i] = genePool.pool for j in range(cf.genomes): # Time estimation if (i == 0 and j == 1): tic = time.time() if (i == 0 and j == 2): print( f'Estimated time: {(time.time()-tic)*cf.generations*cf.genomes/3600} h' )