예제 #1
0

# ------ set up logger
output_file_name = 'scan_{}spins_bound{}.csv'.format(num_spins, bound[1])
logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s]"
                                 "[%(levelname)-5.5s]  %(message)s")
rootLogger = logging.getLogger()
rootLogger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler(output_file_name[:-4] + '.log')
fileHandler.setFormatter(logFormatter)
fileHandler.setLevel(logging.DEBUG)
rootLogger.addHandler(fileHandler)
logging.info('Output file name will be "{}"'.format(output_file_name))

# ------ GOGOGOGO
logging.info('Starting iteration loop')
results = np.zeros(shape=(len(tf_list) * len(time_ratios_list), 3))
idx = 0
for out_idx, tf in enumerate(tf_list):
    logging.info('Starting iteration {}/{}'.format(out_idx + 1, len(list(tf_list))))
    for ratio in time_ratios_list:
        protocol = protocols.DoubleBangProtocolAnsatz()
        protocol.fill_hyperpar_value(tf=tf)
        fun = protocol.time_dependent_fun(np.asarray([bound[1], ratio * tf, bound[0]]))
        output_state = optimization.evolve_state([lmg.H0, [lmg.H1, fun]], initial_state, tf)
        results[idx] = [tf, ratio, qutip.fidelity(output_state, target_state)**2]
        idx += 1
results = pd.DataFrame(results, columns=['tf', 'ratio', 'fid'])

results.to_csv('scan_{}spins_bound{}.csv'.format(num_spins, bound[1]))
os.makedirs(output_file_basename)

# model parameters
N = 100
Omega = 100
omega_0 = 1
lambda_c = np.sqrt(Omega * omega_0) / 2.
# build Hamiltonians
H0 = rabi_model.QRM_free_term(N, Omega, omega_0)
H1 = rabi_model.QRM_interaction_term(N)
# compute initial and target states
initial_state = ground_state(H0)
target_state = ground_state(H0 + lambda_c * H1)
# define the type of protocol and parameter range
heights_to_try = np.linspace(-20, 20, 200)
times_to_try = np.arange(0.2, 40.2, 0.2)

bar = progressbar.ProgressBar()
for time in bar(times_to_try):
    results = np.zeros(shape=[heights_to_try.shape[0], 3])
    for idx, height in enumerate(heights_to_try):
        hamiltonian = H0 + height * H1
        output_state = optimization.evolve_state(hamiltonian=hamiltonian,
                                                 initial_state=initial_state,
                                                 time=time)
        fid = qutip.fidelity(target_state, output_state)**2
        results[idx] = [time, height, fid]
    df_to_save = pd.DataFrame(results, columns=['t', 'height', 'fid'])
    outfile_name = os.path.join(output_file_basename, 't{:04.1f}'.format(time))
    df_to_save.to_csv(outfile_name)