nb_init=0, eval_init=False) bo_args['acquisition_weight'] = 20 # ======================== / # Create runners # ======================== / df = pd.DataFrame() runner_dict = {} for trial in range(NB_TRIALS): for opt, init, itt in zip(NB_OPT_VEC, nb_init_vec, nb_iter_vec): bo_args['nb_iter'] = itt * len(h_config) + init bo_args['initial_design_numdata'] = init runner = op.ParallelRunner(cstvec * opt, op.MethodBO, optimizer_args=bo_args, share_init=True, method='shared') runner_dict[(opt, trial)] = [runner, itt] #%% RUN OPTIMISER # ======================== / # Init runners # ======================== / print('Init runners') t = time.time() Batch = ut.Batch(inst) for run, itt in runner_dict.values(): bo_args = run.optimizer_args x_init = ut.gen_params_on_subspace(bo_args, nb_ignore=12,
domain = np.array([(-NB_DELTA, NB_DELTA) for i in range(nb_params)]) domain += np.array([x_sol,x_sol]).transpose() bo_args = ut.gen_default_argsbo(f=lambda x: .5, domain=domain, nb_init=NB_INIT, eval_init=False) bo_args['nb_iter'] = NB_ITER + NB_INIT bo_args['acquisition_weight'] = 5 bo_args['acquisition_type'] = 'EI' bo_args['initial_design_type'] = 'latin' # ======================== / # Init runner classes with different methods # ======================== / runner = op.ParallelRunner([cst], op.MethodBO, optimizer_args = bo_args, share_init = True, method = 'independent') # ========================= / # And initilization: # ========================= / Batch = ut.Batch(inst) runner.next_evaluation_circuits() print('Circs to init: {}'.format(len(runner.circs_to_exec))) Batch.submit(runner) Batch.execute() runner._last_results_obj = Batch._last_results_obj runner.init_optimisers()
# ======================== / # Init runner (parallel runner is overkill here) # ======================== / df = pd.DataFrame() np.random.seed(int(time.time())) for trial in range(NB_TRIALS): this_data = [] for opt, init, itt in zip(NB_OPT_VEC, nb_init_vec, nb_iter_vec): bo_args['nb_iter'] = itt bo_args['initial_design_numdata'] = init runner = op.ParallelRunner([xy_cost]*opt, op.MethodBO, optimizer_args = bo_args, share_init = False, method = 'shared') # # ========================= / # # And initilization: # ========================= / runner.next_evaluation_circuits() Batch.submit_exec_res(runner) runner.init_optimisers() # Run optimizer step by step for ii in range(itt): runner.next_evaluation_circuits() Batch.submit_exec_res(runner)
bo_args['nb_iter'] = NB_ITER * len(cost_list) + NB_INIT bo_args['acquisition_weight'] = 4 # ======================== / # Init runner classes with different methods # ======================== / opt_bo = op.MethodBO opt_spsa = op.MethodSPSA bo_args_list = [copy.deepcopy(bo_args) for ii in range(len(cost_list))] runner = op.ParallelRunner(cost_list, opt_bo, optimizer_args=bo_args_list, share_init=True, method='independent') x_new = [[x_sol, x_sol], [x_sol]] # ========================= / # Testing circ generation and output formainting # ========================= / if len(runner.optim_list) == 2: Batch = ut.Batch(inst) runner.next_evaluation_circuits() print(runner.method) print(runner._last_x_new) print('---------------------------------------------') runner._gen_circuits_from_params(x_new, inplace=True)