Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added methods to create annihilation, creation, sz, sp, sm and s2 operators in qubit representation #336

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/tequila/quantumchemistry/qc_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,65 @@ 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)
two = 0.5 * self.make_creation_op(i+1) * self.make_annihilation_op(i+1)
sz += (one - two)
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

def make_hamiltonian(self, *args, **kwargs) -> QubitHamiltonian:
"""
Parameters
Expand Down
Loading