Skip to content

Commit

Permalink
Removed parity mapping in VQE electronic_structure
Browse files Browse the repository at this point in the history
  • Loading branch information
renezander90 committed Nov 18, 2024
1 parent 33344a4 commit e0e8b75
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/qrisp/algorithms/vqe/problems/electronic_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,21 +438,17 @@ def ansatz(qv, theta):

return ansatz, num_params

def create_hartree_fock_init_function(M, N, mapping_type='jordan_wigner'):
def create_hartree_fock_init_function(M, N):
"""
Creates the function that, when applied to a :ref:`QuantumVariable`, initializes the Hartee-Fock state:
If the mapping type is ``jordan_wigner``, the first ``N`` qubits are initialized in the $\ket{1}$ state.
If the mapping type is ``parity``, the first ``N`` qubits with even index are initialized in the $\ket{1}$ state.
Consistent with the Jordan-Wigner mapping, the first ``N`` qubits are initialized in the $\ket{1}$ state.
Parameters
----------
M : int
The number of (active) spin orbitals.
N : int
The number of (active) electrons.
mapping_type : string, optinal
The mapping from fermionic Hamiltonian to qubit Hamiltonian. Available are ``jordan_wigner``, ``parity``.
The default is ``jordan_wigner``.
Returns
-------
Expand All @@ -461,11 +457,11 @@ def create_hartree_fock_init_function(M, N, mapping_type='jordan_wigner'):
"""

if mapping_type=='jordan_wigner':
def init_function(qv):
for i in range(N):
x(qv[i])
def init_function(qv):
for i in range(N):
x(qv[i])

"""
if mapping_type=='parity':
def init_function(qv):
for i in range(N//2):
Expand All @@ -474,11 +470,12 @@ def init_function(qv):
if N%2==1:
for i in range(N-1,M):
x(qv[i])
"""

return init_function


def electronic_structure_problem(arg, active_orb=None, active_elec=None, mapping_type='jordan_wigner', ansatz_type='QCCSD', threshold=1e-4):
def electronic_structure_problem(arg, active_orb=None, active_elec=None, ansatz_type='QCCSD', threshold=1e-4):
r"""
Creates a VQE problem instance for an electronic structure problem defined by the
one-electron and two-electron integrals for the spin orbitals (in physicists' notation).
Expand Down Expand Up @@ -520,9 +517,6 @@ def electronic_structure_problem(arg, active_orb=None, active_elec=None, mapping
The number of active spin orbitals.
active_elec : int, optional
The number of active electrons.
mapping_type : string, optinal
The mapping from fermionic Hamiltonian to qubit Hamiltonian. Available are ``jordan_wigner``, ``parity``.
The default is ``jordan_wigner``.
ansatz_type : string, optional
The ansatz type. Availabe is ``QCCSD``. The default is ``QCCSD``.
threshold : float, optional
Expand Down Expand Up @@ -579,7 +573,7 @@ def electronic_structure_problem(arg, active_orb=None, active_elec=None, mapping
ansatz, num_params = create_QCCSD_ansatz(K,L)

fermionic_hamiltonian = create_electronic_hamiltonian(data,K,L)
hamiltonian = fermionic_hamiltonian.to_qubit_operator(mapping_type=mapping_type)
hamiltonian = fermionic_hamiltonian.to_qubit_operator(mapping_type='jordan_wigner')
hamiltonian.apply_threshold(threshold)

return VQEProblem(hamiltonian, ansatz, num_params, init_function=create_hartree_fock_init_function(K,L,mapping_type))
return VQEProblem(hamiltonian, ansatz, num_params, init_function=create_hartree_fock_init_function(K,L))

0 comments on commit e0e8b75

Please sign in to comment.