def expr_two_pcs_vs_rs(n_max, nth, ns, rflct, grid_divides): points = np.linspace(0, 1, grid_divides) rss = [(ra, rb) for ra in points for rb in points] cols = [ 'Nth', 'R', 'State', 'lambda', 'Aver_N', 'VN_Entropy', 'Helstrom_Bound', 'Chernoff_Bound', 'optimal_s', 'A_aver_N', 'B_aver_N', 'ra', 'rb' ] # cols = ['Nth', 'R', 'State', 'lambda', 'ra', 'rb', 'Aver_N', # 'A_N', 'B_N', 'VN_Entropy', 'Helstrom', 'Chernoff', 'S_opt'] df = pd.DataFrame(columns=cols) lmd = np.sqrt(ns / (1 + ns)) expr = QIExpr(n_max=n_max) expr.set_environment(reflectance=rflct, nth=nth) @log def set_laser(rs_t): expr.set_input_laser('PCS', lmd, rs_t) for rs in rss: set_laser(rs) expr.run_expr(qcb_approx=True) new_df = pd.DataFrame.from_dict({'res': expr.get_results()}, orient='index') df = df.append(new_df) write_data_to_file(df, n_max, nth, ns, rflct, grid_divides, cols)
def expr_three_qhb_vs_energy(method, nth, n_max, div1, div2, qcb_approx=True): # nss = np.linspace(0.01, 1, nss_divides) # lambdas = np.sqrt(nss / (1.0 + nss)) # divides: divides lambda cols = [ 'nmax', 'Nth', 'R', 'State', 'sqz', 'lambda', 'Aver_N', 'VN_Entropy', 'Helstrom_Bound', 'Chernoff_Bound', 'optimal_s', 'A_aver_N', 'B_aver_N', 'ra', 'rb' ] df = pd.DataFrame(columns=cols) l1 = np.sqrt(0.01 / (1 + 0.01)) lmds = (l1, ) # lmds = np.append(np.linspace(0.002, 0.452, div1), np.linspace(0.462, 0.602, div2)) names = ('TMSS', 'PS', 'PA', 'PSA', 'PAS', 'PCS') expr = QIExpr(n_max=n_max) expr.set_environment(reflectance=0.01, nth=nth) @log def set_laser(s_name, l): if s_name != 'PCS': expr.set_input_laser(s_name, l) else: # res = minimize(qcb_asym, np.array([0.2, 0.8]), args=(l, expr), # method=method, bounds=[(0, 1), (0, 1)]) # if l > 0.3: # res2 = minimize(qcb_asym, np.array([0.8, 0.8]), args=(l, expr), # method=method, bounds=[(0, 1), (0, 1)]) # if res2.fun < res: # res = res2 # ra, rb = res.x[0], res.x[1] # print("ra: {}, rb: {}".format(ra, rb)) # if (- 1e-6 < ra < 1e-6) and (- 1e-6 < rb < 1e-6): # ra, rb = 1, 1 expr.set_input_laser('PCS', l, rs=(0.11697, 0.948384)) filename = "../output/data/expr_3_qi_nmax_{}_nth_{}_g_{}+{}_{}_opt_qcb_{}.csv"\ .format(n_max, nth, div1, div2, datetime.today().strftime('%m-%d'), method) with open(filename, "a") as file: file.write("# Quantum Illumination Experiment 3.1\n") file.write('# Author: L. Fan\n') file.write('# Created on: {}\n\n'.format(str(datetime.now()))) file.write(','.join(cols) + '\n') for lmd in lmds: for name in names: set_laser(name, lmd) try: expr.run_expr(qcb_approx=qcb_approx) # print(expr.results_string()) file.write(expr.results_string() + '\n') except np.linalg.LinAlgError: file.write('# Singular Matrix lambda: {}'.format(lmd) + '\n') print("Singular Matrix") continue
def find_optimal_etgl(n_max, ns, nth): l = np.sqrt(ns / (1 + ns)) expr = QIExpr(n_max=n_max) expr.set_environment(reflectance=0.01, nth=nth) # # res1 = minimize(qcb_asym, np.array([0.2, 0.8]), args=(l, expr), # # method='L-BFGS-B', bounds=[(0, 1), (0, 1)]) # res2 = minimize(qcb_asym, np.array([0.2, 0.2]), args=(l, expr), # method='L-BFGS-B', bounds=[(0, 1), (0, 1)]) # res3 = minimize(qcb_sym, np.array([0.2]), args=(l, expr), # method='L-BFGS-B', bounds=[(0, 1)]) # # print(res1.fun, res1.x) # print(res2.fun, res2.x) expr.set_input_laser('PCS', lmd=l, rs=(0.11755415, 0.94959852)) expr.run_expr() print(expr.get_results())
def expr_two_pcs_vs_rs(n_max, nth, ns, rflct, l_divides, r_divides, qcb_approx=True): cols = [ 'nmax', 'Nth', 'R', 'State', 'lambda', 'Aver_N', 'VN_Entropy', 'Helstrom_Bound', 'Chernoff_Bound', 'optimal_s', 'A_aver_N', 'B_aver_N', 'ra', 'rb' ] points = np.linspace(0, 1, r_divides) rss = [(ra, rb) for ra in points for rb in points] lmds = np.linspace(0.05, 0.37, l_divides) # l1 = np.sqrt(ns / (1 + ns)) expr = QIExpr(n_max=n_max) expr.set_environment(reflectance=rflct, nth=nth) @log def set_laser(lmd, rs_t): expr.set_input_laser('PCS', lmd, rs_t) filename = "../output/data/expr_2_pcs_scan_nmax_{:d}_nth_{}_div_{:d}x{:d}_{}.csv" \ .format(n_max, nth, l_divides, r_divides, datetime.today().strftime('%m-%d')) with open(filename, "a") as file: file.write("# Quantum Illumination Experiment\n") file.write("# PCS state different ra and rb.\n") file.write("# n_max: {}, nth: {}, ns: {}, rflct: {}\n".format( n_max, nth, ns, rflct)) file.write('# Author: L. Fan\n') file.write('# Created on: {}\n'.format(str(datetime.now()))) file.write(','.join(cols) + '\n') for lmd in lmds: for rs in rss: set_laser(lmd, rs) try: expr.run_expr(qcb_approx=qcb_approx) file.write(expr.results_string() + '\n') except np.linalg.LinAlgError: file.write('# Singular Matrix lambda: {}'.format(lmd) + '\n') print("Singular Matrix") continue
def expr_three_qhb_vs_energy(nth, n_max, divides, qcb_approx=True): # nss = np.linspace(0.01, 1, nss_divides) # lambdas = np.sqrt(nss / (1.0 + nss)) # divides: divides lambda cols = [ 'Nth', 'R', 'State', 'lambda', 'Aver_N', 'VN_Entropy', 'Helstrom_Bound', 'Chernoff_Bound', 'optimal_s', 'A_aver_N', 'B_aver_N', 'ra', 'rb' ] df = pd.DataFrame(columns=cols) lambdas = { 'TMSS': np.linspace(0.001, 0.901, divides), 'PS': np.linspace(0.001, 0.751, divides), 'PA': np.linspace(0.001, 0.701, divides), 'PSA': np.linspace(0.001, 0.601, divides), 'PAS': np.linspace(0.001, 0.551, divides), 'PCS': np.linspace(0.001, 0.701, divides) } names = ('TMSS', 'PS', 'PA', 'PSA', 'PAS', 'PCS') # names = ('TMSS', 'PS', 'PSA') expr = QIExpr(n_max=n_max) expr.set_environment(reflectance=0.01, nth=nth) @log def set_laser(s_name, l): if s_name != 'PCS': expr.set_input_laser(s_name, l) else: expr.set_input_laser('PCS', l, rs=(0.4, 0.4)) for name in names: for lmd in lambdas[name]: set_laser(name, lmd) try: expr.run_expr(qcb_approx=qcb_approx) except Exception as e: print("%s" % str(e)) write_data_to_file(df, nth, divides, cols) new_df = pd.DataFrame.from_dict({'res': expr.get_results()}, orient='index') df = df.append(new_df) write_data_to_file(df, nth, divides, cols)
def special_pcs(n_max, nth): expr = QIExpr(n_max=n_max) expr.set_environment(reflectance=0.01, nth=nth) expr.set_input_laser('PCS', lmd=0.2985, rs=(0.4472107216, 1.0)) expr.run_expr(qcb_approx=True) print(expr.get_results())
def expr_three_qhb_vs_energy(nth, n_max, divides, qcb_approx=True): # nss = np.linspace(0.01, 1, nss_divides) # lambdas = np.sqrt(nss / (1.0 + nss)) # divides: divides lambda cols = [ 'nmax', 'Nth', 'R', 'State', 'lambda', 'Aver_N', 'VN_Entropy', 'Helstrom_Bound', 'Chernoff_Bound', 'optimal_s', 'A_aver_N', 'B_aver_N', 'ra', 'rb' ] df = pd.DataFrame(columns=cols) lambdas = { 'TMSS': np.linspace(0.001, 0.901, divides), 'PS': np.linspace(0.001, 0.751, divides), 'PA': np.linspace(0.001, 0.701, divides), 'PSA': np.linspace(0.001, 0.601, divides), 'PAS': np.linspace(0.001, 0.551, divides), 'PCS': np.linspace(0.3545, 0.701, divides) } # names = ('TMSS', 'PS', 'PA', 'PSA', 'PAS') names = ('PCS', ) expr = QIExpr(n_max=n_max) expr.set_environment(reflectance=0.01, nth=nth) @log def set_laser(s_name, l): if s_name != 'PCS': expr.set_input_laser(s_name, l) else: res = minimize(etgl_asym, np.array([0.2, 0.9]), args=(l, n_max), method='L-BFGS-B', bounds=[(0, 1), (0, 1)]) if l < 0.2: res2 = minimize(etgl_asym, np.array([0.3, 0.3]), args=(l, n_max), method='L-BFGS-B', bounds=[(0, 1), (0, 1)]) if res2.fun < res.fun: res = res2 ra, rb = res.x[0], res.x[1] if (-1e-6 < ra < 1e-6) and (-1e-6 < rb < 1e-6): ra, rb = 1, 1 expr.set_input_laser('PCS', l, rs=(ra, rb)) for name in names: for lmd in lambdas[name]: set_laser(name, lmd) try: expr.run_expr(qcb_approx=qcb_approx) except Exception as e: print("%s" % str(e)) write_data_to_file(df, n_max, nth, divides, cols) new_df = pd.DataFrame.from_dict({'res': expr.get_results()}, orient='index') df = df.append(new_df) write_data_to_file(df, n_max, nth, divides, cols)
def special_pcs(n_max, nth): expr = QIExpr(n_max=n_max) expr.set_environment(reflectance=0.01, nth=nth) expr.set_input_laser('PCS', lmd=0.099503719020998915, rs=(1.0, 0.14019005)) expr.run_expr(qcb_approx=True) print(expr.get_results())
def run_all_states(state_names, n_max, nth, ns, rflct, rs, df): """ run experiments given the provided parameters Parameters ---------- state_names: tuple of string, indicating input states n_max: integer, truncated photon numbers nth: double, average thermal noise number ns: double, N_s parameter of the two mode squeezed state rflct: double, reflectance of the target object rs: tuple of double, parameters for PCS states df: dataframe, running results Returns ------- df: a pandas dataframe recording running results """ lmd = np.sqrt(ns / (1 + ns)) expr = QIExpr(n_max) expr.set_environment(rflct, nth) # print("\nHelstrom Bounds\n") for name in state_names: if name != 'PCS': expr.set_input_laser(name, lmd) else: expr.set_input_laser('PCS', lmd, rs) expr.run_expr() new_df = pd.DataFrame.from_dict({'res': expr.get_results()}, orient='index') df = df.append(new_df) return df