def _train(self): # Get the result of optimization. result = grape_schroedinger_discrete(**self.qoc_config) error = result.best_error # Log the result. self.log_config.update({ "error": error, }) log_str = "{}\n".format( json.dumps(self.log_config, cls=CustomJSONEncoder)) try: with FileLock(LOG_FILE_LOCK_PATH): with open(LOG_FILE_PATH, "a+") as log_file: log_file.write(log_str) except Timeout: print("log file timeout:\n{}" "".format(self.log_config)) # Report the result. result_dict = { "error": error, "done": True, } return result_dict
def run_grape(): save_file_path = generate_save_file_path(EXPERIMENT_NAME, SAVE_PATH) config = copy(GRAPE_CONFIG) config.update({ "save_file_path": save_file_path }) result = grape_schroedinger_discrete(**config)
def run_grape(): t_start = time.process_time() save_file_path = generate_save_file_path(EXPERIMENT_NAME, SAVE_PATH) config = copy(GRAPE_CONFIG) config.update({"save_file_path": save_file_path}) result = grape_schroedinger_discrete(**config) tot_time = time.process_time() - t_start print("Total time (%s iterations): %d s, time/ieration: %.2f s" % (ITERATION_COUNT, tot_time, tot_time / ITERATION_COUNT))
def main(): result = grape_schroedinger_discrete(COSTS, hamiltonian, INITIAL_STATES, ITERATION_COUNT, PARAM_COUNT, PULSE_STEP_COUNT, PULSE_TIME, log_iteration_step=LOG_ITERATION_STEP, max_param_norms=MAX_PARAM_NORMS, optimizer=OPTIMIZER, save_file_name=SAVE_FILE_NAME, save_iteration_step=SAVE_ITERATION_STEP, save_path=SAVE_PATH,)
def main(): result = grape_schroedinger_discrete( COSTS, hamiltonian, INITIAL_STATES, ITERATION_COUNT, PARAM_COUNT, PULSE_STEP_COUNT, PULSE_TIME, log_iteration_step=LOG_ITERATION_STEP, max_param_norms=MAX_PARAM_NORMS, )
def main(): result = grape_schroedinger_discrete( CONTROL_COUNT, CONTROL_STEP_COUNT, COSTS, EVOLUTION_TIME, hamiltonian, INITIAL_STATES, complex_controls=COMPLEX_CONTROLS, iteration_count=ITERATION_COUNT, log_iteration_step=LOG_ITERATION_STEP, save_file_path=SAVE_FILE_PATH, save_iteration_step=SAVE_ITERATION_STEP, )
def main(): result = grape_schroedinger_discrete( CONTROL_COUNT, CONTROL_STEP_COUNT, COSTS, EVOLUTION_TIME, hamiltonian, INITIAL_STATES, ITERATION_COUNT, log_iteration_step=LOG_ITERATION_STEP, max_control_norms=MAX_CONTROL_NORMS, optimizer=OPTIMIZER, save_file_path=SAVE_FILE_PATH, save_iteration_step=SAVE_ITERATION_STEP, )
print("SYSTEM_EVAL_TIMES:\n{}" "".format(anp.linspace(0, EVOLUTION_TIME, SYSTEM_EVAL_COUNT))) # qoc saves data in h5 format. You can parse h5 files using the `h5py` package [5]. EXPERIMENT_NAME = "tutorial_schroed_cavity01" SAVE_PATH = "./out" SCHROED_FILE_PATH = generate_save_file_path(EXPERIMENT_NAME, SAVE_PATH) # Next, we use the GRAPE algorithm to find a set of time-dependent # controls that accomplishes the state transfer that we desire. result = grape_schroedinger_discrete(CONTROL_COUNT, CONTROL_EVAL_COUNT, COSTS, EVOLUTION_TIME, hamiltonian, INITIAL_STATES, SYSTEM_EVAL_COUNT, complex_controls=COMPLEX_CONTROLS, iteration_count=ITERATION_COUNT, log_iteration_step=LOG_ITERATION_STEP, optimizer=OPTIMIZER, save_file_path=SCHROED_FILE_PATH, save_intermediate_states=SAVE_INTERMEDIATE_STATES, save_iteration_step=SAVE_ITERATION_STEP,) # Next, we want to do some analysis of our results. CONTROLS_PLOT_FILE = "{}_controls.png".format(EXPERIMENT_NAME) CONTROLS_PLOT_FILE_PATH = os.path.join(SAVE_PATH, CONTROLS_PLOT_FILE) POPULATION_PLOT_FILE = "{}_population.png".format(EXPERIMENT_NAME) POPULATION_PLOT_FILE_PATH = os.path.join(SAVE_PATH, POPULATION_PLOT_FILE) SHOW = True # This function will plot the controls, and their fourier transform. plot_controls(SCHROED_FILE_PATH, save_file_path=CONTROLS_PLOT_FILE_PATH,
def main(): result = grape_schroedinger_discrete(**GRAPE_CONFIG)