Exemple #1
0
def run_sim_repetitions_stage3(aht,
                               ht,
                               zz,
                               bond_length,
                               n_repetitions,
                               exact=True,
                               noisy=False):
    """Executes state preparation circuit multiple times and computes the energy expectation
    over n times (n_repetitions).

    Args:
    =====
    aht, ht, zz : numeric
        Parameters for decoding circuit
    bond_length : float
        Bond length
    n_repetitions : int
        Number of circuit runs
    exact : bool
        If True, works with wavefunction
    noisy : bool
        If True, runs noisy version of circuit

    Returns:
    ========
    energy_expectation : float
        Energy expectation value
    """
    if exact == True and noisy == False:
        final_state = _run_sim_stage3(aht,
                                      ht,
                                      zz,
                                      exact=True,
                                      print_circuit=False,
                                      noisy=False)
        energy_expectation = settings.compute_energy_expectation(
            bond_length, particle_number_conserve(final_state))
        return energy_expectation

    energy_expectation = 0
    for k in range(n_repetitions):
        final_state = _run_sim_stage3(aht,
                                      ht,
                                      zz,
                                      exact,
                                      print_circuit=False,
                                      noisy=noisy)
        energy_expectation += settings.compute_energy_expectation(
            bond_length,
            particle_number_conserve(final_state)) / float(n_repetitions)
    return float(energy_expectation)
def one_run(alpha, bond_length):
    f_state = _run_sim_stage1(alpha=alpha,
                              exact=True,
                              print_circuit=False,
                              noisy=True)
    return settings.compute_energy_expectation(
        bond_length, particle_number_conserve(f_state))
def compute_stage1_cost_function(alpha,
                                 bond_length,
                                 n_repetitions=100,
                                 exact=True,
                                 noisy=False):
    """Executes state preparation circuit multiple times and computes the energy expectation
    over n times (n_repetitions).

    Args:
    =====
    alpha : numeric
        Parameter for state preparation circuit
    bond_length : float
        Bond length
    n_repetitions : int
        Number of circuit runs
    exact : bool
        If True, works with wavefunction
    noisy : bool
        If True, runs noisy version of circuit

    Returns:
    ========
    energy_expectation : float
        Energy expectation value
    """
    if exact is True and noisy is False:
        f_state = _run_sim_stage1(alpha=alpha,
                                  exact=exact,
                                  print_circuit=False,
                                  noisy=noisy)
        energy_expectation = settings.compute_energy_expectation(
            bond_length, particle_number_conserve(f_state))
        return energy_expectation

    energy_expectation = 0
    for k in range(int(n_repetitions)):
        f_state = _run_sim_stage1(alpha=alpha,
                                  exact=exact,
                                  print_circuit=False,
                                  noisy=noisy)
        energy_expectation += settings.compute_energy_expectation(
            bond_length,
            particle_number_conserve(f_state)) / float(n_repetitions)
    return energy_expectation
Exemple #4
0
def run_sim_repetitions_stage3(aht,
                               ht,
                               zz,
                               bond_length,
                               n_repetitions,
                               exact=True,
                               noisy=False):
    """Executes state preparation circuit multiple times and computes the energy expectation
    over n times (n_repetitions).

    Args:
    =====
    aht, ht, zz : numeric
        Parameters for decoding circuit
    bond_length : float
        Bond length
    n_repetitions : int
        Number of circuit runs
    exact : bool
        If True, works with wavefunction
    noisy : bool
        If True, runs noisy version of circuit

    Returns:
    ========
    energy_expectation : float
        Energy expectation value
    """
    if exact == True and noisy == False:
        final_state = _run_sim_stage3(aht,
                                      ht,
                                      zz,
                                      exact=True,
                                      print_circuit=False,
                                      noisy=False)
        energy_expectation = settings.compute_energy_expectation(
            bond_length, particle_number_conserve(final_state))
        return energy_expectation

# energy_expectation = 0
# for k in range(n_repetitions):
#     energy_expectation += one_run(aht,ht,zz,bond_length)
# energy_expectation = energy_expectation / float(n_repetitions)

    p = Pool()
    args = [(aht, ht, zz, bond_length)] * n_repetitions
    results = p.starmap(one_run, args)
    energy_expectation = np.array(results).mean()
    p.close()
    return energy_expectation