Beispiel #1
0
def find_fidelity(graph, critical_time):
    cost = hamiltonian.HamiltonianMIS(graph, IS_subspace=True)
    driver = hamiltonian.HamiltonianDriver(IS_subspace=True, graph=graph)

    def schedule(t, T):
        # Linear ramp on the detuning, experiment-like ramp on the driver
        k = 50
        a = .95
        b = 3.1
        x = t / T
        amplitude = (
                -1 / (1 + np.e ** (k * (x - a))) ** b - 1 / (1 + np.e ** (-k * (x - (1 - a)))) ** b + 1) / \
                    (-1 / ((1 + np.e ** (k * (1 / 2 - a))) ** b) - 1 / (
                            (1 + np.e ** (-k * (1 / 2 - (1 - a)))) ** b) + 1)
        cost.energies = (3 * 2 * (1 / 2 - x), )
        driver.energies = (amplitude, )

    ad = SimulateAdiabatic(graph=graph,
                           hamiltonian=[cost, driver],
                           cost_hamiltonian=cost,
                           IS_subspace=True)

    final_state = ad.run(critical_time, schedule, method='odeint')[0][-1]
    cost.energies = (1, )
    optimum_indices = np.argwhere(
        cost._diagonal_hamiltonian == cost.optimum).T[0]
    # Construct an operator that is zero everywhere except at the optimum
    optimum = np.zeros(cost._diagonal_hamiltonian.shape)
    optimum[optimum_indices] = 1
    optimum_overlap = cost.optimum_overlap(final_state)
    return final_state, optimum, optimum_overlap
def find_ratio(tails_graph, graph, detuning_plateau, tf):
    cost = hamiltonian.HamiltonianMIS(graph, IS_subspace=True)
    print('Starting driver')
    driver = hamiltonian.HamiltonianDriver(IS_subspace=True, graph=graph)
    print('Starting rydberg')
    if tails_graph is not None:
        rydberg = hamiltonian.HamiltonianRydberg(tails_graph,
                                                 graph,
                                                 IS_subspace=True,
                                                 energies=(2 * np.pi, ))
        ad = SimulateAdiabatic(graph=graph,
                               hamiltonian=[cost, driver, rydberg],
                               cost_hamiltonian=cost,
                               IS_subspace=True)
    else:
        ad = SimulateAdiabatic(graph=graph,
                               hamiltonian=[cost, driver],
                               cost_hamiltonian=cost,
                               IS_subspace=True)

    def schedule_cubic(t, T):
        cubic_ys = 2 * np.pi * np.array([
            11.5, detuning_plateau + .5, detuning_plateau,
            detuning_plateau - .5, -11.5
        ])
        cubic_xs = np.array([
            .312, (T / 2 - .312) / 1.35 + .312, T / 2,
            T - .312 - (T / 2 - .312) / 1.35, T - .312
        ])
        if t < .312:
            driver.energies = (2 * np.pi * 2 * t / .312, )
            cost.energies = (2 * np.pi * 11.5, )
        elif .312 <= t <= T - .312:
            driver.energies = (2 * np.pi * 2, )
            cost.energies = (scipy.interpolate.interp1d(cubic_xs,
                                                        cubic_ys,
                                                        kind='cubic')(t), )
        else:
            driver.energies = (2 * np.pi * 2 * (T - t) / .312, )
            cost.energies = (-2 * np.pi * 11.5, )

    print('Starting evolution')
    states, data = ad.run(tf,
                          schedule_cubic,
                          num=int(400 * tf),
                          method='trotterize',
                          full_output=False)
    np.savez_compressed('{}x{}_{}_{}_{}_trotterize_highres.npz'.format(
        size, size, graph_index, np.round(np.abs(detuning_plateau), 2),
        np.round(np.abs(tf), 2)),
                        state=states[-1])
Beispiel #3
0
def find_ratio(tails_graph, graph, tf):
    cost = hamiltonian.HamiltonianMIS(graph, IS_subspace=True)
    driver = hamiltonian.HamiltonianDriver(IS_subspace=True, graph=graph)

    def schedule(t, T):
        # Linear ramp on the detuning, experiment-like ramp on the driver
        k = 50
        a = .95
        b = 3.1
        x = t / T
        amplitude = (
                            -1 / (1 + np.e ** (k * (x - a))) ** b - 1 / (1 + np.e ** (-k * (x - (1 - a)))) ** b + 1) / \
                    (-1 / ((1 + np.e ** (k * (1 / 2 - a))) ** b) - 1 / (
                            (1 + np.e ** (-k * (1 / 2 - (1 - a)))) ** b) + 1)
        cost.energies = (11 * 2 * (1 / 2 - x), )
        driver.energies = (2 * amplitude, )

    # Uncomment this to print the schedule at t=0
    # schedule(0, 1)
    # print(cost.hamiltonian*2*np.pi)
    # print(driver.hamiltonian)
    if tails_graph is None:
        ad = SimulateAdiabatic(graph=graph,
                               hamiltonian=[cost, driver],
                               cost_hamiltonian=cost,
                               IS_subspace=True)
    else:
        rydberg = hamiltonian.HamiltonianRydberg(tails_graph,
                                                 graph,
                                                 IS_subspace=True,
                                                 energies=(1, ))
        ad = SimulateAdiabatic(graph=graph,
                               hamiltonian=[cost, driver, rydberg],
                               cost_hamiltonian=cost,
                               IS_subspace=True)
    print('running')
    states, data = ad.run(tf, schedule, method='odeint')
    print(data)
    times = data['t']
    is_overlaps = np.zeros((graph.mis_size + 1, len(states)))
    cost.energies = (1, )
    for j in range(graph.mis_size + 1):
        projector = (cost._diagonal_hamiltonian == j)
        for i in range(len(states)):
            is_overlaps[j, i] = np.sum(np.abs(states[i])**2 * projector)
    print(is_overlaps)
    for j in range(graph.mis_size + 1):
        plt.scatter(times, is_overlaps[j], label=str(j))
    plt.legend()
    plt.show()
Beispiel #4
0
def find_critical_time(graph, critical_optimum_overlap):
    cost = hamiltonian.HamiltonianMIS(graph, IS_subspace=True)
    driver = hamiltonian.HamiltonianDriver(IS_subspace=True, graph=graph)

    def schedule(t, T):
        # Linear ramp on the detuning, experiment-like ramp on the driver
        k = 50
        a = .95
        b = 3.1
        x = t / T
        amplitude = (
                -1 / (1 + np.e ** (k * (x - a))) ** b - 1 / (1 + np.e ** (-k * (x - (1 - a)))) ** b + 1) / \
                    (-1 / ((1 + np.e ** (k * (1 / 2 - a))) ** b) - 1 / (
                            (1 + np.e ** (-k * (1 / 2 - (1 - a)))) ** b) + 1)
        cost.energies = (3 * 2 * (1 / 2 - x), )
        driver.energies = (amplitude, )

    ad = SimulateAdiabatic(graph=graph,
                           hamiltonian=[cost, driver],
                           cost_hamiltonian=cost,
                           IS_subspace=True)

    def compute_final_state(T):
        final_state = ad.run(T, schedule, method='odeint')[0][-1]
        cost.energies = (1, )
        optimum_overlap = cost.optimum_overlap(final_state)
        return final_state, optimum_overlap

    def cost_function(T):
        final_state, optimum_overlap = compute_final_state(T)
        print(T, optimum_overlap)
        return optimum_overlap - critical_optimum_overlap

    #return basinhopping(cost_function, 35, niter=3, minimizer_kwargs={'bounds':[(20,50)]})['x']
    return brentq(cost_function, 20, 50, xtol=1e-5)
def eit_simulation(graph, noise_model=None, show_graph=False, gamma=1, delta: float = 0):
    if show_graph:
        nx.draw(graph)
        plt.show()
    # Generate the driving and Rydberg Hamiltonians
    if noise_model == 'continuous':
        laser1 = hamiltonian.HamiltonianDriver(transition=(1, 2), IS_subspace=True, graph=graph, code=rydberg)
        laser2 = hamiltonian.HamiltonianDriver(transition=(0, 1), IS_subspace=True, graph=graph, code=rydberg)
        rydberg_hamiltonian_cost = hamiltonian.HamiltonianMIS(graph, IS_subspace=True, code=rydberg)
        if delta != 0:
            detuning = hamiltonian.HamiltonianEnergyShift(code=rydberg, IS_subspace=True, graph=graph,
                                                          energies=[delta])
        spontaneous_emission = lindblad_operators.SpontaneousEmission(graph=graph, transition=(1, 2), rates=[gamma],
                                                                      IS_subspace=True, code=rydberg)

        # Initialize adiabatic algorithm
        if delta != 0:
            simulation = SimulateAdiabatic(graph, hamiltonian=[laser1, laser2, detuning],
                                           cost_hamiltonian=rydberg_hamiltonian_cost, IS_subspace=True,
                                           noise_model='continuous', code=rydberg, noise=[spontaneous_emission])
        else:
            simulation = SimulateAdiabatic(graph, hamiltonian=[laser1, laser2],
                                           cost_hamiltonian=rydberg_hamiltonian_cost, IS_subspace=True,
                                           noise_model='continuous', code=rydberg, noise=[spontaneous_emission])
        return simulation

    elif noise_model == 'monte_carlo':
        laser1 = hamiltonian.HamiltonianDriver(transition=(1, 2), IS_subspace=True, graph=graph, code=rydberg)
        laser2 = hamiltonian.HamiltonianDriver(transition=(0, 1), IS_subspace=True, graph=graph, code=rydberg)
        rydberg_hamiltonian_cost = hamiltonian.HamiltonianMIS(graph, IS_subspace=True, code=rydberg)
        spontaneous_emission = lindblad_operators.SpontaneousEmission(graph=graph, transition=(1, 2), rates=[gamma],
                                                                      IS_subspace=True, code=rydberg)

        # Initialize adiabatic algorithm
        if delta != 0:
            detuning = hamiltonian.HamiltonianEnergyShift(code=rydberg, IS_subspace=True, graph=graph, energies=[delta])
            simulation = SimulateAdiabatic(graph, hamiltonian=[laser1, laser2, detuning],
                                       cost_hamiltonian=rydberg_hamiltonian_cost, IS_subspace=True,
                                       noise_model='monte_carlo', code=rydberg, noise=[spontaneous_emission])
        else:
            simulation = SimulateAdiabatic(graph, hamiltonian=[laser1, laser2],
                                           cost_hamiltonian=rydberg_hamiltonian_cost, IS_subspace=True,
                                           noise_model='monte_carlo', code=rydberg, noise=[spontaneous_emission])
        return simulation
Beispiel #6
0
def adiabatic_simulation(graph,
                         show_graph=False,
                         IS_subspace=False,
                         noisy=False,
                         trotterize=True):
    if show_graph:
        nx.draw(graph)
        plt.show()
    # Generate the driving and Rydberg Hamiltonians
    if not noisy:
        laser = hamiltonian.HamiltonianDriver(IS_subspace=IS_subspace,
                                              graph=graph)
        detuning = hamiltonian.HamiltonianMIS(graph, IS_subspace=IS_subspace)
        rydberg_hamiltonian_cost = hamiltonian.HamiltonianMIS(
            graph, IS_subspace=IS_subspace)
        # Initialize adiabatic algorithm
        simulation = SimulateAdiabatic(
            graph,
            hamiltonian=[laser, detuning],
            cost_hamiltonian=rydberg_hamiltonian_cost,
            IS_subspace=IS_subspace)
    else:
        laser = hamiltonian.HamiltonianDriver(IS_subspace=IS_subspace,
                                              graph=graph)
        detuning = hamiltonian.HamiltonianMIS(graph, IS_subspace=IS_subspace)
        rydberg_hamiltonian_cost = hamiltonian.HamiltonianMIS(
            graph, IS_subspace=IS_subspace)
        if trotterize:
            spontaneous_emission = quantum_channels.AmplitudeDampingChannel(
                graph=graph, IS_subspace=IS_subspace, rates=(.1, ))
        else:
            spontaneous_emission = lindblad_operators.SpontaneousEmission(
                graph=graph, IS_subspace=IS_subspace, rates=(.1, ))

        # Initialize adiabatic algorithm
        simulation = SimulateAdiabatic(
            graph,
            hamiltonian=[laser, detuning],
            noise_model='continuous',
            noise=[spontaneous_emission],
            cost_hamiltonian=rydberg_hamiltonian_cost,
            IS_subspace=IS_subspace)
    return simulation
def adiabatic_simulation(graph, show_graph=False, IS_subspace=True):
    if show_graph:
        nx.draw(graph)
        plt.show()
    # Generate the driving and Rydberg Hamiltonians
    laser = hamiltonian.HamiltonianDriver(IS_subspace=IS_subspace, graph=graph)
    detuning = hamiltonian.HamiltonianMIS(graph, IS_subspace=IS_subspace)
    rydberg_hamiltonian_cost = hamiltonian.HamiltonianMIS(graph, IS_subspace=IS_subspace)
    graph.mis_size = int(np.max(rydberg_hamiltonian_cost.hamiltonian))
    print('Degeneracy',
          len(np.argwhere(rydberg_hamiltonian_cost.hamiltonian == np.max(rydberg_hamiltonian_cost.hamiltonian)).T[0]))
    # Initialize adiabatic algorithm
    simulation = SimulateAdiabatic(graph, hamiltonian=[laser, detuning], cost_hamiltonian=rydberg_hamiltonian_cost,
                                   IS_subspace=IS_subspace)
    return simulation
Beispiel #8
0
def performance_vs_alpha():
    # alpha = gamma * omega^2/(delta^2 T)
    graph = line_graph(n=3)
    gammas = np.array([1, 5, 10])
    times = np.array([1, 5, 10])
    deltas = np.array([20, 30])
    omegas = np.array([1, 5, 10])
    for (g, d, o) in zip(gammas, deltas, omegas):
        # Find the performance vs alpha
        laser = EffectiveOperatorHamiltonian(graph=graph)
        dissipation = EffectiveOperatorDissipation(graph=graph)
        rydberg_hamiltonian_cost = hamiltonian.HamiltonianMIS(graph, IS_subspace=True, code=qubit)
        adiabatic = SimulateAdiabatic(hamiltonian=[laser], noise = [dissipation], noise_model='continuous',
                                      graph=graph, IS_subspace=True, cost_hamiltonian=rydberg_hamiltonian_cost)
        def schedule(t, tf):
            phi = (tf-t)/tf*np.pi/2
            laser.omega_g = np.cos(phi)
            laser.omega_r = np.sin(phi)
            dissipation.omega_g = np.cos(phi)
            dissipation.omega_r = np.sin(phi)
        performance = adiabatic.performance_vs_total_time(times, schedule=schedule, verbose=True, method='odeint')[0]
        alphas = g * o**2/(d**2 * times)
        plt.scatter(alphas, performance)
    plt.show()
Beispiel #9
0
def eit_steady_state(graph, show_graph=False, gamma=1):
    if show_graph:
        nx.draw(graph)
        plt.show()
    # Generate the driving and Rydberg Hamiltonians
    laser1 = hamiltonian.HamiltonianDriver(transition=(1, 2),
                                           IS_subspace=True,
                                           graph=graph,
                                           code=rydberg)
    laser2 = hamiltonian.HamiltonianDriver(transition=(0, 1),
                                           IS_subspace=True,
                                           graph=graph,
                                           code=rydberg)
    rydberg_hamiltonian_cost = hamiltonian.HamiltonianMIS(graph,
                                                          IS_subspace=True,
                                                          code=rydberg)
    spontaneous_emission = lindblad_operators.SpontaneousEmission(
        graph=graph,
        transition=(1, 2),
        rates=[gamma],
        IS_subspace=True,
        code=rydberg)

    # Initialize adiabatic algorithm
    simulation = SimulateAdiabatic(graph,
                                   hamiltonian=[laser1, laser2],
                                   cost_hamiltonian=rydberg_hamiltonian_cost,
                                   IS_subspace=True,
                                   noise_model='continuous',
                                   code=rydberg,
                                   noise=[spontaneous_emission])

    master_equation = LindbladMasterEquation(
        hamiltonians=[laser1, laser2], jump_operators=[spontaneous_emission])
    initial_state = State(tools.outer_product(
        np.array([[0, 0, 0, 0, 0, 0, 0, 1]]).T,
        np.array([[0, 0, 0, 0, 0, 0, 0, 1]]).T),
                          code=rydberg,
                          IS_subspace=True,
                          is_ket=False)

    print(master_equation.steady_state(initial_state))

    return simulation
def track_eigenstate_populations(graph, tails_graph, grid, k=2):
    n_points = 7
    times_exp = 2**np.linspace(-2.5, 4.5 / 6 *
                               (n_points - 1) - 2.5, n_points) + .312 * 2
    t_max = times_exp[6]
    cost = hamiltonian.HamiltonianMIS(graph, IS_subspace=True)
    # print('Starting driver')
    driver = hamiltonian.HamiltonianDriver(IS_subspace=True, graph=graph)
    # print('Starting rydberg')
    if tails_graph is not None:
        rydberg = hamiltonian.HamiltonianRydberg(tails_graph,
                                                 graph,
                                                 IS_subspace=True,
                                                 energies=(2 * np.pi, ))
    pulse = np.loadtxt('for_AWG_{}.000000.txt'.format(6))
    t_pulse_max = np.max(pulse[:, 0]) - 2 * 0.312
    max_detuning = np.max(pulse[:, 2])

    def schedule_old(t, T):
        # Linear ramp on the detuning, experiment-like ramp on the driver
        k = 50
        a = .95
        b = 3.1
        x = t / T
        amplitude = (
                            -1 / (1 + np.e ** (k * (x - a))) ** b - 1 / (1 + np.e ** (-k * (x - (1 - a)))) ** b + 1) / \
                    (-1 / ((1 + np.e ** (k * (1 / 2 - a))) ** b) - 1 / (
                            (1 + np.e ** (-k * (1 / 2 - (1 - a)))) ** b) + 1)
        cost.energies = (-2 * np.pi * 11 * 2 * (1 / 2 - t / T),
                         )  # (2 * np.pi * (-(11 + 15) / T * t + 15),)
        driver.energies = (2 * np.pi * 2 * amplitude,
                           )  # (2 * np.pi * 2 * amplitude,)

    def schedule_exp_optimized(t, T):
        if t < .312:
            driver.energies = (2 * np.pi * 2 * t / .312, )
            cost.energies = (2 * np.pi * 15, )
        elif .312 <= t <= T - .312:
            t_pulse = (t - 0.312) / (T - 2 * 0.312) * t_pulse_max + 0.312
            driver.energies = (
                2 * np.pi * np.interp(t_pulse, pulse[:, 0], pulse[:, 1] / 2), )
            cost.energies = (2 * np.pi *
                             np.interp(t_pulse, pulse[:, 0], -pulse[:, 2]), )
        else:
            driver.energies = (2 * np.pi * 2 * (T - t) / .312, )
            cost.energies = (-2 * np.pi * max_detuning, )
        # print(t, cost.energies)

    def schedule_exp_linear(t, T):
        if t < .312:
            driver.energies = (2 * np.pi * 2 * t / .312, )
            cost.energies = (2 * np.pi * 15, )
        elif .312 <= t <= T - .312:
            driver.energies = (2 * np.pi * 2, )
            cost.energies = (2 * np.pi * (-(11 + 15) / (T - 2 * .312) *
                                          (t - .312) + 15), )
        else:
            driver.energies = (2 * np.pi * 2 * (T - t) / .312, )
            cost.energies = (-2 * np.pi * 11, )

    def eigs(t):
        schedule_exp_linear(t, t_max)
        eigval, eigvec = eq.eig(which='S', k=k)
        return eigval - eigval[0], eigvec

    if tails_graph is not None:
        eq = schrodinger_equation.SchrodingerEquation(
            hamiltonians=[cost, driver, rydberg])

        ad = SimulateAdiabatic(graph=graph,
                               hamiltonian=[cost, driver, rydberg],
                               cost_hamiltonian=cost,
                               IS_subspace=True)
    else:
        eq = schrodinger_equation.SchrodingerEquation(
            hamiltonians=[cost, driver])

        ad = SimulateAdiabatic(graph=graph,
                               hamiltonian=[cost, driver],
                               cost_hamiltonian=cost,
                               IS_subspace=True)
    print('starting evolution')

    states, data = ad.run(t_max,
                          schedule_exp_linear,
                          num=int(60 * t_max),
                          method='odeint',
                          full_output=True)
    print('finished evolution')
    times = data['t']
    start_index = len(times) // 2
    times = times[start_index:]
    states = states[start_index:]
    populations = np.zeros((len(times), k))
    energies = np.zeros((len(times), k))
    for (i, time) in enumerate(times):
        print(i)
        eigval, eigvecs = eigs(time)
        populations[i] = (np.abs(eigvecs @ states[i])**2).flatten()
        energies[i] = eigval / (2 * np.pi)
    populations = np.log10(populations)
    from matplotlib.collections import LineCollection
    fig, ax = plt.subplots()
    norm = plt.Normalize(-5, np.max(populations))
    for i in range(energies.shape[1]):
        points = np.array([times, energies[:, i]]).T.reshape(-1, 1, 2)
        segments = np.concatenate([points[:-1], points[1:]], axis=1)
        lc = LineCollection(segments, cmap='coolwarm', norm=norm)
        # Set the values used for colormapping
        lc.set_array(populations[:-1, i])
        lc.set_linewidth(1)
        line = ax.add_collection(lc)
    cbar = fig.colorbar(line, ax=ax)
    cbar.ax.set_ylabel(r'$\log_{10}(\rm{population})$')
    ax.set_xlim(np.min(times), np.max(times))
    ax.set_xlabel(r'Time ($\mu$s)')
    ax.set_ylabel(r'Eigenenergy (MHz)')
    ax.set_ylim(np.min(energies) - .3, np.max(energies))
    # ax.annotate(r'$r_{0\rightarrow j} = \sum_\mu |\langle j |c_\mu |0\rangle |^2$', xy=(0.4, 0.1), xycoords='data')
    plt.show()

    fig, ax = plt.subplots()
    deltas = np.zeros(len(times))
    print(times)
    for (i, time) in enumerate(times):
        schedule_exp_linear(time, t_max)
        deltas[i] = cost.energies[0] / (2 * np.pi)
    print(deltas)
    norm = plt.Normalize(-5, np.max(populations))
    for i in range(energies.shape[1]):
        points = np.array([deltas, energies[:, i]]).T.reshape(-1, 1, 2)
        segments = np.concatenate([points[:-1], points[1:]], axis=1)
        lc = LineCollection(segments, cmap='coolwarm', norm=norm)
        # Set the values used for colormapping
        lc.set_array(populations[:-1, i])
        lc.set_linewidth(1)
        line = ax.add_collection(lc)
    cbar = fig.colorbar(line, ax=ax)
    cbar.ax.set_ylabel(r'$\log_{10}(\rm{population})$')
    ax.set_xlim(np.max(deltas), np.min(deltas))
    ax.set_xlabel(r'$\Delta$ (MHz)')
    ax.set_ylabel(r'Eigenenergy (MHz)')
    ax.set_ylim(np.min(energies) - .3, np.max(energies))
    # ax.annotate(r'$r_{0\rightarrow j} = \sum_\mu |\langle j |c_\mu |0\rangle |^2$', xy=(0.4, 0.1), xycoords='data')
    plt.show()

    fig, ax = plt.subplots(3, 5)

    probs = np.abs(eigvecs)**2
    print(probs[:, :10])
    for l in range(k):
        i = l // 5
        j = l % 5
        layout = grid.copy().flatten().astype(float)
        layout[layout == 0] = -5
        layout[layout == 1] = 0
        layout_temp = layout.copy()
        for m in range(probs.shape[1]):
            layout_temp[layout == 0] = layout_temp[
                layout == 0] + (1 - graph.independent_sets[m]) * probs[l, m]
        ax[i][j].imshow(layout_temp.reshape(grid.shape))
        ax[i][j].set_axis_off()
        ax[i][j].text(-0.1,
                      1.05,
                      '$\lambda${}'.format(str(l)),
                      transform=ax[i][j].transAxes,
                      size=10,
                      weight='bold')

    plt.show()
def find_ratio(tails_graph, graph, tf, graph_index=None, size=None):
    cost = hamiltonian.HamiltonianMIS(graph, IS_subspace=True)
    # print('Starting driver')
    driver = hamiltonian.HamiltonianDriver(IS_subspace=True, graph=graph)
    # print('Starting rydberg')
    if tails_graph is not None:
        rydberg = hamiltonian.HamiltonianRydberg(tails_graph,
                                                 graph,
                                                 IS_subspace=True,
                                                 energies=(2 * np.pi, ))
    pulse = np.loadtxt('for_AWG_{}.000000.txt'.format(6))
    t_pulse_max = np.max(pulse[:, 0]) - 2 * 0.312

    def schedule(t, T):
        # Linear ramp on the detuning, experiment-like ramp on the driver
        k = 50
        a = .95
        b = 3.1
        x = t / T
        amplitude = (
                            -1 / (1 + np.e ** (k * (x - a))) ** b - 1 / (1 + np.e ** (-k * (x - (1 - a)))) ** b + 1) / \
                    (-1 / ((1 + np.e ** (k * (1 / 2 - a))) ** b) - 1 / (
                            (1 + np.e ** (-k * (1 / 2 - (1 - a)))) ** b) + 1)
        cost.energies = (2 * np.pi * (-(11 + 15) / T * t + 15), )
        driver.energies = (2 * np.pi * 2 * amplitude, )

    def schedule_old(t, T):
        # Linear ramp on the detuning, experiment-like ramp on the driver
        k = 50
        a = .95
        b = 3.1
        x = t / T
        amplitude = (
                            -1 / (1 + np.e ** (k * (x - a))) ** b - 1 / (1 + np.e ** (-k * (x - (1 - a)))) ** b + 1) / \
                    (-1 / ((1 + np.e ** (k * (1 / 2 - a))) ** b) - 1 / (
                            (1 + np.e ** (-k * (1 / 2 - (1 - a)))) ** b) + 1)
        cost.energies = (-2 * np.pi * 11 * 2 * (1 / 2 - t / T),
                         )  # (2 * np.pi * (-(11 + 15) / T * t + 15),)
        driver.energies = (2 * np.pi * 2 * amplitude,
                           )  # (2 * np.pi * 2 * amplitude,)

    def schedule_exp_optimized(t, T):
        if t < .312:
            driver.energies = (2 * np.pi * 2 * t / .312, )
            cost.energies = (2 * np.pi * 15, )
        elif .312 <= t <= T - .312:
            t_pulse = (t - 0.312) / (T - 2 * 0.312) * t_pulse_max + 0.312
            driver.energies = (
                2 * np.pi * np.interp(t_pulse, pulse[:, 0], pulse[:, 1] / 2), )
            cost.energies = (2 * np.pi *
                             np.interp(t_pulse, pulse[:, 0], -pulse[:, 2]), )
        else:
            driver.energies = (2 * np.pi * 2 * (T - t) / .312, )
            cost.energies = (-2 * np.pi * 11, )
        # print(t, cost.energies)

    def schedule_exp_linear(t, T):
        if t < .312:
            driver.energies = (2 * np.pi * 2 * t / .312, )
            cost.energies = (2 * np.pi * 15, )
        elif .312 <= t <= T - .312:
            driver.energies = (2 * np.pi * 2, )
            cost.energies = (2 * np.pi * (-(11 + 15) / (T - 2 * .312) *
                                          (t - .312) + 15), )
        else:
            driver.energies = (2 * np.pi * 2 * (T - t) / .312, )
            cost.energies = (-2 * np.pi * 11, )

    # print(t, cost.energies)
    # Uncomment this to print the schedule at t=0
    # schedule(0, 1)
    # print(cost.hamiltonian*2*np.pi)
    # print(driver.hamiltonian)
    if tails_graph is None:
        ad = SimulateAdiabatic(graph=graph,
                               hamiltonian=[cost, driver],
                               cost_hamiltonian=cost,
                               IS_subspace=True)
    else:
        ad = SimulateAdiabatic(graph=graph,
                               hamiltonian=[cost, driver, rydberg],
                               cost_hamiltonian=cost,
                               IS_subspace=True)
    # print('Starting evolution')
    ars = []
    probs = []
    for i in range(len(tf)):
        states, data = ad.run(tf[i],
                              schedule_exp_linear,
                              num=int(20 * tf[i]),
                              method='odeint',
                              full_output=False)
        cost.energies = (1, )
        ar = cost.approximation_ratio(states[-1])
        prob = cost.optimum_overlap(states[-1])
        # np.savez_compressed('{}x{}_{}_{}.npz'.format(size, size, graph_index, i), state=states[-1])
        print(tf[i], ar, prob)
        ars.append(ar)
        probs.append(prob)
    return ars, probs
Beispiel #12
0
    deg.append(graph.degeneracy)    #res = scipy.optimize.minimize(lambda dr: k_alpha(dr, graph=graph, verbose=True), [1.], bounds=[(0, 3)])
    #print(res)

    def schedule_hybrid(t, tf, delta_r_bar=0):
        phi = (tf - t) / tf * np.pi / 2
        energy_shift.energies = (delta_r_bar * np.sin(phi) ** 2,)
        laser.omega_g = np.cos(phi)
        laser.omega_r = np.sin(phi)
        dissipation.omega_g = np.cos(phi)
        dissipation.omega_r = np.sin(phi)

    from qsim.graph_algorithms.adiabatic import SimulateAdiabatic
    laser = EffectiveOperatorHamiltonian(graph=graph, IS_subspace=True, energies=(1,), omega_g=1, omega_r=1)
    energy_shift = hamiltonian.HamiltonianEnergyShift(IS_subspace=True, graph=graph, index=0)
    dissipation = EffectiveOperatorDissipation(graph=graph, omega_r=1, omega_g=1, rates=(1,))
    eq = SimulateAdiabatic(graph=graph, hamiltonian=[laser, energy_shift], noise_model='continuous', noise=[dissipation],
                           cost_hamiltonian=energy_shift)

    #eq.spectrum_vs_time(1, schedule_hybrid, num=500, plot=True)
    times = np.linspace(.01, .95, 500)
    eigvecs, indices = eq.groundstate_ordering_vs_time(times, schedule_hybrid, verbose=True)
    #rates_better_reit = np.zeros(len(times))
    rates_self_reit = np.zeros(len(times))
    rates_out_reit = np.zeros(len(times))
    for i in range(len(times)):
        schedule_hybrid(times[i], 1)
        overlap = 0
        overlap_self = 0
        for op in dissipation.jump_operators:
            ground_state = eigvecs[i, 0, :, np.newaxis]
            overlap_self = overlap_self + (np.abs(ground_state.conj().T @ op @ ground_state) ** 2)[0, 0]
            overlap = overlap +  (ground_state.conj().T @ op.conj().T @ op @ ground_state)[0, 0]
def adiabatic_simulation(graph, show_graph=False, approximate=False):
    if show_graph:
        nx.draw(graph)
        plt.show()
    if approximate:
        laser = hamiltonian.HamiltonianDriver(transition=(0, 1),
                                              IS_subspace=True,
                                              graph=graph,
                                              energies=(Omega_g * Omega_r /
                                                        delta, ))
        detuning = hamiltonian.HamiltonianMIS(graph, IS_subspace=True)
        spontaneous_emission1 = lindblad_operators.SpontaneousEmission(
            graph=graph,
            transition=(1, 1),
            rates=[(Omega_g / delta)**2 * Gamma],
            IS_subspace=True)
        spontaneous_emission2 = lindblad_operators.SpontaneousEmission(
            graph=graph,
            transition=(0, 1),
            rates=[(Omega_r / delta)**2 * Gamma],
            IS_subspace=True)
        rydberg_hamiltonian_cost = hamiltonian.HamiltonianMIS(graph,
                                                              IS_subspace=True)

        simulation = SimulateAdiabatic(
            graph,
            hamiltonian=[laser, detuning],
            cost_hamiltonian=rydberg_hamiltonian_cost,
            IS_subspace=True,
            noise_model='continuous',
            noise=[spontaneous_emission1, spontaneous_emission2])
        return simulation
    else:
        # Generate the driving and Rydberg Hamiltonians
        laser1 = hamiltonian.HamiltonianDriver(transition=(1, 2),
                                               IS_subspace=True,
                                               graph=graph,
                                               code=rydberg)
        laser2 = hamiltonian.HamiltonianDriver(transition=(0, 1),
                                               IS_subspace=True,
                                               graph=graph,
                                               code=rydberg)
        laser_detuning = hamiltonian.HamiltonianEnergyShift(index=1,
                                                            IS_subspace=True,
                                                            energies=[delta],
                                                            graph=graph,
                                                            code=rydberg)
        detuning = hamiltonian.HamiltonianMIS(graph,
                                              IS_subspace=True,
                                              code=rydberg)
        rydberg_hamiltonian_cost = hamiltonian.HamiltonianMIS(graph,
                                                              IS_subspace=True,
                                                              code=rydberg)
        spontaneous_emission = lindblad_operators.SpontaneousEmission(
            graph=graph,
            transition=(1, 2),
            IS_subspace=True,
            code=rydberg,
            rates=[Gamma])

        # Initialize adiabatic algorithm
        simulation = SimulateAdiabatic(
            graph,
            hamiltonian=[laser1, laser2, laser_detuning, detuning],
            cost_hamiltonian=rydberg_hamiltonian_cost,
            IS_subspace=True,
            noise_model='continuous',
            code=rydberg,
            noise=[spontaneous_emission])
        return simulation
Beispiel #14
0
def eit_simulation(graph,
                   noise_model=None,
                   show_graph=False,
                   gamma=3.8,
                   delta=0,
                   approximate=False,
                   Omega_g=1,
                   Omega_r=1):
    if show_graph:
        nx.draw(graph)
        plt.show()
    # Generate the driving and Rydberg Hamiltonians
    if noise_model == 'continuous':
        if not approximate:
            laser1 = hamiltonian.HamiltonianDriver(transition=(1, 2),
                                                   IS_subspace=True,
                                                   graph=graph,
                                                   code=rydberg,
                                                   energies=[Omega_g])
            laser2 = hamiltonian.HamiltonianDriver(transition=(0, 1),
                                                   IS_subspace=True,
                                                   graph=graph,
                                                   code=rydberg,
                                                   energies=[Omega_r])
            rydberg_hamiltonian_cost = hamiltonian.HamiltonianMIS(
                graph, IS_subspace=True, code=rydberg)
            detuning = hamiltonian.HamiltonianEnergyShift(code=rydberg,
                                                          IS_subspace=True,
                                                          graph=graph,
                                                          energies=[delta])
            spontaneous_emission = lindblad_operators.SpontaneousEmission(
                graph=graph,
                transition=(1, 2),
                rates=[gamma],
                IS_subspace=True,
                code=rydberg)

            # Initialize adiabatic algorithm
            simulation = SimulateAdiabatic(
                graph,
                hamiltonian=[laser1, laser2, detuning],
                cost_hamiltonian=rydberg_hamiltonian_cost,
                IS_subspace=True,
                noise_model='continuous',
                code=rydberg,
                noise=[spontaneous_emission])
            return simulation
        else:
            laser = hamiltonian.HamiltonianDriver(
                transition=(0, 1),
                IS_subspace=True,
                graph=graph,
                energies=[Omega_g * Omega_r / delta])
            detuning = hamiltonian.HamiltonianMIS(graph, IS_subspace=True)
            spontaneous_emission1 = lindblad_operators.SpontaneousEmission(
                graph=graph,
                transition=(1, 1),
                rates=[(Omega_g / delta)**2 * gamma],
                IS_subspace=True)
            spontaneous_emission2 = lindblad_operators.SpontaneousEmission(
                graph=graph,
                transition=(0, 1),
                rates=[(Omega_r / delta)**2 * gamma],
                IS_subspace=True)
            rydberg_hamiltonian_cost = hamiltonian.HamiltonianMIS(
                graph, IS_subspace=True)

            simulation = SimulateAdiabatic(
                graph,
                hamiltonian=[laser, detuning],
                cost_hamiltonian=rydberg_hamiltonian_cost,
                IS_subspace=True,
                noise_model='continuous',
                noise=[spontaneous_emission1, spontaneous_emission2])
            return simulation

    elif noise_model == 'monte_carlo':
        laser1 = hamiltonian.HamiltonianDriver(transition=(1, 2),
                                               IS_subspace=True,
                                               graph=graph,
                                               code=rydberg)
        laser2 = hamiltonian.HamiltonianDriver(transition=(0, 1),
                                               IS_subspace=True,
                                               graph=graph,
                                               code=rydberg)
        rydberg_hamiltonian_cost = hamiltonian.HamiltonianMIS(graph,
                                                              IS_subspace=True,
                                                              code=rydberg)
        detuning = hamiltonian.HamiltonianEnergyShift(code=rydberg,
                                                      IS_subspace=True,
                                                      graph=graph,
                                                      energies=[delta])

        spontaneous_emission = lindblad_operators.SpontaneousEmission(
            graph=graph,
            transition=(1, 2),
            rates=[gamma],
            IS_subspace=True,
            code=rydberg)

        # Initialize adiabatic algorithm
        simulation = SimulateAdiabatic(
            graph,
            hamiltonian=[laser1, laser2, detuning],
            cost_hamiltonian=rydberg_hamiltonian_cost,
            IS_subspace=True,
            noise_model='monte_carlo',
            code=rydberg,
            noise=[spontaneous_emission])
        return simulation