Пример #1
0
def find_spectrum(fname, adj=None):
    ''' '''

    cells, spacing, zones, J, feedback = parse_qca_file(fname, one_zone=True)
    h, J = qca_to_coef(cells, spacing, J, adj=adj)
    h, J = normalized_coefs(h, J)

    # get clocking schedule
    s, eps, gamma = clock_schedule(scheme='linear')

    spectrum = Spectrum()

    spectrum.solve(h, J, eps, gamma, show=True, exact=False)
Пример #2
0
def find_spectrum(fname, adj=None):
    ''' '''

    cells, spacing, zones, J, feedback = parse_qca_file(fname, one_zone=True)
    h, J = qca_to_coef(cells, spacing, J, adj=adj)
    h, J = normalized_coefs(h,J)

    # get clocking schedule
    s, eps, gamma = clock_schedule(scheme='linear')

    spectrum = Spectrum()

    spectrum.solve(h, J, eps, gamma, show=True, exact=False)
Пример #3
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)
Пример #4
0
def find_true_spectrum(h, J, gmin=0, gmax=1., emin=0., emax=1., nsteps=100):
    ''' '''
    gmin = 1e-5
    gammas = np.linspace(gmax, gmin, nsteps)  # tranverse field scales
    eps = np.linspace(emin, emax, nsteps)  # ising problem scales

    s = np.linspace(0, 1, nsteps)  # annealing schedule parameter

    if len(h) > EXACT_THRESH:
        return

    true_spectrum = Spectrum()
    true_spectrum.solve(h, J, eps, gammas, exact=True, show=False)
    true_spec = true_spectrum.spectrum

    true_spec -= true_spec[:, 0].reshape([-1, 1])

    plt.plot(s, true_spec, 'x')
    plt.xlabel('Annealing parameter (s)', fontsize=FS)
    plt.ylabel('Energy', fontsize=FS)
    plt.show()
Пример #5
0
def find_true_spectrum(h, J, gmin=0, gmax=1., emin=0., emax=1., nsteps=100):
    ''' '''
    gmin = 1e-5
    gammas = np.linspace(gmax, gmin, nsteps)    # tranverse field scales
    eps = np.linspace(emin, emax, nsteps)          # ising problem scales

    s = np.linspace(0, 1, nsteps)   # annealing schedule parameter

    if len(h) > EXACT_THRESH:
        return

    true_spectrum = Spectrum()
    true_spectrum.solve(h, J, eps, gammas, exact=True, show=False)
    true_spec = true_spectrum.spectrum

    true_spec -= true_spec[:,0].reshape([-1,1])

    plt.plot(s, true_spec, 'x')
    plt.xlabel('Annealing parameter (s)', fontsize=FS)
    plt.ylabel('Energy', fontsize=FS)
    plt.show()
Пример #6
0
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]))
Пример #7
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)
Пример #8
0
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]))
Пример #9
0
def estimate_spectrum(h, J, gmin=0., gmax=1., emin=0., emax=1., nsteps=10):
    ''' '''
    gmin = 1e-5
    emin = 1e-5
    gammas = np.linspace(gmax, gmin, nsteps)  # tranverse field scales
    eps = np.linspace(emin, emax, nsteps)  # ising problem scales

    s = np.linspace(0, 1, nsteps)  # annealing schedule parameter
    gammas, eps = query_schedule(sched_file, s)

    # show recursive tree
    if False:
        tree = compute_rp_tree(J)
        show_tree(J, tree)

    # check if solvable using exact methods
    EXACT_check = EXACT and len(h) < EXACT_THRESH

    approx_spectrum = Spectrum()
    rp_spectrum = Spectrum()
    true_spectrum = Spectrum()

    # find approximate spectrum
    print('\nFinding approximate spectrum...')
    approx_spectrum.solve(h, J, eps, gammas, gset=0.5, rp_steps=10, show=False)
    approx_spec = approx_spectrum.spectrum

    if FULL_RP:
        # find more accurate approximate spectrum
        print('\nFinding more accurate spectrum...')
        rp_spectrum.solve(h, J, eps, gammas, gset=2.0, rp_steps=20, show=False)
        rp_spec = rp_spectrum.spectrum

    if EXACT_check:
        # find exact solution
        print('\nFinding true spectrum...')
        true_spectrum.solve(h, J, eps, gammas, exact=True, show=False)
        true_spec = true_spectrum.spectrum

    if ZERO:
        approx_spec -= approx_spec[:, 0].reshape([-1, 1])
        if FULL_RP:
            rp_spec -= rp_spec[:, 0].reshape([-1, 1])
        if EXACT_check:
            true_spec -= true_spec[:, 0].reshape([-1, 1])

    N = approx_spec.shape[1]
    if FULL_RP:
        N = min(N, rp_spec.shape[1])
    if EXACT_check:
        N = min(N, true_spec.shape[1])

    N -= 5
    # plotting
    plt.figure('Spectrum')

    plt.plot(s, approx_spec[:, :N], 'x', markersize=5)
    if FULL_RP:
        plt.plot(s, rp_spec[:, :N], 's')
    if EXACT_check:
        plt.plot(s, true_spec[:, :N], '-')

    plt.xlabel('Annealing Parameter (s)', fontsize=FS)
    plt.ylabel('$E$-$E_0$ (GHz)', fontsize=20)
    plt.ylim([0, 15])

    if SAVE:
        plt.savefig(os.path.join(IMG_DIR, 'test_spectrum.eps'),
                    bbox_inches='tight')

    plt.show()

    xl, xr = int(.3 * nsteps), int(.47 * nsteps)

    plt.figure('Zoom')

    plt.plot(s[xl:xr], approx_spec[xl:xr, :N], 'x', markersize=5)
    if FULL_RP:
        plt.plot(s[xl:xr], rp_spec[xl:xr, :N], 's')
    if EXACT_check:
        plt.plot(s[xl:xr], true_spec[xl:xr, :N], '-')

    plt.xlabel('Annealing Parameters (s)', fontsize=FS)
    plt.ylabel('$E$-$E_0$ (GHz)', fontsize=20)

    plt.xlim([s[xl], s[xr]])
    plt.ylim([1, 4.5])

    if SAVE:
        plt.savefig(os.path.join(IMG_DIR, 'test_zoom.eps'),
                    bbox_inches='tight')

    plt.show()

    if False:
        # compare_spectra(approx_spectrum, rp_spectrum)
        if EXACT_check:
            compare_spectra(rp_spectrum, true_spectrum)
        elif FULL_RP:
            compare_spectra(approx_spectrum, true_spectrum)
    return
    locate_crossings(s, spec)
Пример #10
0
def estimate_spectrum(h, J, gmin=0., gmax=1., emin=0., emax=1., nsteps=10):
    ''' '''
    gmin = 1e-5
    emin = 1e-5
    gammas = np.linspace(gmax, gmin, nsteps)    # tranverse field scales
    eps = np.linspace(emin, emax, nsteps)          # ising problem scales

    s = np.linspace(0, 1, nsteps)   # annealing schedule parameter
    gammas, eps = query_schedule(sched_file, s)

    # show recursive tree
    if False:
        tree = compute_rp_tree(J)
        show_tree(J, tree)

    # check if solvable using exact methods
    EXACT_check = EXACT and len(h) < EXACT_THRESH

    approx_spectrum = Spectrum()
    rp_spectrum = Spectrum()
    true_spectrum = Spectrum()

    # find approximate spectrum
    print('\nFinding approximate spectrum...')
    approx_spectrum.solve(h, J, eps, gammas, gset=0.5, rp_steps=10, show=False)
    approx_spec = approx_spectrum.spectrum

    if FULL_RP:
        # find more accurate approximate spectrum
        print('\nFinding more accurate spectrum...')
        rp_spectrum.solve(h, J, eps, gammas, gset=2.0, rp_steps=20, show=False)
        rp_spec = rp_spectrum.spectrum

    if EXACT_check:
        # find exact solution
        print('\nFinding true spectrum...')
        true_spectrum.solve(h, J, eps, gammas, exact=True, show=False)
        true_spec = true_spectrum.spectrum

    if ZERO:
        approx_spec -= approx_spec[:,0].reshape([-1,1])
        if FULL_RP:
            rp_spec -= rp_spec[:,0].reshape([-1,1])
        if EXACT_check:
            true_spec -= true_spec[:,0].reshape([-1,1])

    N = approx_spec.shape[1]
    if FULL_RP:
        N = min(N, rp_spec.shape[1])
    if EXACT_check:
        N = min(N, true_spec.shape[1])

    N -= 5
    # plotting
    plt.figure('Spectrum')

    plt.plot(s, approx_spec[:,:N], 'x', markersize=5)
    if FULL_RP:
        plt.plot(s, rp_spec[:,:N], 's')
    if EXACT_check:
        plt.plot(s, true_spec[:,:N], '-')

    plt.xlabel('Annealing Parameter (s)', fontsize=FS)
    plt.ylabel('$E$-$E_0$ (GHz)', fontsize=20)
    plt.ylim([0,15])

    if SAVE:
        plt.savefig(os.path.join(IMG_DIR, 'test_spectrum.eps'), bbox_inches='tight')

    plt.show()

    xl, xr = int(.3*nsteps), int(.47*nsteps)

    plt.figure('Zoom')

    plt.plot(s[xl:xr], approx_spec[xl:xr,:N], 'x', markersize=5)
    if FULL_RP:
        plt.plot(s[xl:xr], rp_spec[xl:xr,:N], 's')
    if EXACT_check:
        plt.plot(s[xl:xr], true_spec[xl:xr,:N], '-')

    plt.xlabel('Annealing Parameters (s)', fontsize=FS)
    plt.ylabel('$E$-$E_0$ (GHz)', fontsize=20)

    plt.xlim([s[xl],s[xr]])
    plt.ylim([1, 4.5])

    if SAVE:
        plt.savefig(os.path.join(IMG_DIR, 'test_zoom.eps'), bbox_inches='tight')

    plt.show()



    if False:
        # compare_spectra(approx_spectrum, rp_spectrum)
        if EXACT_check:
            compare_spectra(rp_spectrum, true_spectrum)
        elif FULL_RP:
            compare_spectra(approx_spectrum, true_spectrum)
    return
    locate_crossings(s, spec)