Exemple #1
0
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)
Exemple #2
0
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)