def fel_measmax(x, fun, identifier, fun_evals): fun_none = [] vqe = vqe_nelder_mead(fatol=1e-3) ansatz_name = identifier[1] size = identifier[0] for fun_evals_ in fun_evals: fun_evals_ = int(fun_evals_) if len(fun) < fun_evals_: print(len(fun)) raise ValueError(f'fun_evals={fun_evals_} is to big') fun_ = fun[:fun_evals_] idx = np.argmin(fun_) x_min = x[idx] mat_idx = identifier[4] h = hamiltonians_of_size(size)[0][mat_idx] H, qc, ansatz_, _ = create_and_convert(ansatz_name, h) fun_none_ = vqe.expectation(ansatz_(x_min), H, samples=None, qc=qc)[0] fun_none.append(fun_none_) return np.asarray(fun_none)
def simulate(size, ansatz_name, minimizer, repeats, hamiltonian_idx, max_meas, samples, h, eig): H, qc, ansatz_, initial_params = \ core.interface.create_and_convert(ansatz_name, h) if minimizer == 'nelder-mead': vqe = vqe_nelder_mead(samples=samples, H=H, fatol=0, xatol=0) tol_para = 1e-3 max_same_para = 3 callback = cb.restart(max_same_para, tol_para) elif minimizer == 'bayes': n_calls = int(round(max_meas/samples)) vqe = vqe_bayes(n_calls=n_calls) def callback(*args, **kwargs): pass if ansatz_name == 'multi_particle': initial_params = [(-1.0, 1.0)]*(size - 1) elif ansatz_name == 'one_particle_ucc': initial_params = [(-3.0, 3.0)] * (size - 1) else: raise RuntimeError("Don't know that ansatz.") else: raise RuntimeError('Bad minimizer') result = vqe_eig.smallest(H, qc, initial_params, vqe, ansatz_, samples, callback=callback, max_meas=max_meas) result.correct = eig return result
def simulate(size, hamiltonian_idx, V, max_meas, samples, h, eig): H, qc, ansatz_, initial_params = \ core.interface.create_and_convert('multi_particle', h) vqe = vqe_nelder_mead(samples=samples, H=H, fatol=0, xatol=0) tol_para = 1e-3 max_same_para = 3 callback = cb.restart(max_same_para, tol_para) result = vqe_eig.smallest(H, qc, initial_params, vqe, ansatz_, samples, callback=callback, max_meas=max_meas) result.correct = eig return result
def simulate(ansatz_name, size, hamiltonian_idx, samples, repeats, h, eig): # TODO: create VQE-object here! (not multiprocess safe) # TODO: run e.g. smallest here and return result. H, qc, ansatz_, initial_params = core.interface.create_and_convert( ansatz_name, h) vqe = vqe_nelder_mead(samples=samples, H=H) max_fun_evals = 200 result = vqe_eig.smallest(H, qc, initial_params, vqe, ansatz_, samples, max_meas=samples * max_fun_evals) result.correct = eig return result