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 input_3(size, hamiltonian_idx, V): if V == np.inf: e = 0. V = 1. else: e = 1 h, eig = hamiltonians_of_size(size, V, e) return h[hamiltonian_idx], eig[hamiltonian_idx]
def _num_terms(mat2op, size_min=2, size_max=101, m=25): num_sizes = size_max - size_min + 1 nbr_terms = np.zeros(num_sizes) matrix_size = np.zeros(num_sizes) idx = 0 for i in range(num_sizes): size = size_min + i V = np.random.randn(m) temp = 0 count = 0 for v in V: hs = hamiltonians_of_size(size, v)[0] for h in hs: count += 1 temp += len(mat2op(h)) matrix_size[idx] = size nbr_terms[idx] = temp / count idx += 1 print(size) return matrix_size, nbr_terms
def input_3(ansatz_name, size, hamiltonian_idx): h, eig = hamiltonians_of_size(size) return h[hamiltonian_idx], eig[hamiltonian_idx]
def input_5(size, ansatz_name, minimizer, repeats, hamiltonian_idx): h, eig = hamiltonians_of_size(size) return h[hamiltonian_idx], eig[hamiltonian_idx]