Skip to content

Commit

Permalink
Added documentation and make number operator method
Browse files Browse the repository at this point in the history
  • Loading branch information
davibinco authored Mar 20, 2024
1 parent 6981a89 commit 80bb59b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/tequila/quantumchemistry/qc_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,16 +646,32 @@ def n_electrons(self) -> int:
return 2 * len(self.integral_manager.active_reference_orbitals)

def make_annihilation_op(self, orbital, coefficient=1.0):
"""
Compute annihilation operator on orbital=orbital in qubit representation
"""
assert orbital<=self.n_orbitals*2
aop = openfermion.ops.FermionOperator(f'{orbital}', coefficient)
return self.transformation(aop)

def make_creation_op(self, orbital, coefficient=1.0):
"""
Compute creation operator on orbital=orbital in qubit representation
"""
assert orbital<=self.n_orbitals*2
cop = openfermion.ops.FermionOperator(f'{orbital}^', coefficient)
return self.transformation(cop)

def make_number_op(self, orbital):
"""
Compute number operator on orbital=orbital in qubit representation
"""
num_op = self.make_creation_op(orbital) * self.make_annihilation_op(orbital)
return num_op

def make_sz_op(self):
"""
Compute the spin_z operator of the molecule in qubit representation
"""
sz = QubitHamiltonian()
for i in range(0, self.n_orbitals * 2, 2):
one = 0.5 * self.make_creation_op(i) * self.make_annihilation_op(i)
Expand All @@ -664,18 +680,27 @@ def make_sz_op(self):
return sz

def make_sp_op(self):
"""
Compute the spin+ operator of the molecule in qubit representation
"""
sp = QubitHamiltonian()
for i in range(self.n_orbitals):
sp += self.make_creation_op(i*2) * self.make_annihilation_op(i*2 + 1)
return sp

def make_sm_op(self):
"""
Compute the spin- operator of the molecule in qubit representation
"""
sm = QubitHamiltonian()
for i in range(self.n_orbitals):
sm += self.make_creation_op(i*2 + 1) * self.make_annihilation_op(i*2)
return sm

def make_s2_op(self):
"""
Compute the spin^2 operator of the molecule in qubit representation
"""
s2_op = self.make_sm_op() * self.make_sp_op() + self.make_sz_op() * (self.make_sz_op() + 1)
return s2_op

Expand Down

0 comments on commit 80bb59b

Please sign in to comment.