sandbox-quantum / Tangelo

A python package for exploring end-to-end chemistry workflows on quantum computers and simulators.
https://sandbox-quantum.github.io/Tangelo/
Other
109 stars 29 forks source link

Bugfix: DMET fragment object initialization from IntegralSolver fixed #355

Closed alexfleury-sb closed 11 months ago

alexfleury-sb commented 11 months ago

A bug was causing this code to crash

from tangelo import SecondQuantizedMolecule
from tangelo.problem_decomposition.dmet.dmet_problem_decomposition import Localization, DMETProblemDecomposition

xyz_H4 = [("H", [0.0, 0.0, i*2.5]) for i in range(4)]
mol = SecondQuantizedMolecule(xyz_H4, q=0, spin=0, basis="sto-3g")

my_backend_options = {"target": "qulacs", "n_shots": None, "noise_model": None}
solvers_options = {"backend_options": my_backend_options}

opt_dmet = {"molecule": mol,
            "fragment_atoms": [1]*4,
            "fragment_solvers": ["vqe"]*4,
            "solvers_options": [solvers_options]*4,
            "electron_localization": Localization.meta_lowdin,
            "verbose": True
            }

# Run DMET
dmet = DMETProblemDecomposition(opt_dmet)
dmet.build()

energy = dmet.simulate()

print(energy)

The root cause of this was because the initial_var_params for the UCCSD ansatz is set to MP2. The code portiuon computing those parameter was checking the solver attribute of the provided molecule, and SecondQuantizedDMETFragment did not have that attribute.

The test were not failing because when no solvers_options is defined, the initial_var_params for VQE are set to ones. Setting the solvers_options without specifying the initial_var_params was reverting them to MP2 for the default ansatz (UCCSD).