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

DMET bug with QCC #253

Merged
merged 7 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 15 additions & 12 deletions tangelo/toolboxes/ansatz_generator/qcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down