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

Simplify Hamiltonian functions in Molecule class #19

Merged
merged 2 commits into from
May 10, 2023
Merged

Conversation

chmwzc
Copy link
Contributor

@chmwzc chmwzc commented Apr 24, 2023

Previously:

Needed three lines to get the molecular Hamiltonian as a SymbolicHamiltonian:

fermionic_ham = mol.fermionic_hamiltonian()
qubit_ham = mol.qubit_hamiltonian(fermionic_ham)
symbolic_ham = mol.symbolic_hamiltonian(qubit_ham)

Gets really tedious after a while...

Now:

Do everything in a single function call instead!

symbolic_ham = mol.hamiltonian()

Another example: HF embedding:

# Run HF embedding
mol.hf_embedding(active=<Your active space here>)
# Define the OEI/TEI to be used for the molecular Hamiltonian
hamiltonian = mol.hamiltonian(oei=mol.embed_oei, tei=mol.embed_tei, constant=mol.inactive_energy)

Notes

  • Default arguments of the new hamiltonian() function uses the Molecule class attributes oei, tei, and e_nuc to get the molecular Hamiltonian as a SymbolicHamiltonian directly; no longer need to type so many lines 😄
  • If one wants to work with the OpenFermion FermionOperator or QubitOperator, the ham_type argument can be used, with "f" to get a FermionOperator, or "q" to get the QubitOperator.
    • E.g. fermion_operator = mol.hamiltonian("f") returns the molecular Hamiltonian as a FermionOperator
  • Arguments for the functions in the previous version of the code are all included as well (see docstring below)
    def hamiltonian(
        self,
        ham_type=None,
        oei=None,
        tei=None,
        constant=None,
        ferm_qubit_map=None,
    ):
        """
        Builds a molecular Hamiltonian using the one-/two- electron integrals

        Args:
            ham_type: Format of molecular Hamiltonian returned
                ("f", "ferm"): OpenFermion FermionOperator
                ("q", "qubit"): OpenFermion QubitOperator
                ("s", "sym"): Qibo SymbolicHamiltonian (default)
            oei: 1-electron integrals. Default: self.oei (MO basis)
            tei: 2-electron integrals in 2ndQ notation. Default: self.tei (MO basis)
            constant: For inactive Fock energy if embedding used. Default: 0.0
            ferm_qubit_map: Which fermion to qubit transformation to use.
                Must be either "jw" (default) or "bk"

            Returns:
                Molecular Hamiltonian in the format of choice
        """
  • expectation() and eigenvalues() functions were also cleaned up slightly
    • Draft code (commented out) that uses expectation_from_samples() added in as well

chmwzc added 2 commits April 21, 2023 17:49
Now only need to call .hamiltonian() directly to get the
SymbolicHamiltonian!
@damarkian damarkian merged commit a4bd735 into main May 10, 2023
@chmwzc chmwzc deleted the dev/hamiltonian branch May 31, 2023 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants