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

RDMs transformation #341

Merged
merged 10 commits into from
Apr 24, 2024
13 changes: 11 additions & 2 deletions src/tequila/quantumchemistry/qc_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,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 = None):
"""
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 @@ -1750,6 +1751,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 @@ -1994,8 +1998,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
Loading