Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, manipulator, extra_seeds=None, extra_criteria=None, **kwargs):
super(SearchDriver, self).__init__(**kwargs)
if extra_seeds is None:
extra_seeds = []
self.manipulator = manipulator
self.wait_for_results = self.tuning_run_main.results_wait
self.commit = self.tuning_run_main.commit
self.extra_criteria = extra_criteria
self.generation = 0
self.test_count = 0
self.plugins = plugin.get_enabled(self.args)
self.pending_result_callbacks = list() # (DesiredResult, function) tuples
# deepcopy is required to have multiple tuning runs in a single process
if self.args.list_techniques:
techniques, generators = technique.all_techniques()
for t in techniques:
print(t.name)
sys.exit(0)
if self.args.generate_bandit_technique:
# generate a bandit
self.root_technique = AUCBanditMetaTechnique.generate_technique(manipulator)
else:
self.root_technique = copy.deepcopy(technique.get_root(self.args))
if isinstance(self.root_technique, AUCBanditMetaTechnique):
self.session.flush()
info = BanditInfo(tuning_run=self.tuning_run,
c=self.root_technique.bandit.C,
window=self.root_technique.bandit.window,)
self.session.add(info)
self.generation = 0
self.test_count = 0
self.plugins = plugin.get_enabled(self.args)
self.pending_result_callbacks = list() # (DesiredResult, function) tuples
# deepcopy is required to have multiple tuning runs in a single process
if self.args.list_techniques:
techniques, generators = technique.all_techniques()
for t in techniques:
print(t.name)
sys.exit(0)
if self.args.generate_bandit_technique:
# generate a bandit
self.root_technique = AUCBanditMetaTechnique.generate_technique(manipulator)
else:
self.root_technique = copy.deepcopy(technique.get_root(self.args))
if isinstance(self.root_technique, AUCBanditMetaTechnique):
self.session.flush()
info = BanditInfo(tuning_run=self.tuning_run,
c=self.root_technique.bandit.C,
window=self.root_technique.bandit.window,)
self.session.add(info)
for t in self.root_technique.techniques:
subtechnique = BanditSubTechnique(bandit_info=info,
name=t.name)
self.session.add(subtechnique)
self.objective.set_driver(self)
self.pending_config_ids = set()
self.best_result = None
#Acceptance probability function for annealing
def AcceptanceFunction(e,e_new,temp,scaling):
#Standard acceptance probability function using relative "goodness"
if e>=e_new:
return 1
if temp == 0:
return 0
if scaling*(e_new-e)/temp > 10:
#for practical purposes, probability is too low.
return 0
return math.exp(scaling*(e-e_new)/temp)
#register technique
technique.register(PseudoAnnealingSearch())
seed_configs = []
for m in seed_multipliers:
seed_config = manipulator.seed_config()
for p in cfg.getAllParameters().values() + jvm_options.values():
if isinstance(p, sjparameters.sjCompositionParameter):
p.equal_division(seed_config)
elif isinstance(p, sjparameters.sjPermutationParameter):
pass #p.set_value(config, p.seed_value())
else:
seed_config[p.name] = p.value
seed_config['multiplier'] = m
seed_configs.append(seed_config)
# The default bandit, plus our custom techniques.
from opentuner.search import technique, bandittechniques, differentialevolution, evolutionarytechniques, simplextechniques
technique.register(bandittechniques.AUCBanditMetaTechnique([
sjtechniques.FixedTechnique(seed_configs),
differentialevolution.DifferentialEvolutionAlt(),
evolutionarytechniques.UniformGreedyMutation(),
evolutionarytechniques.NormalGreedyMutation(mutation_rate=0.3),
simplextechniques.RandomNelderMead(),
sjtechniques.ForceRemove(),
sjtechniques.ForceFuse(),
sjtechniques.ForceUnbox(),
sjtechniques.ForceEqualDivision(),
sjtechniques.CrossSocketBeforeHyperthreadingAffinity(),
], name = "StreamJITBandit"))
mi = StreamJITMI(args, cfg, jvm_options, manipulator, FixedInputManager(), MinimizeTime())
m = TuningRunMain(mi, args)
m.main()
"""
mutate single parameter of cfg in place
"""
if param.is_primitive():
param.op1_normal_mutation(cfg, self.sigma)
else:
random.choice(param.manipulators(cfg))(cfg)
class UniformGreedyMutation(GreedySelectionMixin, GlobalEvolutionaryTechnique):
pass
class NormalGreedyMutation(NormalMutationMixin, GreedySelectionMixin, GlobalEvolutionaryTechnique):
pass
technique.register(NormalGreedyMutation( crossover_rate=0.5, crossover_strength=0.2, name='GGA'))
for param in params:
if param.is_permutation() and param.size>6:
getattr(param, self.crossover_op)(new, cfg1, cfg2, d=old_div(param.size,3))
return new
class UniformGreedyMutation(GreedySelectionMixin, EvolutionaryTechnique):
pass
class NormalGreedyMutation(NormalMutationMixin, GreedySelectionMixin, EvolutionaryTechnique):
pass
class GA(CrossoverMixin, UniformGreedyMutation):
pass
technique.register(GA(crossover = 'op3_cross_OX3', mutation_rate=0.10, crossover_rate=0.8))
technique.register(GA(crossover = 'op3_cross_OX1', mutation_rate=0.10,crossover_rate=0.8))
technique.register(GA(crossover = 'op3_cross_PX', mutation_rate=0.10, crossover_rate=0.8))
technique.register(GA(crossover = 'op3_cross_CX', mutation_rate=0.10, crossover_rate=0.8))
technique.register(GA(crossover = 'op3_cross_PMX', mutation_rate=0.10, crossover_rate=0.8))
technique.register(UniformGreedyMutation(name='ga-base', mutation_rate=0.10))
technique.register(UniformGreedyMutation(name='UniformGreedyMutation05', mutation_rate=0.05))
technique.register(UniformGreedyMutation(name='UniformGreedyMutation10', mutation_rate=0.10))
technique.register(UniformGreedyMutation(name='UniformGreedyMutation20', mutation_rate=0.20))
technique.register(NormalGreedyMutation(name='NormalGreedyMutation05', mutation_rate=0.05))
technique.register(NormalGreedyMutation(name='NormalGreedyMutation10', mutation_rate=0.10))
technique.register(NormalGreedyMutation(name='NormalGreedyMutation20', mutation_rate=0.20))
self.velocity[p.name]=0
def move(self, global_best):
"""
Update parameter values using corresponding operators.
TODO: introduce operator choice map
"""
m = self.manipulator
for p in m.params:
self.velocity[p.name] = p.op3_swarm(self.position, global_best, self.best, c=self.omega, c1=self.phi_g, c2=self.phi_l, xchoice=self.crossover_choice, velocity=self.velocity[p.name])
technique.register(PSO(crossover = 'op3_cross_OX3'))
technique.register(PSO(crossover = 'op3_cross_OX1'))
technique.register(PSO(crossover = 'op3_cross_PMX'))
technique.register(PSO(crossover = 'op3_cross_PX'))
technique.register(PSO(crossover = 'op3_cross_CX'))
# -*- coding: utf-8 -*-
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab autoindent smarttab
from __future__ import absolute_import
from builtins import range
from builtins import object
from .manipulator import *
from opentuner.search import technique
import random
import math
class PSO(technique.SequentialSearchTechnique ):
""" Particle Swarm Optimization """
def __init__(self, crossover, N = 30, init_pop=None, *pargs, **kwargs):
"""
crossover: name of crossover operator function
"""
super(PSO, self).__init__(*pargs, **kwargs)
self.crossover = crossover
self.name = 'pso-'+crossover.replace("op3_cross_","")
self.init_pop = init_pop
self.N = N
def main_generator(self):
objective = self.objective
driver = self.driver
m = self.manipulator
from __future__ import division
from builtins import range
from past.utils import old_div
from opentuner.search import technique
import math
import random
#Default interval steps for cooling schedules
DEFAULT_INTERVAL = 100
#Pseudo-annealing - no relative energy input into acceptance function
class PseudoAnnealingSearch(technique.SequentialSearchTechnique):
def __init__(self,
temps = [30,0], #temperature schedule
intervals = [], #duration schedule
loop = True, #Do we loop the schedule if we reach the end?
*pargs, **kwargs):
#fill intervals sufficiently
ext_intervals = list(intervals)
for i in range(len(temps)-len(intervals)-1):
ext_intervals.append(DEFAULT_INTERVAL)
#create temperature schedule (list of temps)
cool_schedule = [temps[0]]
for i in range(len(temps)-1):
step = old_div((float(temps[i+1]) - temps[i]),ext_intervals[i])
for j in range(ext_intervals[i]):
cool_schedule.append(max(cool_schedule[-1] + step,0))
class UniformGreedyMutation(GreedySelectionMixin, EvolutionaryTechnique):
pass
class NormalGreedyMutation(NormalMutationMixin, GreedySelectionMixin, EvolutionaryTechnique):
pass
class GA(CrossoverMixin, UniformGreedyMutation):
pass
technique.register(GA(crossover = 'op3_cross_OX3', mutation_rate=0.10, crossover_rate=0.8))
technique.register(GA(crossover = 'op3_cross_OX1', mutation_rate=0.10,crossover_rate=0.8))
technique.register(GA(crossover = 'op3_cross_PX', mutation_rate=0.10, crossover_rate=0.8))
technique.register(GA(crossover = 'op3_cross_CX', mutation_rate=0.10, crossover_rate=0.8))
technique.register(GA(crossover = 'op3_cross_PMX', mutation_rate=0.10, crossover_rate=0.8))
technique.register(UniformGreedyMutation(name='ga-base', mutation_rate=0.10))
technique.register(UniformGreedyMutation(name='UniformGreedyMutation05', mutation_rate=0.05))
technique.register(UniformGreedyMutation(name='UniformGreedyMutation10', mutation_rate=0.10))
technique.register(UniformGreedyMutation(name='UniformGreedyMutation20', mutation_rate=0.20))
technique.register(NormalGreedyMutation(name='NormalGreedyMutation05', mutation_rate=0.05))
technique.register(NormalGreedyMutation(name='NormalGreedyMutation10', mutation_rate=0.10))
technique.register(NormalGreedyMutation(name='NormalGreedyMutation20', mutation_rate=0.20))