Skip to content

Commit

Permalink
rdms transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
pwkj committed Apr 16, 2024
1 parent a752e8c commit 78c8dc6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/tequila/quantumchemistry/qc_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,8 @@ def rdm2(self):
return None

def compute_rdms(self, U: QCircuit = None, variables: Variables = None, spin_free: bool = True,
get_rdm1: bool = True, get_rdm2: bool = True, ordering="dirac", use_hcb: bool = False):
get_rdm1: bool = True, get_rdm2: bool = True, ordering="dirac", use_hcb: bool = False,
rdm_trafo: QubitHamiltonian = False):
"""
Computes the one- and two-particle reduced density matrices (rdm1 and rdm2) given
a unitary U. This method uses the standard ordering in physics as denoted below.
Expand Down Expand Up @@ -1666,6 +1667,9 @@ def compute_rdms(self, U: QCircuit = None, variables: Variables = None, spin_fre
get_rdm1, get_rdm2 :
Set whether either one or both rdm1, rdm2 should be computed. If both are needed at some point,
it is recommended to compute them at once.
rdm_trafo :
The rdm operators can be transformed, e.g., a^dagger_i a_j -> U^dagger a^dagger_i a_j U,
where U represents the transformation. The default is set to None, implying that U equas the identity.
Returns
-------
Expand Down Expand Up @@ -1910,8 +1914,13 @@ def _build_2bdy_operators_hcb() -> list:
# Transform operator lists to QubitHamiltonians
if (not use_hcb):
qops = [_get_qop_hermitian(op) for op in qops]

# Compute expected values
evals = simulate(ExpectationValue(H=qops, U=U, shape=[len(qops)]), variables=variables)
if rdm_trafo is None:
evals = simulate(ExpectationValue(H=qops, U=U, shape=[len(qops)]), variables=variables)
else:
qops = [rdm_trafo.dagger()*qops[i]*rdm_trafo for i in range(len(qops))]
evals = simulate(ExpectationValue(H=qops, U=U, shape=[len(qops)]), variables=variables)

# Assemble density matrices
# If self._rdm1, self._rdm2 exist, reset them if they are of the other spin-type
Expand Down

0 comments on commit 78c8dc6

Please sign in to comment.