Beispiel #1
0
 def __call__(self, U,  *args, **kwargs):
     circuit = self.Upre + U + self.Upost
     objective = ExpectationValue(H=self.H, U=circuit)
     Qp = paulis.Qp(U.qubits)
     # get all overlaps
     for i,Ux in enumerate(self.circuits):
         S2 = ExpectationValue(H=Qp, U=circuit+Ux.dagger())
         objective += numpy.abs(self.factors[i])*S2
     return objective
Beispiel #2
0
def test_paulistring_sampling(backend, case):
    print(case)
    H = QubitHamiltonian.from_paulistrings(PauliString.from_string(case[0]))
    U = gates.X(target=1) + gates.X(target=3) + gates.X(target=5)
    E = ExpectationValue(H=H, U=U)
    result = simulate(E,backend=backend, samples=1)
    assert isclose(result, case[1], 1.e-4)
    def compute_energy(self, method, *args, **kwargs):
        """
        Call classical methods over PySCF (needs to be installed) or
        use as a shortcut to calculate quantum energies (see make_upccgsd_ansatz)

        Parameters
        ----------
        method: method name
                classical: HF, MP2, CCSD, CCSD(T), FCI
                quantum: SPA-GASD (SPA can be dropped as well as letters in GASD)
                examples: GSD is the same as UpCCGSD, SPA alone is equivalent to SPA-D
                see make_upccgsd_ansatz of the this class for more information
        args
        kwargs

        Returns
        -------

        """
        if any([x in method.upper() for x in ["U", "SPA", "PNO", "HCB"]]):
            # simulate entirely in HCB representation if no singles are involved
            if "S" not in method.upper().split("-")[-1] and "HCB" not in method.upper():
                method = "HCB-"+method
            U = self.make_upccgsd_ansatz(name=method)
            if "hcb" in method.lower():
                H = self.make_hardcore_boson_hamiltonian()
            else:
                H = self.make_hamiltonian()
            E = ExpectationValue(H=H, U=U)
            from tequila import minimize
            return minimize(objective=E, *args, **kwargs).energy
        else:
            from tequila.quantumchemistry import INSTALLED_QCHEMISTRY_BACKENDS
            if "pyscf" not in INSTALLED_QCHEMISTRY_BACKENDS:
                raise TequilaMadnessException("PySCF needs to be installed to compute {}/MRA-PNO".format(method))
            else:
                from tequila.quantumchemistry import QuantumChemistryPySCF
                molx = QuantumChemistryPySCF.from_tequila(self)
                return molx.compute_energy(method=method)
Beispiel #4
0
 def __call__(self, U, screening=False, *args, **kwargs):
     return ExpectationValue(H=self.H, U=self.Upre + U + self.Upost, *args, **kwargs)