common_files
molecule_factory
molecule_factory_with_sparse
- class openvqe.common_files.molecule_factory_with_sparse.MoleculeFactory[source]
A class used to represent the molecule which consists of several main methods: get_parameters, generate_hamiltonian, calculate_uccsd, generate_cluster_ops.
- calculate_uccsd(molecule_symbol, transform, active)[source]
This function is responsible for constructing the cluster operators, the MP2 initial guesses variational parameters of the UCCSD ansatz. It computes the cluster operators in the spin representation and the size of the pool.
- Parameters
molecule_symbol (string) – the sumbol of the molecule
transform (string) – type of transformation. Either ‘JW’, ‘Bravyi-Kitaev’, or ‘parity_basis’
active (bool) – False if the non-active space is considered True if the active space is considered
- Returns
pool_size (int) – The number of the cluster operators
cluster_ops (list[Hamiltonian]) – list of fermionic cluster operators
cluster_ops_sp (list[Hamiltonian]) – list of spin cluster operators
theta_MP2 (list[float]) – list of parameters in the MP2 pre-screening process
hf_init (int) – the integer corresponding to the occupation of the Hartree-Fock solution
- generate_cluster_ops(molecule_symbol, type_of_generator, transform, active=False)[source]
This function computes the cluster operators and its size in the fermionic and spin representations for UCC family ansatz in the active and non-active space selection for any molecule within its basis sets. It also generates the cluster operators in the matrix representation using sparse method.
- Parameters
molecule_symbol (string) – the sumbol of the molecule
type_of_generator (string) – the type of excitation generator the user needs
transform (string) – type of transform of the molecule
active (bool) – False if the non-active space is considered True if the active space is considered
- Returns
In the case of UCCSD –
- pool_size: int
size of the pool
- cluster_ops: list[Any]
list of fermionic cluster operators
- cluster_ops_sp: list[Any]
list of spin cluster operators
- cluster_ops_sparse: np.ndarray
matrix representation of the cluster operator
- theta_MP2: list[float]
list of parameters in the MP2 screening process
- hf_init: int
the integer coressponding to the occupation of the Hartree-Fock solution
In any of the other cases –
- pool_size: int
size of the pool
- cluster_ops: list[Any]
list of fermionic cluster operators
- cluster_ops_sp: list[Any]
list of spin cluster operators
- cluster_ops_sparse: np.ndarray
matrix representation of the cluster operator
- generate_hamiltonian(molecule_symbol, active=False, transform='JW', display=True)[source]
This function is responsible for generating the hamiltonian of the molecule in the fermionic and the spin representation. It operates in the active and non-active space selections.
- Parameters
molecule_symbol (string) – the sumbol of the molecule
active (bool) – False if the non-active space is considered True if the active space is considered
transform (string) – type of transformation
display (bool) – False if no need to print the steps for debugging True if debugging is needed (so print the steps)
- Returns
In case of active space –
- h_active: Hamiltonian
electronic structure hamiltonian in the active space selection
- h_active_sparse: np.array
Active space hamiltonian matrix in the sparse representation
- h_active_sp: Hamiltonian
Active space hamiltonian in the spin representation
- h_active_sp_sparse: Hamiltonian
Active space sparsed hamiltonian in the spin representation
- nb_active_els: int
number of electrons in the active space
- active_noons: list[float]
list of noons in the active space
- active_orb_energies: list[float]
list of orbital energies in the active space
- info: dict (dict of str: float)
dictionary of HF, CCSD, FCI
In case of non-active space –
- h: Hamiltonian
electronic structure hamiltonian
- hamiltonian_sparse: np.array
Hamiltonian matrix in the sparse representation
- hamiltonian_sp: Hamiltonian
Hamiltonian in the spin representation
- hamiltonian_sp_sparse: Hamiltonian
Sparse hamiltonian in the spin representation
- n_elec: int
number of electrons
- noons_full: list[float]
list of noons
- orb_energies_full: list[float]
list of orbital energies
- info: dict (dict of str:float)
dictionary of HF, CCSD, FCI
- get_parameters(molecule_symbol)[source]
This function is responsible for representing the molecule returning its characteristics.
- Parameters
molecule_symbol (string) – the sumbol of the molecule
- Returns
r (float) – bone length
geometry (list<Tuple>) – geometry representation of a molecule (x,y,z) format.
charge (int) – charge of the molecule
spin (int) – spin of the molecule
basis (string) – chemical basis set of the molecule
generator_excitations
- openvqe.common_files.generator_excitations.merge_duplicate_terms(hamiltonian)[source]
Take a fermionic Hamiltonian and merge terms with same operator content
- Parameters
hamiltonian (Hamiltonian) – Of type fermionic cluster operator
- Returns
merged_hamiltonian – The listed merged operators
- Return type
Hamiltonian
- openvqe.common_files.generator_excitations.singlet_gsd(n_elec, orbital_number, transform)[source]
This function is responsible for generating the ‘generalized’ single and double excitations occured from occupied-occupied, occupied-unoccupied, and unoccupied-unoccupied orbitals within singlet spin symmetry.
- Parameters
n_elec (int) – The number of electrons
orbital_number (int) – The number of orbitals
transform (string) – type of transformation. Either ‘JW’, ‘Bravyi-Kitaev’, or ‘parity_basis’
- Returns
pool_size (int) – The number of the cluster operators
cluster_ops (List<Hamiltonian>) – List of fermionic cluster operators
cluster_ops_sp (List<Hamiltonian>) – List of spin cluster operators
- openvqe.common_files.generator_excitations.singlet_sd(n_elec, orbital_number, transform)[source]
This function is responsible for generating the single and double excitations occured from occupied to unoccupied orbitals within singlet spin symmetry.
- Parameters
n_elec (int) – The number of electrons
orbital_number (int) – The number of orbitals
transform (string) – type of transformation. Either ‘JW’, ‘Bravyi-Kitaev’, or ‘parity_basis’
- Returns
pool_size (int) – The number of the cluster operators
cluster_ops (List<Hamiltonian>) – List of fermionic cluster operators
cluster_ops_sp (List<Hamiltonian>) – List of spin cluster operators
- openvqe.common_files.generator_excitations.singlet_upccgsd(n_orb, transform, perm)[source]
This function is responsible for generating the paired generalized single and double excitations within singlet spin symmetry. Note that ‘k’ is always equal to 1 but in molecule_factory.py file, the user can type k>1. ‘k’ denotes the products of unitary paired generalized double excitations, along with the full set of generalized single excitations.
- Parameters
n_orb (int) – The number of orbitals
transform (string) – type of transformation. Either ‘JW’, ‘Bravyi-Kitaev’, or ‘parity_basis’
perm (int) – the prefactor number (which is ‘k’)
- Returns
pool_size (int) – The number of the cluster operators
cluster_ops (List<Hamiltonian>) – List of fermionic cluster operators
cluster_ops_sp (List<Hamiltonian>) – List of spin cluster operators
- openvqe.common_files.generator_excitations.spin_complement_gsd(n_elec, orbital_number, transform)[source]
This function is responsible for generating the spin complement generalized single and double excitations.
- Parameters
n_elec (int) – The number of electrons
orbital_number (int) – The number of orbitals
transform (string) – type of transformation. Either ‘JW’, ‘Bravyi-Kitaev’, or ‘parity_basis’
- Returns
pool_size (int) – The number of the cluster operators
cluster_ops (List<Hamiltonian>) – List of fermionic cluster operators
cluster_ops_sp (List<Hamiltonian>) – List of spin cluster operators
- openvqe.common_files.generator_excitations.spin_complement_gsd_twin(n_elec, orbital_number, transform)[source]
This function is responsible for generating the spin complement generalized single and double excitations. This is the twin version of spin_complement_gsd
- Parameters
n_elec (int) – The number of electrons
orbital_number (int) – The number of orbitals
transform (string) – type of transformation. Either ‘JW’, ‘Bravyi-Kitaev’, or ‘parity_basis’
- Returns
pool_size (int) – The number of the cluster operators
cluster_ops (List<Hamiltonian>) – List of fermionic cluster operators
cluster_ops_sp (List<Hamiltonian>) – List of spin cluster operators
- openvqe.common_files.generator_excitations.uccsd(hamiltonian, n_elec, noons_full, orb_energies_full, transform)[source]
This function is responsible for constructing the cluster operators, the MP2 initial guesses variational parameters of the UCCSD ansatz. It computes the cluster operators in the spin representation and the size of the pool.
- Parameters
hamiltonian (Hamiltonian) – The electronic structure Hamiltonian
n_elec (int) – The number of electrons
noons_full (List<float>) – The list of noons
orb_energies_full (List<float>) – The list of orbital energies with double degeneracy
transform (string) – type of transformation. Either ‘JW’, ‘Bravyi-Kitaev’, or ‘parity_basis’
- Returns
pool_size (int) – The number of the cluster operators
cluster_ops (list[Hamiltonian]) – list of fermionic cluster operators
cluster_ops_sp (list[Hamiltonian]) – list of spin cluster operators
theta_MP2 (list[float]) – list of parameters in the MP2 pre-screening process
hf_init (int) – the integer corresponding to the occupation of the Hartree-Fock solution
qubit_pool
- class openvqe.common_files.qubit_pool.QubitPool[source]
This class contains functions that are responsible for generating the qubit cluster operators in a pool from two main functions: ‘generate_pool_from_cluster’ and ‘generate_pool_without_cluster’. The first function takes as parameters the pool name and return the pool with its size. The pools that are accessible for the user are as follows: full, full_without_Z and reduced_without_Z. However the function generate_pool_without_cluster() takes as parameters the type of pool, pool generated from cluster operators and returns the pool with its size. The type of pool that are considered as options for the user are as follows: - YXXX - XYXX - XXYX - XXXY - random - two - four - eight - without_Z_from_generator - minimal - pure_with_symmetry Note that the other functions in this class are helper functions.
- double_position_generator(nos_qubits)[source]
Returns the permutation list of indices [i1, i2, i3, i4] such that i1 < i2 < i3 < i4 and i4 <= nos_qubits
- Parameters
nos_qubits (int) – number of qbits
- Returns
store – the permutation list
- Return type
List[List[int]]
- extract_list_qubits_operators(list_terms)[source]
extract the qubits and operators from the lists and keep them grouped together as they were in the original Hamiltonian objects.
- Parameters
list_terms (List[Any]) – list of extracted terms for each cluster operator
- Returns
list_list_digits (List[List[int]]) – Extracted digits for each term
list_list_letters (List[List[string]]) – Extracted letters for each term
- extract_qubits_operators(terms)[source]
get the qubits and the operators from the terms
- Parameters
terms (list[string]) – list of terms for each cluster operator
- Returns
list_digits (List<List<int>>) – Extracted digits for each term
list_letters (List<List<string>>) – Extracted letters for each term
- extract_qubits_operators_without_z(terms)[source]
same as ‘extract_qubits_operators’ but ommiting the Z Pauli terms
- Parameters
terms (list[string]) – list of terms for each cluster operator
- Returns
list_digits (List<List<int>>) – Extracted digits for each term
list_letters (List<List<string>>) – Extracted letters for each term
- extract_terms(qubit_pool)[source]
Extract terms from qubitPool such as Pauli strings and number of qbits.
- Parameters
qubit_pool (list[Hamiltonian]) – list of spin cluster operators
- Returns
terms – list of extracted terms for each cluster operator
- Return type
list[string]
- extract_terms_with_coeff(qubit_pool)[source]
Sometimes we have coefficients like MP2 pre-screening parameters are needed. So in this function, we extract from the qubit pool the terms with their associated parameters.
- Parameters
qubit_pool (list[Hamiltonian]) – list of spin cluster operators
- Returns
list_terms (list[any]) – list of extracted terms for each cluster operator
list_coeffs (list[list[floats]]) – list of associated coefficients
- extract_terms_without_z(terms)[source]
Omits all the Z Pauli terms.
- Parameters
terms (list[string]) – list of extracted terms for each cluster operator
- Returns
terms – list of extracted terms for each cluster operator with Z Pauli terms omitted
- Return type
list[string]
- generate_eight_pools(nbqbits, qubit_pool)[source]
generate the list of qubit pool operators where each operator is a sum of eight Pauli strings associated with their qubit digits with parity conditions.
- Parameters
nbqbits (int) – The number of qbits
- Returns
length (int) – Number of eight-pool operators
eight_pool (List<Hamiltonian>) – list of spin cluster operators
- generate_excitations(nbqbits, s, d)[source]
generates the single (s) and double (d) qubit excitations according to this article:
‘’’Yordanov YS, Armaos V, Barnes CH, Arvidsson-Shukur DR. Qubit-excitation-based adaptive variational quantum eigensolver. Communications Physics 2021; 4(1): 1-1’’’
- Parameters
nbqbits (int) – number of qbits
s (List[List[int]]) – list of two-indices lists
d (List[List[int]]) – list of four-indices lists
- Returns
length (int) – the number of qubit excitations
qubit_excitation (List<Hamiltonian>) – The list of spin cluster operators of qubit excitations
- generate_four_pools(nbqbits)[source]
generate the list of qubit pool operators where each operator is a sum of four Pauli strings associated with their qubit digits with parity conditions.
- Parameters
nbqbits (int) – The number of qbits
- Returns
length (int) – Number of four-pool operators
four_pool (List<Hamiltonian>) – list of spin cluster operators
- generate_minimal_pool(nbqbits)[source]
generate minimal pool according to this article
‘’’Tang HL, Shkolnikov V, Barron GS, et al. qubit-adapt-vqe: An adaptive algorithm for constructing hardware-efficient ansätze on a quantum processor. PRX Quantum 2021; 2(2): 020310’’’
- Parameters
nbqbits (int) – The number of qbits
- Returns
length (int) – Number of minimal pool operators
minimal_pool4 (List<Hamiltonian>) – list of spin cluster operators
- generate_pool(cluster_ops)[source]
generate the qubitPool from cluster_ops which is equivalent to getting cluster_ops_sp
- Parameters
cluster_ops (list[Hamiltonian]) – list of fermionic cluster operators
- Returns
qubit_pool – list of spin cluster operators
- Return type
list[Hamiltonian]
- generate_pool_from_cluster(pool_condition, cluster_ops, nbqbits)[source]
- This function generates the following type of pools:
full
full_without_Z
reduced_without_Z
- Parameters
pool_condition (string) – The pool type
cluster_ops (list[Hamiltonian]) – list of fermionic cluster operators
nbqbits (int) – The number of qbits.
- Returns
len_hamiltonian_pool (int) – Number of the pool operators
hamiltonian_pool (List<Hamiltonian>) – list of spin cluster operators
- generate_pool_pure_with_symmetry(molecule_symbol)[source]
generate pool pure with symmetry according to this article
‘’’Shkolnikov V, Mayhall NJ, Economou SE, Barnes E. Avoiding symmetry roadblocks and minimizing the measurement overhead of adaptive variational quantum eigensolvers. arXiv preprint arXiv:2109.05340 2021’’’
Note: Only H4 is supported. User can extend for other molecules like BeH2 or LiH.
- Parameters
molecule_symbol (string) – The name of the molecule
- Returns
length (int) – Number of minimal pool operators
pool_pure (List<Hamiltonian>) – list of spin cluster operators
- generate_pool_without_cluster(pool_type, nbqbits=12, qubit_pool=None, molecule_symbol='H4')[source]
This function calls the following type of pools: - YXXX - XYXX - XXYX - XXXY - random - two - four - eight - without_Z_from_generator - minimal - pure_with_symmetry
- Parameters
pool_type (string) – The pool type
nbqbits (int) – The number of qbits. Defaults to 12.
qubit_pool (list[Hamiltonian]) –
- list of spin cluster operators. Defaults to None. Only used for the following pool types:
eight
without_Z_from_generator
molecule_symbol (string) – The name of the molecule. Defaults to ‘H4’. Only used for pure_with_symmetry pool type
- Returns
len_returned_pool (int) – Number of the pool operators
returned_pool (List<Hamiltonian>) – list of spin cluster operators
- generate_pool_without_z_from_generator(nbqbits, qubit_pool)[source]
Takes the original Hamiltonian object and returns the Hamiltonian object without Z Pauli terms. Note: each double fermionic operator after JW transformation gives eight operators composed of Pauli strings including Z term. (This is a second version of generate_eight_pools)
- Parameters
nbqbits (int) – The number of qbits
qubit_pool (list[Hamiltonian]) – list of spin cluster operators
- Returns
length (int) – Number of eight-pool operators
eight_pool (List<Hamiltonian>) – list of spin cluster operators
- generate_random_pool(yxxx_pool, xyxx_pool, xxyx_pool, xxxy_pool)[source]
generate randomly chosen qubit pools from YXXX, XYXX, XXYX, and XXXY pools
- Parameters
yxxx_pool (List<Hamiltonian>) – list of YXXX spin cluster operators
xyxx_pool (List<Hamiltonian>) – list of XYXX spin cluster operators
xxyx_pool (List<Hamiltonian>) – list of XXYX spin cluster operators
xxxy_pool (List<Hamiltonian>) – list of XXXY spin cluster operators
- Returns
length (int) – Number of operators in the randomly generated pool
random_pool (List<Hamiltonian>) – list of the randomly chosen spin cluster operators
- generate_reduced_qubit_pool(terms, nbqbits)[source]
generate the qubit pools discarding the Z-string responsible for the anticommutation of fermions and only keeping the first string acting on each set of spin orbitals
- Parameters
terms (list[string]) – list of terms for each cluster operator
nbqbits (int) – The number of qbits
- Returns
list_hamiltonian – list of spin cluster operators
- Return type
List<Hamiltonian>
- generate_two_pools(nbqbits)[source]
generate the list of qubit pool operators where each operator is a sum of two Pauli strings associated with their qubit digits with parity conditions.
- Parameters
nbqbits (int) – The number of qbits
- Returns
length (int) – Number of two-pool operators
two_pool (List<Hamiltonian>) – list of spin cluster operators
- generate_xxxy_pool(nbqbits)[source]
generate the qubit pools containing the XXXY string with parity sum conditions.
- Parameters
nbqbits (int) – The number of qbits
- Returns
length (int) – Number of XXXY operators in a pool
xxxy_pool (List<Hamiltonian>) – list of spin cluster operators
- generate_xxyx_pool(nbqbits)[source]
generate the qubit pools containing the XXYX string with parity sum conditions.
- Parameters
nbqbits (int) – The number of qbits
- Returns
length (int) – Number of XXYX operators in a pool
xxyx_pool (List<Hamiltonian>) – list of spin cluster operators
- generate_xyxx_pool(nbqbits)[source]
generate the qubit pools containing the XYXX string with parity sum conditions.
- Parameters
nbqbits (int) – The number of qbits
- Returns
length (int) – Number of XYXX operators in a pool
xyxx_pool (List<Hamiltonian>) – list of spin cluster operators
- generate_yxxx_pool(nbqbits)[source]
generate the qubit pools containing the YXXX string with parity sum conditions.
- Parameters
nbqbits (int) – The number of qbits
- Returns
length (int) – Number of YXXX operators in a pool
yxxx_pool (List<Hamiltonian>) – list of spin cluster operators
- qubit_excitations(nbqbits)[source]
Combines the functions ‘single_position_generator’, ‘double_position_generator’, and ‘generate_excitations’
- Parameters
nbqbits (int) – number of qbits
Returns –
s (List[List[int]]) – list of two-indices lists
d (List[List[int]]) – list of four-indices lists
len_qubit_excitation (int) – the number of qubit excitations
qubit_excitation (List<Hamiltonian>) – The list of spin cluster operators of qubit excitations
---------- –
- single_position_generator(nos_qubits)[source]
Returns the permutation list of indices [i1, i2] such that i1 < i2 and i2 <= nos_qubits
- Parameters
nos_qubits (int) – number of qbits
- Returns
store – the permutation list
- Return type
List[List[int]]
- terms_to_hamiltonian(terms, nbqbits)[source]
transform the qubits and terms to hamiltonian operators, which is the accepted input format for generator excitations.
- Parameters
terms (list[string]) – list of terms for each cluster operator
nbqbits (int) – The number of qbits
- Returns
list_hamiltonian – list of spin cluster operators
- Return type
List<Hamiltonian>
sorted_gradient
- openvqe.common_files.sorted_gradient.abs_sort_desc(my_list) list [source]
Internal function for internal working of program
- openvqe.common_files.sorted_gradient.apply_neg(sorted_list, neg_num, occ_dict)[source]
Internal function for internal working of program
- openvqe.common_files.sorted_gradient.corresponding_index(new_list, new_list_index, sorted_new)[source]
It generates sorted index after shuffling of elements in list.
- openvqe.common_files.sorted_gradient.index_without_0(my_list)[source]
index_without_0 generate a list of index without 0.
it takes list with 0 and returns list of index without 0
fermion_util
- openvqe.common_files.fermion_util.order_fermionic_ops(fermionic_term)[source]
Order the operators list of a fermionic_term by putting the creations operators on the left and the annihilation operators on the right, with respect to the fermionic anticommutation relations.
- Parameters
fermionic_term (Term) – the term to order
- Returns
the list of ordered fermionic terms
- Return type
ordered_fermionic_terms (list<Term>)
- openvqe.common_files.fermion_util.order_fermionic_term(fermionic_term)[source]
Order any fermionic term by putting the creation operators on the left, ordered by increasing qubit numbers, and the annihilation operators on the right, ordered y increasing qubit numbers, with respect to the fermionic anticommutation relations.
- Parameters
fermionic_term (Term) – the term to order
- Returns
the list of ordered fermionic terms
- Return type
ordered_fermionic_terms (list<Term>)
- openvqe.common_files.fermion_util.order_qubits(fermionic_term)[source]
Takes a fermionic term which pauli_op is supposed to be ordered properly, and reorder it increasing qbit numbers
- Parameters
fermionic_term (Term) – the term to reorder
- Returns
the reordered term
- Return type
ordered_term (Term)
- openvqe.common_files.fermion_util.permute_fermionic_operator(fermionic_term, ind)[source]
Perform the permutation of the two operators in index ind and ind + 1 in a fermionic Term pauli string
- Parameters
fermionic_term (Term) – the fermionic term which operators we seek to permute
ind (int) – the lower index of the two consecutive creation or annihilation operators we seek to permute
- Returns
the list of fermionic terms resulting of the permutation
- Return type
list_terms (list<Term>)
circuit
- openvqe.common_files.circuit.circuit_opt_double(q, qc, exci, theta)[source]
A Double-fermionic-evolution circuit See circuit in figure 2.14 of the following reference: Yordanov Y. Quantum computational chemistry methods for early-stage quantum computers. PhD thesis. University of Cambridge, Cambridge, UK; 2021.
- openvqe.common_files.circuit.circuit_opt_simple(q, qc, exci, theta)[source]
A Single-fermionic-evolution circuit See circuit in figure 2.13 of the following reference: Yordanov Y. Quantum computational chemistry methods for early-stage quantum computers. PhD thesis. University of Cambridge, Cambridge, UK; 2021.
- openvqe.common_files.circuit.count(gate, mylist)[source]
count function counts the number of gates in the given list params: it takes two parameters. first is which gate you want to apply like rx, ry etc. second it take the list of myqlm gates instruction. returns: it returns number of gates.
- openvqe.common_files.circuit.double_qubit_evo(q, qc, exci, theta)[source]
Double qubit evolution circuit See circuit in figure 2.14 of the following reference: Yordanov Y. Quantum computational chemistry methods for early-stage quantum computers. PhD thesis. University of Cambridge, Cambridge, UK; 2021.
- openvqe.common_files.circuit.efficient_fermionic_ansatz(q, qc, list_exci, list_theta)[source]
See chapter 2 of the following reference: Yordanov Y. Quantum computational chemistry methods for early-stage quantum computers. PhD thesis. University of Cambridge, Cambridge, UK; 2021.
- openvqe.common_files.circuit.efficient_qubit_ansatz(q, qc, list_exci, list_theta)[source]
See chapter 2 of the following reference: Yordanov Y. Quantum computational chemistry methods for early-stage quantum computers. PhD thesis. University of Cambridge, Cambridge, UK; 2021.
- openvqe.common_files.circuit.single_qubit_evo(q, qc, exci, theta)[source]
Single qubit evolution circuit See circuit in figure 2.10 of the following reference: Yordanov Y. Quantum computational chemistry methods for early-stage quantum computers. PhD thesis. University of Cambridge, Cambridge, UK; 2021.