adapt
fermionic_adapt_vqe
- openvqe.adapt.fermionic_adapt_vqe.commutators_calculations(cluster_ops_sp, hamiltonian_sp)[source]
Compute the commutators [cluster_ops_sp[i], hamiltonian_sp]. Note: it is under developement
- Parameters
cluster_ops_sp (list[Hamiltonian]) – list of spin cluster operators
hamiltonian_sp (Hamiltonian) – Hamiltonian in the spin representation
- Returns
list_commutators – list of the resulting commutators (gradients)
- Return type
list<float>
- openvqe.adapt.fermionic_adapt_vqe.compute_gradient_i(i, cluster_ops_sparse, v, sig)[source]
Compute analytically the gradient of the ith operator of “cluster_ops_sparse”.
- Parameters
i (int) – the index of the fermionic operator for which the gradient is computed
cluster_ops_sparse (List<transposable linear operator>) – the sparse fermionic operators
v (ndarray) – the current state
sig (ndarray) – the resultant of the dot product of a hamiltonian operator with the current state
- Returns
gi – the gradient of the correponding fermionic operator
- Return type
float
- openvqe.adapt.fermionic_adapt_vqe.fermionic_adapt_vqe(hamiltonian_sparse, cluster_ops_sparse, reference_ket, hamiltonian_sp, cluster_ops_sp, hf_init_sp, n_max_grads, fci, optimizer, tolerance, type_conver, threshold_needed, max_external_iterations=30)[source]
Runs the loop of making fermionic adapt vqe found in this reference in section “Results” Grimsley HR, Economou SE, Barnes E, Mayhall NJ. An adaptive variational algorithm for exact molecular simulations on a quantum computer. Nature communications 2019; 10(1): 1-9.
- Parameters
hamiltonian_sparse (ndarray) – The sparse hamiltonian
cluster_ops_sparse (List<transposable linear operator>) – the sparse fermionic operators
reference_ket (ndarray) – the initial state
hamiltonian_sp (Hamiltonian) – Hamiltonian in the spin representation
cluster_ops_sp (list[Hamiltonian]) – list of spin cluster operators
hf_init_sp (int) – the integer corresponds to the hf_init (The Hartree-Fock state in integer representation) obtained by using “qat.fermion.transforms.record_integer”.
n_max_grads (int) – the number of maximum gradients chosen per internal iteration
fci (float) – the full configuration interaction energy
optimizer (string) – the type of the optimizer
tolerance (float) – the tolerance for reaching convergence
type_conver (string) – in our case, “norm” is chosen
threshold_needed (float) – the norm threshold
max_external_iterations (int) – the number of maximum iteration to perform the whole adaptive loop
- Returns
iterations (Dict) – the following properties of the simulation: energies, energies_substracted_from_FCI, norms, Max_gradients, fidelity, CNOTs, Hadamard, RY, and RX.
result (Dict) – the following properties after convergence: indices, Number_operators, final_norm, parameters, Number_CNOT_gates, Number_Hadamard_gates, Number_RX_gates, final_energy_last_iteration,
- openvqe.adapt.fermionic_adapt_vqe.fun_fidelity(circ, eigenvalues, eigenvectors, nbqbits)[source]
Checks the fidelity between the resulted state and exact wave function
- Parameters
circ (qat.core.Circuit) – the circuit corresponding to the resulted state
eigenvalues (ndarray) – the eigen values of the hamiltonian
eigenvectors (ndarray) – the eigen vectors of the hamiltonian
nbqbits (int) – the number of qubits
- Returns
fid – the fidelity
- Return type
float
- openvqe.adapt.fermionic_adapt_vqe.get_statevector(result, nbqbits)[source]
Get the statevector from the Result class
- Parameters
result (qat.core.BatchResult) – the result of an executed job
nbqbits (int) – the number of qubits
statevector (ndarray) – the resulting statevector representation
- openvqe.adapt.fermionic_adapt_vqe.hf_energy(hf_state, hamiltonian_sp)[source]
Returns the Hartee Fock energy
- Parameters
hf_state (qat.core.Circuit) – the circuit representing the HF state
hamiltonian_sp (Hamiltonian) – Hamiltonian in the spin representation
- Returns
res.value – the resulted energy
- Return type
float
- openvqe.adapt.fermionic_adapt_vqe.prepare_adapt_state(reference_ket, spmat_ops, parameters)[source]
Computes the action of the matrix exponential of fermionic sparse operators (“spmat_ops”) on the state initiated by “reference_ket”.
- Parameters
reference_ket (ndarray) – the initial state
spmat_ops (List<transposable linear operator>) – the sparse fermionic operators
parameters (List<float>) – list of parameters for the “spmat_ops”
- Returns
new_state – the new state
- Return type
ndarray
- openvqe.adapt.fermionic_adapt_vqe.prepare_hf_state(hf_init_sp, cluster_ops_sp)[source]
It constructs the Hartree-Fock state (ansatz)
- Parameters
hf_init_sp (int) – the integer corresponds to the hf_init (The Hartree-Fock state in integer representation) obtained by using “qat.fermion.transforms.record_integer”.
cluster_ops_sp (list[Hamiltonian]) – list of spin cluster operators
- Returns
circuit – the circuit representing the HF-state
- Return type
qat.core.Circuit
- openvqe.adapt.fermionic_adapt_vqe.prepare_state_ansatz(cluster_ops_sp, hf_init_sp, parameters)[source]
It constructs the trial wave function (ansatz)
- Parameters
cluster_ops_sp (list[Hamiltonian]) – list of spin cluster operators
hf_init_sp (int) – the integer corresponds to the hf_init (The Hartree-Fock state in integer representation) obtained by using “qat.fermion.transforms.record_integer”.
parameters (List<float>) – the Parameters for the trial wave function to be constructed
- Returns
curr_state – the circuit that represent the trial wave function
- Return type
qat.core.Circuit
- openvqe.adapt.fermionic_adapt_vqe.return_gradient_list(cluster_ops_sparse, hamiltonian_sparse, curr_state)[source]
Compute analytically the gradient for all fermionic cluster operators (“cluster_ops_sparse”).
- Parameters
cluster_ops_sparse (List<transposable linear operator>) – the sparse fermionic operators
hamiltonian_sparse (ndarray) – the hamiltonian operator
curr_state (ndarray) – the current state
- Returns
list_grad (List<float>) – the gradients for all the fermionic cluster operators
curr_norm (float) – the magnitude of the gradients
next_deriv (float) – the maximum gradient (in absolute value)
next_index (int) – the index of the operator with maximum gradient
- openvqe.adapt.fermionic_adapt_vqe.ucc_action(hamiltonian_sp, cluster_ops_sp, hf_init_sp, theta_current)[source]
It maps the exponential of cluster operators (“cluster_ops_sp”) associated by their parameters (“theta_current”) using the CNOTS-staircase method, which is done by “build_ucc_ansatz” which creates the circuit on the top of the HF-state (“hf_init_sp”). Then, this function also calculates the expected value of the hamiltonian (“hamiltonian_sp”).
- Parameters
hamiltonian_sp (Hamiltonian) – Hamiltonian in the spin representation
cluster_ops_sp (list[Hamiltonian]) – list of spin cluster operators
hf_init_sp (int) – the integer corresponds to the hf_init (The Hartree-Fock state in integer representation) obtained by using “qat.fermion.transforms.record_integer”.
theta_current (List<float>) – the Parameters of the cluster operators
- Returns
res.value – the resulted energy
- Return type
float
qubit_adapt_vqe
- openvqe.adapt.qubit_adapt_vqe.calculate_gradient(sparse_operator, state, sparse_hamiltonian)[source]
Computation of the gradient 2*<bra|sparse_hamiltonian*sparse_operator|state>
- Parameters
sparse_operator (transposable linear operator) – the sparse qubit operator
state (ndarray) – the current state
sparse_hamiltonian (ndarray) – the sparsed hamiltonian operator
- Returns
gradient – the computed gradient for the qubit operator
- Return type
float
- openvqe.adapt.qubit_adapt_vqe.compute_commutator_i(commutator, curr_state)[source]
computes the expectation value of the commutator of a given qubit operator
- Parameters
commutator (Hamiltonian) – The product of the qubit operator and the spin hamiltonian
curr_state (qat.core.Circuit) – the ansatz of the current state
res.value (float) – the obtained expectation value (gradient)
- openvqe.adapt.qubit_adapt_vqe.hf_energy(hf_state, hamiltonian_sp)[source]
Returns the Hartee Fock energy
- Parameters
hf_state (qat.core.Circuit) – the circuit representing the HF state
hamiltonian_sp (Hamiltonian) – Hamiltonian in the spin representation
- Returns
res.value – the resulted energy
- Return type
float
- openvqe.adapt.qubit_adapt_vqe.prepare_adapt_state(reference_state, ansatz, coefficients)[source]
Computes the action of the matrix exponential of qubit sparse operators (“ansatz”) on the state initiated by “reference_state”.
- Parameters
reference_state (ndarray) – the initial state
ansatz (List<transposable linear operator>) – the sparse qubit operators
coefficients (List<float>) – list of parameters for the “ansatz”
- Returns
state – the new state
- Return type
ndarray
- openvqe.adapt.qubit_adapt_vqe.prepare_hf_state(hf_init_sp, cluster_ops_sp)[source]
It constructs the Hartree-Fock state (ansatz)
- Parameters
hf_init_sp (int) – the integer corresponds to the hf_init (The Hartree-Fock state in integer representation) obtained by using “qat.fermion.transforms.record_integer”.
cluster_ops_sp (list[Hamiltonian]) – list of spin cluster operators
- Returns
circuit – the circuit representing the HF-state
- Return type
qat.core.Circuit
- openvqe.adapt.qubit_adapt_vqe.prepare_state_ansatz(cluster_ops_sp, hf_init_sp, parameters)[source]
It constructs the trial wave function (ansatz)
- Parameters
cluster_ops_sp (list[Hamiltonian]) – list of spin cluster operators
hf_init_sp (int) – the integer corresponds to the hf_init (The Hartree-Fock state in integer representation) obtained by using “qat.fermion.transforms.record_integer”.
parameters (List<float>) – the Parameters for the trial wave function to be constructed
- Returns
curr_state – the circuit that represent the trial wave function
- Return type
qat.core.Circuit
- openvqe.adapt.qubit_adapt_vqe.qubit_adapt_vqe(hamiltonian_sp, hamiltonian_sp_sparse, reference_ket, nqubits, pool_mix, hf_init_sp, fci, n_max_grads=2, adapt_conver='norm', adapt_thresh=1e-08, adapt_maxiter=45, tolerance_sim=1e-07, method_sim='BFGS')[source]
adapt_conver adapt_thresh adapt_maxiter tolerance_sim method_sim
Runs the loop of making qubit adapt vqe found in this reference in section “Results” Grimsley HR, Economou SE, Barnes E, Mayhall NJ. An adaptive variational algorithm for exact molecular simulations on a quantum computer. Nature communications 2019; 10(1): 1-9.
Note: the analytical calculation for the “exact_adapt_energy” are still under developement so that we later can compare the results obtained by the qlm simulator and the “exact_adapt_energy”
- Parameters
hamiltonian_sp (Hamiltonian) – Hamiltonian in the spin representation
hamiltonian_sp_sparse (ndarray) – The sparsed spin hamiltonian
reference_ket (ndarray) – the initial state
nqubits (int) – the number of qubits
pool_mix (List<Hamiltonian>) – list of qubit cluster operators
hf_init_sp (int) – the integer corresponds to the hf_init (The Hartree-Fock state in integer representation) obtained by using “qat.fermion.transforms.record_integer”.
fci (float) – the full configuration interaction energy
n_max_grads (int) – the number of maximum gradients chosen per internal iteration
adapt_conver (string) – in our case, “norm” is chosen
adapt_thresh (float) – the norm threshold
adapt_maxiter (int) – the number of maximum iteration to perform the whole adaptive loop
tolerance_sim (float) – the tolerance for reaching convergence
method_sim (string) – the type of the optimizer for the qlm simulator
Returns –
-------- –
iterations_sim (Dict) – the following properties: energies, energies_substracted_from_fci, norms, Max_gradient, CNOTs, Hadamard, RY, RX
result_sim (Dict) – the following properties: optimizer, final_norm, indices, len_operators, parameters, final_energy,
iterations_ana (Empty dict (see the note above)) –
result_ana (Empty dict (see the note above)) –
- openvqe.adapt.qubit_adapt_vqe.term_to_matrix_sparse(spin_operator)[source]
converts the terms in the spin hamiltonian into a sparse.csr_matrix.
- Parameters
spin_operator (Hamiltonian) – cluster operator in the spin representation
- Returns
matrix_final – the final matrix of the spin operator
- Return type
ndarray
- openvqe.adapt.qubit_adapt_vqe.ucc_action(hamiltonian_sp, cluster_ops_sp, hf_init_sp, theta_current)[source]
It maps the exponential of cluster operators (“cluster_ops_sp”) associated by their parameters (“theta_current”) using the CNOTS-staircase method, which is done by “build_ucc_ansatz” which creates the circuit on the top of the HF-state (“hf_init_sp”). Then, this function also calculates the expected value of the hamiltonian (“hamiltonian_sp”).
- Parameters
hamiltonian_sp (Hamiltonian) – Hamiltonian in the spin representation
cluster_ops_sp (list[Hamiltonian]) – list of spin cluster operators
hf_init_sp (int) – the integer corresponds to the hf_init (The Hartree-Fock state in integer representation) obtained by using “qat.fermion.transforms.record_integer”.
theta_current (List<float>) – the Parameters of the cluster operators
- Returns
res.value – the resulted energy
- Return type
float