def main(fname, nsteps=100): ''' ''' print('\n\nRunning problem: {0}...'.format(os.path.splitext(fname)[0])) base = os.path.splitext(fname)[0] coef_file = base + '.txt' json_file = base + '.json' rt = int(os.path.basename(os.path.dirname(fname))) _h, _J = load_coef_file(coef_file) qbits, energies, spins, occ = load_json_file(json_file) N = len(qbits) h = [_h[k] for k in qbits] qbit_map = {qb: i for i, qb in enumerate(qbits)} J = np.zeros([N, N], dtype=float) for i, x in _J.items(): i = qbit_map[i] for j, v in x.items(): j = qbit_map[j] J[i, j] = J[j, i] = v s = np.linspace(0, 1, nsteps) gammas, eps = query_schedule(sched_file, s) # eps = np.linspace(0,1,nsteps) # gammas = np.linspace(1,0,nsteps) spec = Spectrum() if N < EXACT_THRESH: spec.solve(h, J, eps, gammas, show=SHOW, exact=True) else: spec.solve(h, J, eps, gammas, show=SHOW) if True: params = spec.ground_check(occ, show=SHOW) else: spec.build_causal(show=True) params = spec.pull_causal(occ, energies) append_data(params, rt, base)
def main(fname, nsteps=100): ''' ''' print('\n\nRunning problem: {0}...'.format(os.path.splitext(fname)[0])) base = os.path.splitext(fname)[0] coef_file = base+'.txt' json_file = base+'.json' rt = int(os.path.basename(os.path.dirname(fname))) _h, _J = load_coef_file(coef_file) qbits, energies, spins, occ = load_json_file(json_file) N = len(qbits) h = [_h[k] for k in qbits] qbit_map = {qb:i for i,qb in enumerate(qbits)} J = np.zeros([N,N], dtype=float) for i, x in _J.items(): i = qbit_map[i] for j, v in x.items(): j = qbit_map[j] J[i,j] = J[j,i] = v s = np.linspace(0,1,nsteps) gammas, eps = query_schedule(sched_file, s) # eps = np.linspace(0,1,nsteps) # gammas = np.linspace(1,0,nsteps) spec = Spectrum() if N < EXACT_THRESH: spec.solve(h, J, eps, gammas, show=SHOW, exact=True) else: spec.solve(h, J, eps, gammas, show=SHOW) if True: params = spec.ground_check(occ, show=SHOW) else: spec.build_causal(show=True) params = spec.pull_causal(occ, energies) append_data(params, rt, base)
def main(fname, nsteps=100): ''' ''' base = os.path.splitext(fname)[0] coef_file = base+'.txt' json_file = base+'.json' rt = int(os.path.basename(os.path.dirname(fname))) _h, _J = load_coef_file(coef_file) qbits, energies, spins, occ = load_json_file(json_file) N = len(qbits) h = [_h[k] for k in qbits] qbit_map = {qb:i for i,qb in enumerate(qbits)} J = np.zeros([N,N], dtype=float) for i, x in _J.items(): i = qbit_map[i] for j, v in x.items(): j = qbit_map[j] J[i,j] = J[j,i] = v s = np.linspace(0,1,nsteps) gammas, eps = query_schedule(sched_file, s) spec = Spectrum() spec.solve(h, J, eps, gammas, show=True, exact=True) spec.build_causal(show=False) spec.compute_eqs() pr = spec.predict_probs(rt) Es = [eps[-1]*e for e in energies] e_probs = spec.format_probs(occ, Es) for e in pr: print('{0:.4f} :: {1:.4f}:{2:.4f}'.format(e, e_probs[e], pr[e]))
def main(fname, nsteps=100): ''' ''' base = os.path.splitext(fname)[0] coef_file = base + '.txt' json_file = base + '.json' rt = int(os.path.basename(os.path.dirname(fname))) _h, _J = load_coef_file(coef_file) qbits, energies, spins, occ = load_json_file(json_file) N = len(qbits) h = [_h[k] for k in qbits] qbit_map = {qb: i for i, qb in enumerate(qbits)} J = np.zeros([N, N], dtype=float) for i, x in _J.items(): i = qbit_map[i] for j, v in x.items(): j = qbit_map[j] J[i, j] = J[j, i] = v s = np.linspace(0, 1, nsteps) gammas, eps = query_schedule(sched_file, s) spec = Spectrum() spec.solve(h, J, eps, gammas, show=True, exact=True) spec.build_causal(show=False) spec.compute_eqs() pr = spec.predict_probs(rt) Es = [eps[-1] * e for e in energies] e_probs = spec.format_probs(occ, Es) for e in pr: print('{0:.4f} :: {1:.4f}:{2:.4f}'.format(e, e_probs[e], pr[e]))