def main(): name = 'LTL-MDP-CE_6_8_TD1_New' try: with open('path.conf') as f: root_dir_path = f.read().strip() except FileNotFoundError: raise FileNotFoundError( "You have not set the root path to store your results." " Write the path to a path.conf text file in the bin directory" " before running the simulation") paths = Paths(name, dict(run_no='test'), root_dir_path=root_dir_path) print("All output logs can be found in directory ", paths.logs_path) traj_file = os.path.join(paths.output_dir_path, 'data.h5') # Create an environment that handles running our simulation # This initializes a PyPet environment env = Environment( trajectory=name, filename=traj_file, file_title=u'{} data'.format(name), comment=u'{} data'.format(name), add_time=True, freeze_input=True, multiproc=True, use_scoop=True, wrap_mode=pypetconstants.WRAP_MODE_LOCAL, automatic_storing=True, log_stdout=False, # Sends stdout to logs log_folder=os.path.join(paths.output_dir_path, 'logs')) create_shared_logger_data(logger_names=['bin', 'optimizers'], log_levels=['INFO', 'INFO'], log_to_consoles=[True, True], sim_name=name, log_directory=paths.logs_path) configure_loggers() # Get the trajectory from the environment traj = env.trajectory # NOTE: Benchmark function optimizee = StateActionOptimizee(traj) # NOTE: Outerloop optimizer initialization # TODO: Change the optimizer to the appropriate Optimizer class parameters = CrossEntropyParameters(pop_size=75, rho=0.2, smoothing=0.0, temp_decay=0, n_iteration=75, distribution=NoisyGaussian( noise_magnitude=1, noise_decay=0.95), stop_criterion=np.inf, seed=102) optimizer = CrossEntropyOptimizer( traj, optimizee_create_individual=optimizee.create_individual, optimizee_fitness_weights=(-1., ), parameters=parameters, optimizee_bounding_func=optimizee.bounding_func) # Add post processing env.add_postprocessing(optimizer.post_process) # Add Recorder recorder = Recorder(trajectory=traj, optimizee_name='SNN StateAction', optimizee_parameters=['gamma', 'eta'], optimizer_name=optimizer.__class__.__name__, optimizer_parameters=optimizer.get_params()) recorder.start() # Run the simulation with all parameter combinations env.run(optimizee.simulate) # NOTE: Outerloop optimizer end optimizer.end(traj) recorder.end() # Finally disable logging and close all log-files env.disable_logging()
def main(dependent, optimizer): opt = optimizer.upper() identifier = '{:05x}'.format(np.random.randint(16**5)) print('Identifier: ' + identifier) allocated_id = '07' # dls.get_allocated_board_ids()[0] board_calibration_map = { 'B291698': { 'dac': 'dac_default.json', 'cap': 'cap_mem_29.json' }, '07': { 'dac': 'dac_07_chip_20.json', 'cap': 'calibration_20.json' }, 'B201319': { 'dac': 'dac_B201319_chip_21.json', 'cap': 'calibration_24.json' }, 'B201330': { 'dac': 'dac_B201330_chip_22.json', 'cap': 'calibration_22.json' } } dep_name = 'DEP' if dependent else 'IND' name = 'MAB_ANN_{}_{}_{}'.format(identifier, opt, dep_name) root_dir_path = os.path.expanduser('~/simulations') paths = Paths(name, dict(run_no=u'test'), root_dir_path=root_dir_path) with open(os.path.expanduser('~/LTL/bin/logging.yaml')) as f: l_dict = yaml.load(f) log_output_file = os.path.join(paths.results_path, l_dict['handlers']['file']['filename']) l_dict['handlers']['file']['filename'] = log_output_file logging.config.dictConfig(l_dict) print("All output logs can be found in directory " + str(paths.logs_path)) traj_file = os.path.join(paths.output_dir_path, u'data.h5') # Create an environment that handles running our simulation # This initializes a PyPet environment env = Environment( trajectory=name, filename=traj_file, file_title=u'{} data'.format(name), comment=u'{} data'.format(name), add_time=True, # freeze_input=True, # multiproc=True, # use_scoop=True, wrap_mode=pypetconstants.WRAP_MODE_LOCK, automatic_storing=True, log_stdout=False, # Sends stdout to logs log_folder=os.path.join(paths.output_dir_path, 'logs')) create_shared_logger_data(logger_names=['bin', 'optimizers', 'optimizees'], log_levels=['INFO', 'INFO', 'INFO'], log_to_consoles=[True, True, True], sim_name=name, log_directory=paths.logs_path) configure_loggers() # Get the trajectory from the environment traj = env.trajectory optimizee_seed = 100 with open('../adv/' + board_calibration_map[allocated_id]['cap']) as f: calibrated_config = json.load(f) with open('../adv/' + board_calibration_map[allocated_id]['dac']) as f: dac_config = json.load(f) class Dummy(object): def __init__(self, connector): self.connector = connector def __enter__(self): return self.connector def __exit__(self, exc_type, exc_val, exc_tb): pass class Mgr(object): def __init__(self): self.connector = None def establish(self): return Dummy(self.connector) max_learning_rate = 1. mgr = Mgr() optimizee_parameters = \ BanditParameters(n_arms=2, n_pulls=100, n_samples=40, seed=optimizee_seed, max_learning_rate=max_learning_rate, learning_rule=ANNLearningRule, establish_connection=mgr.establish) optimizee = BanditOptimizee(traj, optimizee_parameters, dp=dependent) # Add post processing optimizer = None pop_size = 200 n_iteration = 60 if opt == 'CE': ce_optimizer_parameters = CrossEntropyParameters( pop_size=pop_size, rho=0.06, smoothing=0.3, temp_decay=0, n_iteration=n_iteration, distribution=NoisyGaussian(noise_magnitude=.2, noise_decay=.925), #Gaussian(),#NoisyGaussian(noise_magnitude=1., noise_decay=0.99), stop_criterion=np.inf, seed=102) ce_optimizer = CrossEntropyOptimizer( traj, optimizee_create_individual=optimizee.create_individual, optimizee_fitness_weights=(1, ), parameters=ce_optimizer_parameters, optimizee_bounding_func=optimizee.bounding_func) optimizer = ce_optimizer elif opt == 'ES': es_optimizer_parameters = EvolutionStrategiesParameters( learning_rate=1.8, learning_rate_decay=.93, noise_std=.03, mirrored_sampling_enabled=True, fitness_shaping_enabled=True, pop_size=int(pop_size / 2), n_iteration=n_iteration, stop_criterion=np.inf, seed=102) optimizer = EvolutionStrategiesOptimizer(traj, optimizee.create_individual, (1, ), es_optimizer_parameters, optimizee.bounding_func) elif opt == 'GD': gd_parameters = ClassicGDParameters(learning_rate=.003, exploration_step_size=.1, n_random_steps=pop_size, n_iteration=n_iteration, stop_criterion=np.inf, seed=102) optimizer = GradientDescentOptimizer(traj, optimizee.create_individual, (1, ), gd_parameters, optimizee.bounding_func) elif opt == 'SA': sa_parameters = SimulatedAnnealingParameters( n_parallel_runs=pop_size, noisy_step=.1, temp_decay=.9, n_iteration=n_iteration, stop_criterion=np.inf, seed=102, cooling_schedule=AvailableCoolingSchedules.EXPONENTIAL_ADDAPTIVE) optimizer = SimulatedAnnealingOptimizer(traj, optimizee.create_individual, (1, ), sa_parameters, optimizee.bounding_func) elif opt == 'GS': n_grid_points = 5 gs_optimizer_parameters = GridSearchParameters( param_grid={ 'weight_prior': (0, 1, n_grid_points), 'learning_rate': (0, 1, n_grid_points), 'stim_inhibition': (0, 1, n_grid_points), 'action_inhibition': (0, 1, n_grid_points), 'learning_rate_decay': (0, 1, n_grid_points) }) gs_optimizer = GridSearchOptimizer( traj, optimizee_create_individual=optimizee.create_individual, optimizee_fitness_weights=(1, ), parameters=gs_optimizer_parameters) optimizer = gs_optimizer else: exit(1) env.add_postprocessing(optimizer.post_process) # Add Recorder recorder = Recorder(trajectory=traj, optimizee_name='MAB', optimizee_parameters=optimizee_parameters, optimizer_name=optimizer.__class__.__name__, optimizer_parameters=optimizer.get_params()) recorder.start() # Run the simulation with all parameter combinations # optimizee.simulate(traj) # exit(0) with Connector(calibrated_config, dac_config, 3) as connector: mgr.connector = connector env.run(optimizee.simulate) mgr.connector.disconnect() ## Outerloop optimizer end optimizer.end(traj) recorder.end() # Finally disable logging and close all log-files env.disable_logging()
def main(path_name, resolution, fixed_delay, state_handling, use_pecevski, num_trials): name = path_name try: with open('bin/path.conf') as f: root_dir_path = f.read().strip() except FileNotFoundError: raise FileNotFoundError( "You have not set the root path to store your results." " Write the path to a path.conf text file in the bin directory" " before running the simulation") paths = Paths(name, dict(run_no='test'), root_dir_path=root_dir_path) traj_file = os.path.join(paths.output_dir_path, 'data.h5') # Create an environment that handles running our simulation # This initializes a PyPet environment env = Environment( trajectory=name, filename=traj_file, file_title='{} data'.format(name), comment='{} data'.format(name), add_time=True, automatic_storing=True, use_scoop=True, multiproc=True, wrap_mode=pypetconstants.WRAP_MODE_LOCAL, log_stdout=False, # Sends stdout to logs ) create_shared_logger_data(logger_names=['bin', 'optimizers'], log_levels=['INFO', 'INFO'], log_to_consoles=[True, True], sim_name=name, log_directory=paths.logs_path) configure_loggers() # Get the trajectory from the environment traj = env.trajectory # NOTE: Innerloop simulator optimizee = SAMGraphOptimizee(traj, n_NEST_threads=1, time_resolution=resolution, fixed_delay=fixed_delay, use_pecevski=use_pecevski, state_handling=state_handling, plots_directory=paths.output_dir_path, num_fitness_trials=num_trials) # Get bounds for mu and sigma calculation. param_spec = OrderedDict(sorted(SAMGraph.parameter_spec(4).items())) names = [k for k, _ in param_spec.items()] mu = np.array([(v_min + v_max) / 2 for k, (v_min, v_max) in param_spec.items()]) sigma = np.array([(v_max - v_min) / 2 for k, (v_min, v_max) in param_spec.items()]) print("Using means: {}\nUsing stds: {}".format(dict(zip(names, mu)), dict(zip(names, sigma)))) # NOTE: Outerloop optimizer initialization parameters = NaturalEvolutionStrategiesParameters( seed=0, pop_size=96, n_iteration=40, learning_rate_sigma=0.5, learning_rate_mu=0.5, mu=mu, sigma=sigma, mirrored_sampling_enabled=True, fitness_shaping_enabled=True, stop_criterion=np.Inf) optimizer = NaturalEvolutionStrategiesOptimizer( traj, optimizee_create_individual=optimizee.create_individual, optimizee_fitness_weights=(-1.0, ), parameters=parameters, optimizee_bounding_func=optimizee.bounding_func, fitness_plot_name=path_name) # Add post processing env.add_postprocessing(optimizer.post_process) # Run the simulation with all parameter combinations env.run(optimizee.simulate) # NOTE: Outerloop optimizer end optimizer.end(traj) # Finally disable logging and close all log-files env.disable_logging()
def main(): name = 'LTL-MDP-GD_6_8_TD1' try: with open('path.conf') as f: root_dir_path = f.read().strip() except FileNotFoundError: raise FileNotFoundError( "You have not set the root path to store your results." " Write the path to a path.conf text file in the bin directory" " before running the simulation" ) paths = Paths(name, dict(run_no='test'), root_dir_path=root_dir_path) print("All output logs can be found in directory ", paths.logs_path) traj_file = os.path.join(paths.output_dir_path, 'data.h5') # Create an environment that handles running our simulation # This initializes a PyPet environment env = Environment(trajectory=name, filename=traj_file, file_title=u'{} data'.format(name), comment=u'{} data'.format(name), add_time=True, # freeze_input=True, # multiproc=True, # use_scoop=True, wrap_mode=pypetconstants.WRAP_MODE_LOCK, automatic_storing=True, log_stdout=False, # Sends stdout to logs log_folder=os.path.join(paths.output_dir_path, 'logs') ) create_shared_logger_data(logger_names=['bin', 'optimizers'], log_levels=['INFO', 'INFO'], log_to_consoles=[True, True], sim_name=name, log_directory=paths.logs_path) configure_loggers() # Get the trajectory from the environment traj = env.trajectory optimizee = DLSMDPOptimizee(traj) ## Outerloop optimizer initialization parameters = ClassicGDParameters(learning_rate=0.001, exploration_step_size=0.001, n_random_steps=50, n_iteration=30, stop_criterion=np.Inf, seed=1234) #parameters = AdamParameters(learning_rate=0.01, exploration_step_size=0.01, n_random_steps=15, first_order_decay=0.8, # second_order_decay=0.8, n_iteration=83, stop_criterion=np.Inf, seed=99) # parameters = StochasticGDParameters(learning_rate=0.01, stochastic_deviation=1, stochastic_decay=0.99, # exploration_step_size=0.01, n_random_steps=5, n_iteration=100, # stop_criterion=np.Inf) #parameters = RMSPropParameters(learning_rate=0.01, exploration_step_size=0.01, # n_random_steps=5, momentum_decay=0.5, # n_iteration=100, stop_criterion=np.Inf, seed=99) optimizer = GradientDescentOptimizer(traj, optimizee_create_individual=optimizee.create_individual, optimizee_fitness_weights=(-1.,), parameters=parameters, optimizee_bounding_func=optimizee.bounding_func, base_point_evaluations=10) # Add post processing env.add_postprocessing(optimizer.post_process) # Run the simulation with all parameter combinations env.run(optimizee.simulate) ## Outerloop optimizer end optimizer.end(traj) # Finally disable logging and close all log-files env.disable_logging()
def main(path_name, resolution, fixed_delay, use_pecevski, num_trials): name = path_name try: with open('bin/path.conf') as f: root_dir_path = f.read().strip() except FileNotFoundError: raise FileNotFoundError( "You have not set the root path to store your results." " Write the path to a path.conf text file in the bin directory" " before running the simulation") paths = Paths(name, dict(run_no='test'), root_dir_path=root_dir_path) traj_file = os.path.join(paths.output_dir_path, 'data.h5') # Create an environment that handles running our simulation # This initializes a PyPet environment env = Environment( trajectory=name, filename=traj_file, file_title='{} data'.format(name), comment='{} data'.format(name), add_time=True, automatic_storing=True, use_scoop=True, multiproc=True, wrap_mode=pypetconstants.WRAP_MODE_LOCAL, log_stdout=False, # Sends stdout to logs ) create_shared_logger_data(logger_names=['bin', 'optimizers'], log_levels=['INFO', 'INFO'], log_to_consoles=[True, True], sim_name=name, log_directory=paths.logs_path) configure_loggers() # Get the trajectory from the environment traj = env.trajectory # NOTE: Innerloop simulator optimizee = SAMOptimizee(traj, use_pecevski=use_pecevski, n_NEST_threads=1, time_resolution=resolution, fixed_delay=fixed_delay, plots_directory=paths.output_dir_path, num_fitness_trials=num_trials) # NOTE: Outerloop optimizer initialization parameters = GeneticAlgorithmParameters(seed=0, popsize=200, CXPB=0.5, MUTPB=1.0, NGEN=20, indpb=0.01, tournsize=20, matepar=0.5, mutpar=1.0, remutate=False) optimizer = GeneticAlgorithmOptimizer( traj, optimizee_create_individual=optimizee.create_individual, optimizee_fitness_weights=(-0.1, ), parameters=parameters, optimizee_bounding_func=optimizee.bounding_func, optimizee_parameter_spec=optimizee.parameter_spec, fitness_plot_name=path_name) # Add post processing env.add_postprocessing(optimizer.post_process) # Run the simulation with all parameter combinations env.run(optimizee.simulate) # NOTE: Outerloop optimizer end optimizer.end(traj) # Finally disable logging and close all log-files env.disable_logging()
def main(): name = 'LTL-MDP-SA_6_8_TD1' try: with open('path.conf') as f: root_dir_path = f.read().strip() except FileNotFoundError: raise FileNotFoundError( "You have not set the root path to store your results." " Write the path to a path.conf text file in the bin directory" " before running the simulation" ) paths = Paths(name, dict(run_no='test'), root_dir_path=root_dir_path) print("All output logs can be found in directory ", paths.logs_path) traj_file = os.path.join(paths.output_dir_path, 'data.h5') # Create an environment that handles running our simulation # This initializes a PyPet environment env = Environment(trajectory=name, filename=traj_file, file_title=u'{} data'.format(name), comment=u'{} data'.format(name), add_time=True, # freeze_input=True, # multiproc=True, # use_scoop=True, wrap_mode=pypetconstants.WRAP_MODE_LOCK, automatic_storing=True, log_stdout=False, # Sends stdout to logs log_folder=os.path.join(paths.output_dir_path, 'logs') ) create_shared_logger_data(logger_names=['bin', 'optimizers'], log_levels=['INFO', 'INFO'], log_to_consoles=[True, True], sim_name=name, log_directory=paths.logs_path) configure_loggers() # Get the trajectory from the environment traj = env.trajectory optimizee = DLSMDPOptimizee(traj) # NOTE: Outerloop optimizer initialization parameters = SimulatedAnnealingParameters(n_parallel_runs=50, noisy_step=.03, temp_decay=.99, n_iteration=30, stop_criterion=np.Inf, seed=np.random.randint(1e5), cooling_schedule=AvailableCoolingSchedules.QUADRATIC_ADDAPTIVE) optimizer = SimulatedAnnealingOptimizer(traj, optimizee_create_individual=optimizee.create_individual, optimizee_fitness_weights=(-1.,), parameters=parameters, optimizee_bounding_func=optimizee.bounding_func) # Add post processing env.add_postprocessing(optimizer.post_process) # Run the simulation with all parameter combinations env.run(optimizee.simulate) ## Outerloop optimizer end optimizer.end(traj) # Finally disable logging and close all log-files env.disable_logging()
def main(): name = 'LTL-MDP-GS' try: with open('path.conf') as f: root_dir_path = f.read().strip() except FileNotFoundError: raise FileNotFoundError( "You have not set the root path to store your results." " Write the path to a path.conf text file in the bin directory" " before running the simulation") paths = Paths(name, dict(run_no='test'), root_dir_path=root_dir_path) print("All output logs can be found in directory ", paths.logs_path) traj_file = os.path.join(paths.output_dir_path, 'data.h5') # Create an environment that handles running our simulation # This initializes a PyPet environment env = Environment( trajectory=name, filename=traj_file, file_title=u'{} data'.format(name), comment=u'{} data'.format(name), add_time=True, freeze_input=True, multiproc=True, use_scoop=True, wrap_mode=pypetconstants.WRAP_MODE_LOCAL, automatic_storing=True, log_stdout=False, # Sends stdout to logs log_folder=os.path.join(paths.output_dir_path, 'logs')) create_shared_logger_data(logger_names=['bin', 'optimizers'], log_levels=['INFO', 'INFO'], log_to_consoles=[True, True], sim_name=name, log_directory=paths.logs_path) configure_loggers() # Get the trajectory from the environment traj = env.trajectory # NOTE: Innerloop simulator optimizee = StateActionOptimizee(traj) # NOTE: Outerloop optimizer initialization n_grid_divs_per_axis = 50 parameters = GridSearchParameters( param_grid={ 'gamma': (optimizee.bound[0], optimizee.bound[1], n_grid_divs_per_axis), #'lam': (optimizee.bound[0], optimizee.bound[1], n_grid_divs_per_axis), 'eta': (optimizee.bound[0], optimizee.bound[1], n_grid_divs_per_axis), }) optimizer = GridSearchOptimizer( traj, optimizee_create_individual=optimizee.create_individual, optimizee_fitness_weights=(-1.), parameters=parameters) # Add post processing env.add_postprocessing(optimizer.post_process) # Run the simulation with all parameter combinations env.run(optimizee.simulate) # NOTE: Outerloop optimizer end optimizer.end(traj) # Finally disable logging and close all log-files env.disable_logging()
def main(): name = 'LTL-MDP-ES_6_8_TD1' try: with open('path.conf') as f: root_dir_path = f.read().strip() except FileNotFoundError: raise FileNotFoundError( "You have not set the root path to store your results." " Write the path to a path.conf text file in the bin directory" " before running the simulation" ) paths = Paths(name, dict(run_no='test'), root_dir_path=root_dir_path) print("All output logs can be found in directory ", paths.logs_path) traj_file = os.path.join(paths.output_dir_path, 'data.h5') # Create an environment that handles running our simulation # This initializes a PyPet environment env = Environment(trajectory=name, filename=traj_file, file_title=u'{} data'.format(name), comment=u'{} data'.format(name), add_time=True, # freeze_input=True, # multiproc=True, # use_scoop=True, wrap_mode=pypetconstants.WRAP_MODE_LOCK, automatic_storing=True, log_stdout=False, # Sends stdout to logs log_folder=os.path.join(paths.output_dir_path, 'logs') ) create_shared_logger_data(logger_names=['bin', 'optimizers'], log_levels=['INFO', 'INFO'], log_to_consoles=[True, True], sim_name=name, log_directory=paths.logs_path) configure_loggers() # Get the trajectory from the environment traj = env.trajectory ## Benchmark function optimizee = DLSMDPOptimizee(traj) ## Innerloop simulator ## Outerloop optimizer initialization optimizer_seed = 1234 parameters = EvolutionStrategiesParameters( learning_rate=0.5, learning_rate_decay=0.95, noise_std=0.1, mirrored_sampling_enabled=True, fitness_shaping_enabled=True, pop_size=25, n_iteration=30, stop_criterion=np.Inf, seed=optimizer_seed) optimizer = EvolutionStrategiesOptimizer( traj, optimizee_create_individual=optimizee.create_individual, optimizee_fitness_weights=(-1.,), parameters=parameters, optimizee_bounding_func=optimizee.bounding_func) # Add post processing env.add_postprocessing(optimizer.post_process) # Run the simulation with all parameter combinations env.run(optimizee.simulate) ## Outerloop optimizer end optimizer.end(traj) # Finally disable logging and close all log-files env.disable_logging()
def main(): name = 'LTL-MDP-FACE' try: with open('path.conf') as f: root_dir_path = f.read().strip() except FileNotFoundError: raise FileNotFoundError( "You have not set the root path to store your results." " Write the path to a path.conf text file in the bin directory" " before running the simulation") paths = Paths(name, dict(run_no='test'), root_dir_path=root_dir_path) print("All output logs can be found in directory ", paths.logs_path) traj_file = os.path.join(paths.output_dir_path, 'data.h5') # Create an environment that handles running our simulation # This initializes a PyPet environment env = Environment( trajectory=name, filename=traj_file, file_title=u'{} data'.format(name), comment=u'{} data'.format(name), add_time=True, # freeze_input=True, # multiproc=True, # use_scoop=True, wrap_mode=pypetconstants.WRAP_MODE_LOCK, automatic_storing=True, log_stdout=False, # Sends stdout to logs log_folder=os.path.join(paths.output_dir_path, 'logs')) create_shared_logger_data(logger_names=['bin', 'optimizers'], log_levels=['INFO', 'INFO'], log_to_consoles=[True, True], sim_name=name, log_directory=paths.logs_path) configure_loggers() # Get the trajectory from the environment traj = env.trajectory optimizee = DLSMDPOptimizee(traj) # NOTE: Outerloop optimizer initialization # TODO: Change the optimizer to the appropriate Optimizer class parameters = FACEParameters(min_pop_size=25, max_pop_size=25, n_elite=10, smoothing=0.2, temp_decay=0, n_iteration=100, distribution=Gaussian(), n_expand=5, stop_criterion=np.inf, seed=109) optimizer = FACEOptimizer( traj, optimizee_create_individual=optimizee.create_individual, optimizee_fitness_weights=(-1.), parameters=parameters, optimizee_bounding_func=optimizee.bounding_func) # Add post processing env.add_postprocessing(optimizer.post_process) # Run the simulation with all parameter combinations env.run(optimizee.simulate) ## Outerloop optimizer end optimizer.end(traj) # Finally disable logging and close all log-files env.disable_logging()
def run_best_spigraph(resolution, fixed_delay, min_delay, max_delay, use_pecevski, num_trials, seed): '''Runs the best SPI setup in the log file chosen by the user.''' import logging.config from sam.optimizee import SPINetworkOptimizee from ltl import sdict from pypet import Environment, pypetconstants from ltl.logging_tools import create_shared_logger_data, configure_loggers from ltl.paths import Paths logger = logging.getLogger('bin.ltl-spigraph-ga') name = "trial" root_dir_path = "plots" paths = Paths(name, dict(run_no='test'), root_dir_path=root_dir_path) traj_file = os.path.join(paths.output_dir_path, 'data.h5') # Create an environment that handles running our simulation # This initializes a PyPet environment env = Environment( trajectory=name, filename=traj_file, file_title='{} data'.format(name), comment='{} data'.format(name), add_time=True, automatic_storing=True, use_scoop=True, multiproc=True, wrap_mode=pypetconstants.WRAP_MODE_LOCAL, log_stdout=False, # Sends stdout to logs ) create_shared_logger_data(logger_names=['bin', 'optimizers'], log_levels=['INFO', 'INFO'], log_to_consoles=[True, True], sim_name=name, log_directory=paths.logs_path) configure_loggers() # Get the trajectory from the environment traj = env.trajectory print( "Running with resolution = {}, fixed delay = {}, use_pecevski = {}\n". format(resolution, fixed_delay, use_pecevski)) fns, hps = process_spigraph_results('/home/krisdamato/LTL-SAM/results/') print('') for i, fn in enumerate(fns): print("{}: {}".format(i, fn)) try: i = int(input('\nChoose log index: ')) except ValueError: print("Not a number!") return if i >= len(fns): print("Choose within the range!") return # Get best hps in the chosen log file. params = hps[fns[i]] params['intrinsic_step_time_fraction'] = 1.0 params['stdp_time_fraction'] = 1.0 params['learning_time'] = 300000 # Create the SAM optimizee. optimizee = SPINetworkOptimizee( traj, use_pecevski=use_pecevski, n_NEST_threads=1, time_resolution=resolution, min_delay=min_delay, max_delay=max_delay, fixed_delay=fixed_delay, plots_directory='/home/krisdamato/LTL-SAM/plots/', forced_params=params, plot_all=False, seed=seed, num_fitness_trials=num_trials) # Run simulation with the forced params. optimizee.simulate(traj)