From 78c8dc6ff506266a692c2967dd07050d1535bab8 Mon Sep 17 00:00:00 2001 From: pwkj Date: Tue, 16 Apr 2024 13:59:03 +0200 Subject: [PATCH] rdms transformation --- src/tequila/quantumchemistry/qc_base.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tequila/quantumchemistry/qc_base.py b/src/tequila/quantumchemistry/qc_base.py index 9689b042..c6f6b36d 100644 --- a/src/tequila/quantumchemistry/qc_base.py +++ b/src/tequila/quantumchemistry/qc_base.py @@ -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. @@ -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 ------- @@ -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