diff --git a/tangelo/problem_decomposition/dmet/dmet_problem_decomposition.py b/tangelo/problem_decomposition/dmet/dmet_problem_decomposition.py index 0d2d2f33a..e9b211cd1 100644 --- a/tangelo/problem_decomposition/dmet/dmet_problem_decomposition.py +++ b/tangelo/problem_decomposition/dmet/dmet_problem_decomposition.py @@ -176,6 +176,9 @@ def __init__(self, opt_dict): self.orb_list2 = None self.onerdm_low = None + # If save_results in _oneshot_loop is True, the dict is populated. + self.solver_fragment_dict = dict() + @property def quantum_fragments_data(self): """This aims to return a dictionary with all necessary components to diff --git a/tangelo/toolboxes/ansatz_generator/qcc.py b/tangelo/toolboxes/ansatz_generator/qcc.py index 179f85443..4e5605a65 100644 --- a/tangelo/toolboxes/ansatz_generator/qcc.py +++ b/tangelo/toolboxes/ansatz_generator/qcc.py @@ -40,7 +40,6 @@ from tangelo.toolboxes.qubit_mappings.mapping_transform import get_qubit_number,\ fermion_to_qubit_mapping from tangelo.linq import Circuit -from tangelo import SecondQuantizedMolecule from tangelo.toolboxes.ansatz_generator.ansatz import Ansatz from tangelo.toolboxes.ansatz_generator.ansatz_utils import exp_pauliword_to_gates from tangelo.toolboxes.ansatz_generator._qubit_mf import init_qmf_from_hf, get_qmf_circuit, purify_qmf_state @@ -55,9 +54,11 @@ class QCC(Ansatz): state is obtained using a RHF or ROHF Hamiltonian, respectively. Args: - molecule (SecondQuantizedMolecule or dict): The molecular system, which can - be passed as a SecondQuantizedMolecule or a dictionary with keys that - specify n_spinoribtals, n_electrons, and spin. Default, None. + molecule (SecondQuantizedMolecule, SecondQuantizedDMETFragment or dict): + The molecular system, which can be passed as a + SecondQuantizedMolecule/SecondQuantizedDMETFragment or a dictionary + with keys that specify n_spinoribtals, n_electrons, and spin. + Default, None. mapping (str): One of the supported qubit mapping identifiers. Default, "jw". up_then_down (bool): Change basis ordering putting all spin-up orbitals first, followed by all spin-down. Default, False. @@ -86,18 +87,20 @@ def __init__(self, molecule, mapping="jw", up_then_down=False, dis=None, qmf_circuit=None, qmf_var_params=None, qubit_ham=None, qcc_tau_guess=1e-2, deqcc_dtau_thresh=1e-3, max_qcc_gens=None, reference_state="HF"): - if not molecule and not (isinstance(molecule, SecondQuantizedMolecule) and isinstance(molecule, dict)): - raise ValueError("An instance of SecondQuantizedMolecule or a dict is required for " - "initializing the self.__class__.__name__ ansatz class.") + if isinstance(molecule, dict) and not qubit_ham: + raise ValueError(f"An instance of SecondQuantizedMolecule or a dict" + " + qubit operator is required for initializing the " + f"{self.__class__.__name__} ansatz class.") + self.molecule = molecule - if isinstance(self.molecule, SecondQuantizedMolecule): - self.n_spinorbitals = self.molecule.n_active_sos - self.n_electrons = self.molecule.n_active_electrons - self.spin = self.molecule.spin - elif isinstance(self.molecule, dict): + if isinstance(self.molecule, dict): self.n_spinorbitals = self.molecule["n_spinorbitals"] self.n_electrons = self.molecule["n_electrons"] self.spin = self.molecule["spin"] + else: + self.n_spinorbitals = self.molecule.n_active_sos + self.n_electrons = self.molecule.n_active_electrons + self.spin = self.molecule.spin self.mapping = mapping self.up_then_down = up_then_down