Giter Club home page Giter Club logo

openfermion-pyscf's Introduction

OpenFermion-PySCF

image

image

OpenFermion is an open source library (licensed under Apache 2) for compiling and analyzing quantum algorithms which simulate fermionic systems. This plugin library allows the electronic structure package PySCF (licensed under BSD-2-Clause) to interface with OpenFermion.

Installation

To start using OpenFermion-PySCF, first install PySCF. Then, to install the latest versions of OpenFermion and OpenFermion-PySCF (in development mode):

git clone https://github.com/quantumlib/OpenFermion-PySCF
cd OpenFermion-PySCF
python -m pip install -e .

Alternatively, to install the latest PyPI releases as libraries (in user mode):

python -m pip install --user openfermionpyscf

Also be sure to take a look at the ipython notebook demo.

How to contribute

We'd love to accept your contributions and patches to OpenFermion-PySCF. There are a few guidelines you need to follow. Contributions to OpenFermion-PySCF must be accompanied by a Contributor License Agreement. You (or your employer) retain the copyright to your contribution, this simply gives us permission to use and redistribute your contributions as part of the project. Head over to https://cla.developers.google.com/ to see your current agreements on file or to sign a new one.

All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult GitHub Help for more information on using pull requests. Furthermore, please make sure your new code comes with extensive tests! We use automatic testing to make sure all pull requests pass tests and do not decrease overall test coverage by too much. Make sure you adhere to our style guide. Just have a look at our code for clues. We mostly follow PEP 8 and use the corresponding linter to check for it. Code should always come with documentation.

Authors

Ryan Babbush (Google), Jarrod McClean (Google), Kevin Sung (University of Michigan), Ian Kivlichan (Harvard), Dave Bacon (Google), Yudong Cao (Harvard), Chengyu Dai (University of Michigan), E. Schuyler Fried (Harvard), Craig Gidney (Google), Brendan Gimby (University of Michigan), Pranav Gokhale (University of Chicago), Thomas Häner (ETH Zurich), Tarini Hardikar (Dartmouth), Vojtĕch Havlíček (Oxford), Oscar Higgott (University College London), Cupjin Huang (University of Michigan), Josh Izaac (Xanadu), Zhang Jiang (NASA), Xinle Liu (Google), Sam McArdle (Oxford), Matthew Neeley (Google), Thomas O'Brien (Leiden University), Bryan O'Gorman (UC Berkeley, NASA), Isil Ozfidan (D-Wave Systems), Max Radin (UC Santa Barbara), Jhonathan Romero (Harvard), Nicholas Rubin (Google), Daniel Sank (Google), Nicolas Sawaya (Harvard), Kanav Setia (Dartmouth), Hannah Sim (Harvard), Damian Steiger (ETH Zurich), Mark Steudtner (Leiden University), Qiming Sun (Caltech), Wei Sun (Google), Daochen Wang (River Lane Research), Chris Winkler (University of Chicago) and Fang Zhang (University of Michigan).

How to cite

When using OpenFermion-PySCF for research projects, please cite:

Jarrod R. McClean, Kevin J. Sung, Ian D. Kivlichan, Yudong Cao, Chengyu Dai, E. Schuyler Fried, Craig Gidney, Brendan Gimby, Pranav Gokhale, Thomas Häner, Tarini Hardikar, Vojtĕch Havlíček, Oscar Higgott, Cupjin Huang, Josh Izaac, Zhang Jiang, Xinle Liu, Sam McArdle, Matthew Neeley, Thomas O'Brien, Bryan O'Gorman, Isil Ozfidan, Maxwell D. Radin, Jhonathan Romero, Nicholas Rubin, Nicolas P. D. Sawaya, Kanav Setia, Sukin Sim, Damian S. Steiger, Mark Steudtner, Qiming Sun, Wei Sun, Daochen Wang, Fang Zhang and Ryan Babbush. OpenFermion: The Electronic Structure Package for Quantum Computers. arXiv:1710.07629. 2017.

as well as

Qiming Sun, Timothy C. Berkelbach, Nick S. Blunt, George H. Booth, Sheng Guo, Zhendong Li, Junzi Liu, James McClain, Elvira. R. Sayfutyarova, Sandeep Sharma, Sebastian Wouters and Garnet Kin-Lic Chan. The Python-based Simulations of Chemistry Framework (PySCF). WIREs Compututational Molecular Science. 2017.

We are happy to include future contributors as authors on later OpenFermion releases.

Disclaimer

Copyright 2017 The OpenFermion Developers. This is not an official Google product.

openfermion-pyscf's People

Contributors

babbush avatar dabacon avatar jarrodmcc avatar kevinsung avatar ncrubin avatar r-imai-quantum avatar strilanc avatar sunqm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openfermion-pyscf's Issues

Continuous integration testing

In principle we should be able to setup automatic testing with Travis similar to how we set it up in OpenFermion core. The main issue is that this requires a method of automatically installing pyscf. I would rate this as a very high priority. @sunqm is this something you can help with? Since you are an expert in pyscf installation, perhaps you can get this to work. If so, I can give you admin to the repo to set this up.

2 tests fail

========================================================================================== FAILURES ==========================================================================================
______________________________________________________________________________ test_load_molecular_hamiltonian _______________________________________________________________________________

src = '37316d06-b95c-4ffb-91d3-5beaeb5c9326.hdf5', dst = '/usr/local/lib/python3.9/site-packages/openfermion/testing/data/H1-Li1_sto-3g_singlet.hdf5'
copy_function = <function copy2 at 0x83487a790>

    def move(src, dst, copy_function=copy2):
        """Recursively move a file or directory to another location. This is
        similar to the Unix "mv" command. Return the file or directory's
        destination.
    
        If the destination is a directory or a symlink to a directory, the source
        is moved inside the directory. The destination path must not already
        exist.
    
        If the destination already exists but is not a directory, it may be
        overwritten depending on os.rename() semantics.
    
        If the destination is on our current filesystem, then rename() is used.
        Otherwise, src is copied to the destination and then removed. Symlinks are
        recreated under the new name if os.rename() fails because of cross
        filesystem renames.
    
        The optional `copy_function` argument is a callable that will be used
        to copy the source or it will be delegated to `copytree`.
        By default, copy2() is used, but any function that supports the same
        signature (like copy()) can be used.
    
        A lot more could be done here...  A look at a mv.c shows a lot of
        the issues this implementation glosses over.
    
        """
        sys.audit("shutil.move", src, dst)
        real_dst = dst
        if os.path.isdir(dst):
            if _samefile(src, dst):
                # We might be on a case insensitive filesystem,
                # perform the rename anyway.
                os.rename(src, dst)
                return
    
            # Using _basename instead of os.path.basename is important, as we must
            # ignore any trailing slash to avoid the basename returning ''
            real_dst = os.path.join(dst, _basename(src))
    
            if os.path.exists(real_dst):
                raise Error("Destination path '%s' already exists" % real_dst)
        try:
>           os.rename(src, real_dst)
E           PermissionError: [Errno 13] Permission denied: '37316d06-b95c-4ffb-91d3-5beaeb5c9326.hdf5' -> '/usr/local/lib/python3.9/site-packages/openfermion/testing/data/H1-Li1_sto-3g_singlet.hdf5'

/usr/local/lib/python3.9/shutil.py:825: PermissionError

During handling of the above exception, another exception occurred:

    def test_load_molecular_hamiltonian():
        geometry = [('Li', (0., 0., 0.)), ('H', (0., 0., 1.4))]
    
>       lih_hamiltonian = openfermionpyscf.generate_molecular_hamiltonian(
                geometry, 'sto-3g', 1, 0, 2, 2)

openfermionpyscf/_run_pyscf_test.py:20: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
openfermionpyscf/_run_pyscf.py:237: in generate_molecular_hamiltonian
    molecule = run_pyscf(
openfermionpyscf/_run_pyscf.py:205: in run_pyscf
    pyscf_molecular_data.save()
/usr/local/lib/python3.9/site-packages/openfermion/chem/molecular_data.py:717: in save
    shutil.move("{}.hdf5".format(tmp_name), "{}.hdf5".format(self.filename))
/usr/local/lib/python3.9/shutil.py:845: in move
    copy_function(src, real_dst)
/usr/local/lib/python3.9/shutil.py:444: in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

src = '37316d06-b95c-4ffb-91d3-5beaeb5c9326.hdf5', dst = '/usr/local/lib/python3.9/site-packages/openfermion/testing/data/H1-Li1_sto-3g_singlet.hdf5'

    def copyfile(src, dst, *, follow_symlinks=True):
        """Copy data from src to dst in the most efficient way possible.
    
        If follow_symlinks is not set and src is a symbolic link, a new
        symlink will be created instead of copying the file it points to.
    
        """
        sys.audit("shutil.copyfile", src, dst)
    
        if _samefile(src, dst):
            raise SameFileError("{!r} and {!r} are the same file".format(src, dst))
    
        file_size = 0
        for i, fn in enumerate([src, dst]):
            try:
                st = _stat(fn)
            except OSError:
                # File most likely does not exist
                pass
            else:
                # XXX What about other special files? (sockets, devices...)
                if stat.S_ISFIFO(st.st_mode):
                    fn = fn.path if isinstance(fn, os.DirEntry) else fn
                    raise SpecialFileError("`%s` is a named pipe" % fn)
                if _WINDOWS and i == 0:
                    file_size = st.st_size
    
        if not follow_symlinks and _islink(src):
            os.symlink(os.readlink(src), dst)
        else:
            with open(src, 'rb') as fsrc:
                try:
>                   with open(dst, 'wb') as fdst:
E                   PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.9/site-packages/openfermion/testing/data/H1-Li1_sto-3g_singlet.hdf5'

/usr/local/lib/python3.9/shutil.py:266: PermissionError
------------------------------------------------------------------------------------ Captured stdout call ------------------------------------------------------------------------------------
overwrite output file: addopts=
_______________________________________________________________________________________ test_run_pyscf _______________________________________________________________________________________

src = 'e420e408-8627-4146-8f01-6d197ff47f0c.hdf5', dst = '/usr/local/lib/python3.9/site-packages/openfermion/testing/data/H2_6-31g_singlet.hdf5'
copy_function = <function copy2 at 0x83487a790>

    def move(src, dst, copy_function=copy2):
        """Recursively move a file or directory to another location. This is
        similar to the Unix "mv" command. Return the file or directory's
        destination.
    
        If the destination is a directory or a symlink to a directory, the source
        is moved inside the directory. The destination path must not already
        exist.
    
        If the destination already exists but is not a directory, it may be
        overwritten depending on os.rename() semantics.
    
        If the destination is on our current filesystem, then rename() is used.
        Otherwise, src is copied to the destination and then removed. Symlinks are
        recreated under the new name if os.rename() fails because of cross
        filesystem renames.
    
        The optional `copy_function` argument is a callable that will be used
        to copy the source or it will be delegated to `copytree`.
        By default, copy2() is used, but any function that supports the same
        signature (like copy()) can be used.
    
        A lot more could be done here...  A look at a mv.c shows a lot of
        the issues this implementation glosses over.
    
        """
        sys.audit("shutil.move", src, dst)
        real_dst = dst
        if os.path.isdir(dst):
            if _samefile(src, dst):
                # We might be on a case insensitive filesystem,
                # perform the rename anyway.
                os.rename(src, dst)
                return
    
            # Using _basename instead of os.path.basename is important, as we must
            # ignore any trailing slash to avoid the basename returning ''
            real_dst = os.path.join(dst, _basename(src))
    
            if os.path.exists(real_dst):
                raise Error("Destination path '%s' already exists" % real_dst)
        try:
>           os.rename(src, real_dst)
E           PermissionError: [Errno 13] Permission denied: 'e420e408-8627-4146-8f01-6d197ff47f0c.hdf5' -> '/usr/local/lib/python3.9/site-packages/openfermion/testing/data/H2_6-31g_singlet.hdf5'

/usr/local/lib/python3.9/shutil.py:825: PermissionError

During handling of the above exception, another exception occurred:

    def test_run_pyscf():
>       new_mole = run_pyscf(molecule,
                             run_scf=True,
                             run_mp2=True,
                             run_cisd=True,
                             run_ccsd=True,
                             run_fci=True,
                             verbose=1)

openfermionpyscf/tests/_run_pyscf_test.py:32: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
openfermionpyscf/_run_pyscf.py:205: in run_pyscf
    pyscf_molecular_data.save()
/usr/local/lib/python3.9/site-packages/openfermion/chem/molecular_data.py:717: in save
    shutil.move("{}.hdf5".format(tmp_name), "{}.hdf5".format(self.filename))
/usr/local/lib/python3.9/shutil.py:845: in move
    copy_function(src, real_dst)
/usr/local/lib/python3.9/shutil.py:444: in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

src = 'e420e408-8627-4146-8f01-6d197ff47f0c.hdf5', dst = '/usr/local/lib/python3.9/site-packages/openfermion/testing/data/H2_6-31g_singlet.hdf5'

    def copyfile(src, dst, *, follow_symlinks=True):
        """Copy data from src to dst in the most efficient way possible.
    
        If follow_symlinks is not set and src is a symbolic link, a new
        symlink will be created instead of copying the file it points to.
    
        """
        sys.audit("shutil.copyfile", src, dst)
    
        if _samefile(src, dst):
            raise SameFileError("{!r} and {!r} are the same file".format(src, dst))
    
        file_size = 0
        for i, fn in enumerate([src, dst]):
            try:
                st = _stat(fn)
            except OSError:
                # File most likely does not exist
                pass
            else:
                # XXX What about other special files? (sockets, devices...)
                if stat.S_ISFIFO(st.st_mode):
                    fn = fn.path if isinstance(fn, os.DirEntry) else fn
                    raise SpecialFileError("`%s` is a named pipe" % fn)
                if _WINDOWS and i == 0:
                    file_size = st.st_size
    
        if not follow_symlinks and _islink(src):
            os.symlink(os.readlink(src), dst)
        else:
            with open(src, 'rb') as fsrc:
                try:
>                   with open(dst, 'wb') as fdst:
E                   PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.9/site-packages/openfermion/testing/data/H2_6-31g_singlet.hdf5'

/usr/local/lib/python3.9/shutil.py:266: PermissionError
------------------------------------------------------------------------------------ Captured stdout call ------------------------------------------------------------------------------------
overwrite output file: addopts=
Hartree-Fock energy for H2_6-31g_singlet (2 electrons) is -1.1267339671165666.
MP2 energy for H2_6-31g_singlet (2 electrons) is -1.1441304105295214.
CISD energy for H2_6-31g_singlet (2 electrons) is -1.1516827321098897.
CCSD energy for H2_6-31g_singlet (2 electrons) is -1.1516828675117317.
FCI energy for H2_6-31g_singlet (2 electrons) is -1.1516827321098888.
====================================================================================== warnings summary ======================================================================================
openfermionpyscf/_pyscf_molecular_data.py:72
  /disk-samsung/freebsd-ports/science/py-OpenFermion-PySCF/work-py39/OpenFermion-PySCF-0.5/openfermionpyscf/_pyscf_molecular_data.py:72: DeprecationWarning: invalid escape sequence \i
    """A 4-dimension array for electron repulsion integrals in the MO

../../../../../../usr/local/lib/python3.9/site-packages/pyscf/__init__.py:93
  /usr/local/lib/python3.9/site-packages/pyscf/__init__.py:93: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    if LooseVersion(numpy.__version__) <= '1.8.0':

../../../../../../usr/local/lib/python3.9/site-packages/setuptools/_distutils/version.py:346
../../../../../../usr/local/lib/python3.9/site-packages/setuptools/_distutils/version.py:346
../../../../../../usr/local/lib/python3.9/site-packages/setuptools/_distutils/version.py:346
../../../../../../usr/local/lib/python3.9/site-packages/setuptools/_distutils/version.py:346
../../../../../../usr/local/lib/python3.9/site-packages/setuptools/_distutils/version.py:346
../../../../../../usr/local/lib/python3.9/site-packages/setuptools/_distutils/version.py:346
../../../../../../usr/local/lib/python3.9/site-packages/setuptools/_distutils/version.py:346
../../../../../../usr/local/lib/python3.9/site-packages/setuptools/_distutils/version.py:346
  /usr/local/lib/python3.9/site-packages/setuptools/_distutils/version.py:346: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    other = LooseVersion(other)

../../../../../../usr/local/lib/python3.9/site-packages/pyscf/__init__.py:99
  /usr/local/lib/python3.9/site-packages/pyscf/__init__.py:99: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    elif '1.16.2' <= LooseVersion(numpy.__version__) < '1.18':

../../../../../../usr/local/lib/python3.9/site-packages/numpy/ctypeslib.py:137
  /usr/local/lib/python3.9/site-packages/numpy/ctypeslib.py:137: DeprecationWarning: 
  
    `numpy.distutils` is deprecated since NumPy 1.23.0, as a result
    of the deprecation of `distutils` itself. It will be removed for
    Python >= 3.12. For older Python versions it will remain present.
    It is recommended to use `setuptools < 60.0` for those Python versions.
    For more details, see:
      https://numpy.org/devdocs/reference/distutils_status_migration.html 
  
  
    from numpy.distutils.misc_util import get_shared_lib_extension

../../../../../../usr/local/lib/python3.9/site-packages/pyscf/lib/numpy_helper.py:884
../../../../../../usr/local/lib/python3.9/site-packages/pyscf/lib/numpy_helper.py:884
  /usr/local/lib/python3.9/site-packages/pyscf/lib/numpy_helper.py:884: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    if LooseVersion(numpy.__version__) <= LooseVersion('1.6.0'):

../../../../../../usr/local/lib/python3.9/site-packages/matplotlib/__init__.py:152
../../../../../../usr/local/lib/python3.9/site-packages/matplotlib/__init__.py:152
../../../../../../usr/local/lib/python3.9/site-packages/matplotlib/__init__.py:152
../../../../../../usr/local/lib/python3.9/site-packages/matplotlib/__init__.py:152
../../../../../../usr/local/lib/python3.9/site-packages/matplotlib/__init__.py:152
  /usr/local/lib/python3.9/site-packages/matplotlib/__init__.py:152: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    if LooseVersion(module.__version__) < minver:

../../../../../../usr/local/lib/python3.9/site-packages/openfermion/hamiltonians/hartree_fock.py:11
  /usr/local/lib/python3.9/site-packages/openfermion/hamiltonians/hartree_fock.py:11: DeprecationWarning: Please use `OptimizeResult` from the `scipy.optimize` namespace, the `scipy.optimize.optimize` namespace is deprecated.
    from scipy.optimize.optimize import OptimizeResult

../../../../../../usr/local/lib/python3.9/site-packages/pyscf/mp/mp2.py:357
../../../../../../usr/local/lib/python3.9/site-packages/pyscf/mp/mp2.py:357
../../../../../../usr/local/lib/python3.9/site-packages/pyscf/mp/mp2.py:357
../../../../../../usr/local/lib/python3.9/site-packages/pyscf/mp/mp2.py:357
openfermionpyscf/tests/_pyscf_molecular_data_test.py::test_accessing_rdm
openfermionpyscf/tests/_run_pyscf_test.py::test_run_pyscf
openfermionpyscf/tests/_run_pyscf_test.py::test_run_pyscf
openfermionpyscf/tests/_run_pyscf_test.py::test_run_pyscf
openfermionpyscf/tests/_run_pyscf_test.py::test_run_pyscf
  /usr/local/lib/python3.9/site-packages/pyscf/mp/mp2.py:357: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    moidx = numpy.ones(mp.mo_occ.size, dtype=numpy.bool)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
==================================================================== 2 failed, 2 passed, 29 warnings in 93.82s (0:01:33) =====================================================================
*** Error code 1

Version: 0.5
Python-3.9
FreeBSD 13.1

Unable to install using pip within Python 3.7.9 environment

I am attempting to install this software after running into issues after downloading the pennylane package by following the instructions provided here. When I ran the following:

H, qubits = qml.qchem.molecular_hamiltonian(symbols, coordinates)

I received the following error: ModuleNotFoundError: No module named 'openfermionpyscf'

I decided to install this package manually by going to this repository and using the commands:

python -m pip install --user openfermionpyscf

But this run into the following issue:

ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.

This lead me to install it using the following command:

pip install openfermionpyscf

This lead to the following error:

ERROR: The tar file (C:\Users\13473\AppData\Local\Temp\pip-unpack-ppyy7yj7\pyscf-2.0.1.tar.gz) has a file (C:\Users\13473\AppData\Local\Temp\pip-install-lves2kza\pyscf\pyscf/agf2/aux.py) trying to install outside target directory (C:\Users\13473\AppData\Local\Temp\pip-install-lves2kza\pyscf)

This is my first time encountering these types of error messages, so I am not entirely sure what this means or what should be done to resolve it.

CC double excitation pre-factor convention

There is a subtlety with the definition of ccsd_double_amps generated by run_pyscf (and the _pyscf_molecular_data behind it). For a user to correctly instantiate the packed ccsd amplitudes in openfermion, he would actually need to do
uccsd_singlet_get_packed_amplitudes(ccsd_single_amps, (1/2)*ccsd_double_amps, num_qubits, num_electrons)
on data generated from run_pyscf. Notice the factor 1/2; In the literature, I don't think there is a clear winner on the prefactor in front of T_2, the CC doubles operator. I have seen 1, or 1/2, or 1/4.

However, as a simple test, I have compared several different methods, and for H2 and LiH, and found good agreement between 'classical' CCSD and quantum circuit UCCSD with the packed amplitudes generated by uccsd_singlet_get_packed_amplitudes(ccsd_single_amps, ccsd_double_amps, num_qubits, num_electrons), for input data from OpenfermionPsi4 and other test hdf5 files around, where there is no need for a pre-factor, and the assumptions/conventions therefore seem aligned.

Now, only for data generated by openfermionpyscf there is a need for this factor 0.5 (sanity check: omitting the factor gives results which are worse even than HF). Hope I explained that clearly, and perhaps someone can independently check this.
A possible solution is to adjust the property ccsd_double_amps of PyscfMolecularData and insert the factor there, in order to be consistent with what uccsd_singlet_get_packed_amplitudes assumes.

ImportError: No module named 'pyscf' but OpenFermion-PySCF is installed

Hi,

I'm trying to run some of the examples (generate_diatomic.py) in my Fedora 25 desktop, but I always get the same error (see below), both installing pyscf in the development mode or as a user library

I'm using Python 3.5.4

I tried the same in CentOS 7 using python 2.7 with the same result

Any help will be welcome

Thanks

$ python3 diatomic.py 
Traceback (most recent call last):
  File "/home/fernando/QC/OpenFermion/OpenFermion-PySCF/openfermionpyscf/__init__.py", line 20, in <module>
    from ._run_pyscf import run_pyscf
  File "/home/fernando/QC/OpenFermion/OpenFermion-PySCF/openfermionpyscf/_run_pyscf.py", line 19, in <module>
    import pyscf
ImportError: No module named 'pyscf'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "diatomic.py", line 18, in <module>
    from openfermionpyscf import run_pyscf
  File "/home/fernando/QC/OpenFermion/OpenFermion-PySCF/openfermionpyscf/__init__.py", line 22, in <module>
    raise Exception("Please install PySCF.")
Exception: Please install PySCF.

run_pyscf is broken

For instance, executing the example notebook gives the error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-3cf684407860> in <module>
     35                          run_cisd=run_cisd,
     36                          run_ccsd=run_ccsd,
---> 37                          run_fci=run_fci)
     38 
     39     # Print out some results of calculation.

~/Projects/OpenFermion-PySCF/openfermionpyscf/_run_pyscf.py in run_pyscf(molecule, run_scf, run_mp2, run_cisd, run_ccsd, run_fci, verbose)
    158             print("WARNING: RO-MP2 is not available in PySCF.")
    159         else:
--> 160             pyscf_mp2 = pyscf.mp.MP2(pyscf_scf)
    161             pyscf_mp2.verbose = 0
    162             pyscf_mp2.run()

AttributeError: module 'pyscf' has no attribute 'mp'

@sunqm Do you know what's up with this? Something strange that I found is that if I do

import pyscf
_ = pyscf.mp

I get the same error,

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'pyscf' has no attribute 'mp'

However,

from pyscf import mp

works fine.

'PyscfMolecularData' object has no attribute 'general_calculations'

I run the run_pyscf from openfermionpyscf for an molecular object, loaded from hdf5 molecular file with MolecularData. Then I got the error: 'PyscfMolecularData' object has no attribute 'general_calculations'.

package versions:
openfermion 1.5.0
openfermionpyscf 0.5
pyscf 2.0.1

Code:
from openfermion.chem import MolecularData
from openfermionpyscf import run_pyscf
mol_name = 'H6_0.8.hdf5'
molecule_of = MolecularData(filename=mol_name)
molecule_of.load()
mol = run_pyscf(molecule_of, run_fci=1)

Err info:
----> 4 mol = run_pyscf(molecule_of, run_fci=1)

~/miniconda3/envs/env1/lib/python3.7/site-packages/openfermionpyscf/_run_pyscf.py in run_pyscf(molecule, run_scf, run_mp2, run_cisd, run_ccsd, run_fci, verbose)
203 pyscf_molecular_data = PyscfMolecularData.new(PyscfMolecularData)
204 pyscf_molecular_data.dict.update(molecule.dict)
--> 205 pyscf_molecular_data.save()
206 return pyscf_molecular_data
207

~/miniconda3/envs/env1/lib/python3.7/site-packages/openfermion/chem/molecular_data.py in save(self)
698
699 # Save general calculation data
--> 700 key_list = list(self.general_calculations.keys())
701 f.create_dataset("general_calculations_keys",
702 data=([numpy.string_(key) for key in key_list]

AttributeError: 'PyscfMolecularData' object has no attribute 'general_calculations'

Optional disable file saving when `run_pyscf`

Can we add an option to not save data in run_pyscf?

Saving data is prohibited in my cluster (error message attached) and is not necessary I guess?

  File "/usr/local/lib/python3.6/dist-packages/openfermionpyscf/_run_pyscf.py", line 206, in run_pyscf
    pyscf_molecular_data.save()
  File "/usr/local/lib/python3.6/dist-packages/openfermion/hamiltonians/_molecular_data.py", line 642, in save
    "{}.hdf5".format(self.filename))
OSError: [Errno 18] Invalid cross-device link: 'f73a457b-1fec-42ee-a484-ed2325f89cf0.hdf5' -> '/usr/local/lib/python3.6/dist-packages/openfermion/data/H2_sto-3g_singlet.hdf5'

Related code: save run_pyscf

Package breaks with latest h5py


~/cirq/py39-venv/lib/python3.9/site-packages/pyscf/lib/misc.py in <module>
     44                      'Async-IO is disabled.\n' % ((h5py.version.version,)*2))
     45 if h5py.version.version[:2] == '3.':
---> 46     h5py.get_config().default_file_mode = 'a'
     47 
     48 c_double_p = ctypes.POINTER(ctypes.c_double)

h5py/h5.pyx in h5py.h5.H5PYConfig.default_file_mode.__set__()

ValueError: Using default_file_mode other than 'r' is no longer supported. Pass the mode to h5py.File() instead.

RDM calculation not stored correctly in MolecularData

Hello, I ran a simple test with the H2 molecule at bond distance, this is what I get from the OpenFermion hdf5:

import os
from openfermion.hamiltonians import MolecularData

THIS_DIRECTORY = '.'
filename = os.path.join(THIS_DIRECTORY, 'src','openfermion','data','H2_sto-3g_singlet_0.7414')
molecule = MolecularData([('H', (0,0,0)),('H', (0,0,0.7414))],'sto-3g', 1, filename=filename)
molecule.load()

# FCI RDM
fci_rdm = molecule.get_molecular_rdm(use_fci=True)

print(fci_rdm)

the output is:

((0, 1), (0, 0)) 0.9872699847206565
((1, 1), (1, 0)) 0.9872699847206565
((2, 1), (2, 0)) 0.012730015279343554
((3, 1), (3, 0)) 0.012730015279343554
((0, 1), (1, 1), (0, 0), (1, 0)) -0.9872699847206565
((0, 1), (1, 1), (1, 0), (0, 0)) 0.9872699847206565
((0, 1), (1, 1), (2, 0), (3, 0)) 0.11210692213387734
((0, 1), (1, 1), (3, 0), (2, 0)) -0.11210692213387734
((1, 1), (0, 1), (0, 0), (1, 0)) 0.9872699847206565
((1, 1), (0, 1), (1, 0), (0, 0)) -0.9872699847206565
((1, 1), (0, 1), (2, 0), (3, 0)) -0.11210692213387734
((1, 1), (0, 1), (3, 0), (2, 0)) 0.11210692213387734
((2, 1), (3, 1), (0, 0), (1, 0)) 0.11210692213387734
((2, 1), (3, 1), (1, 0), (0, 0)) -0.11210692213387734
((2, 1), (3, 1), (2, 0), (3, 0)) -0.012730015279343554
((2, 1), (3, 1), (3, 0), (2, 0)) 0.012730015279343554
((3, 1), (2, 1), (0, 0), (1, 0)) -0.11210692213387734
((3, 1), (2, 1), (1, 0), (0, 0)) 0.11210692213387734
((3, 1), (2, 1), (2, 0), (3, 0)) 0.012730015279343554
((3, 1), (2, 1), (3, 0), (2, 0)) -0.012730015279343554

Instead form OpenFermion-PySCF, using the method run_pyscf:

from openfermion.hamiltonians import MolecularData
from openfermionpyscf import run_pyscf

molecule = MolecularData([('H', (0,0,0)),('H', (0,0,0.7414))],'sto-3g', 1)
molecule = run_pyscf(molecule,
                     run_scf=1,
                     run_fci=1)

# FCI RDM
fci_rdm = molecule.get_molecular_rdm(use_fci=True)

print(fci_rdm)

the output is:

((0, 1), (0, 0)) 1.9745399697399248
((1, 1), (1, 0)) 0.025460030260075338
((0, 1), (0, 1), (0, 0), (0, 0)) 1.9745399697399248
((0, 1), (0, 1), (1, 0), (1, 0)) -0.22421384296984592
((1, 1), (1, 1), (0, 0), (0, 0)) -0.22421384296984592
((1, 1), (1, 1), (1, 0), (1, 0)) 0.025460030260075338

The tests have been run with both packages updated to the latest git commit.

Set parse_arg option of pyscf.gto.mole.Mole.build to False

pyscf.gto.mole.Mole.build method has parse_arg option, which specifies whether pyscf should parse command line arguments or not:

https://sunqm.github.io/pyscf/gto.html#pyscf.gto.mole.Mole.build

The default value of the option is True and it sometimes results in a conflict with command line arguments parsed by a user script.
cf. pyscf/pyscf#470

I think the root problem is on pyscf side (they should set the default value to False), but I think it is good to specify the argument explicitly in OpenFermion-PySCF; for example here:

pyscf_molecule.build()

Inconsistency in get_molecular_hamiltonian()

Hello,

I'm using the get_molecular_hamiltonian() method for H4, but the behavior is not being consistent from one execution to the next.

My application is VQE. The problem is that I want to store the optimized parameters, but not the Hamiltonian. However, when I evaluate the energy with the supposedly optimized parameters (obtained in a previous execution), the value is often suboptimal. I can't reproduce the ground state, because the parameters that should define it do not minimize the energy calculated with the Hamiltonian I obtain after I recreate the molecule.

Versions: pyscf 2.2.0, openfermion 1.5.1, openfermionpyscf 0.5

A very simple example of the variations in the Hamiltonian:

from openfermion import MolecularData
from openfermionpyscf import run_pyscf

r = 1.5
geometry = [('H', (0,0,0)), ('H', (0,0,r)), ('H', (0,0,2*r)), ('H', (0,0,3*r))]
basis = 'sto-3g'
multiplicity = 1
charge = 0
h4 = MolecularData(geometry,basis,multiplicity,charge,description='H4')
h4 = run_pyscf(h4,run_fci = True,run_ccsd = True)
print(h4.get_molecular_hamiltonian())

I won't post the full output as it's unnecessary, but I leave the last 10 lines for two different executions of the code above:

((7, 1), (6, 1), (6, 0), (3, 0)) 0.03730971574012655
((7, 1), (6, 1), (6, 0), (7, 0)) 0.22562069773706908
((7, 1), (7, 1), (1, 0), (1, 0)) 0.05498004656600459
((7, 1), (7, 1), (1, 0), (5, 0)) -0.0177711366810768
((7, 1), (7, 1), (3, 0), (3, 0)) 0.0588973786630837
((7, 1), (7, 1), (3, 0), (7, 0)) 0.03730971574012656
((7, 1), (7, 1), (5, 0), (1, 0)) -0.017771136681076806
((7, 1), (7, 1), (5, 0), (5, 0)) 0.08469509925466397
((7, 1), (7, 1), (7, 0), (3, 0)) 0.03730971574012655
((7, 1), (7, 1), (7, 0), (7, 0)) 0.22562069773706908
((7, 1), (6, 1), (6, 0), (3, 0)) -0.03730971574012662
((7, 1), (6, 1), (6, 0), (7, 0)) 0.22562069773706936
((7, 1), (7, 1), (1, 0), (1, 0)) 0.0549800465660047
((7, 1), (7, 1), (1, 0), (5, 0)) -0.017771136681076806
((7, 1), (7, 1), (3, 0), (3, 0)) 0.05889737866308378
((7, 1), (7, 1), (3, 0), (7, 0)) -0.037309715740126585
((7, 1), (7, 1), (5, 0), (1, 0)) -0.017771136681076813
((7, 1), (7, 1), (5, 0), (5, 0)) 0.08469509925466404
((7, 1), (7, 1), (7, 0), (3, 0)) -0.03730971574012662
((7, 1), (7, 1), (7, 0), (7, 0)) 0.22562069773706936

Problem with active space feature in "generate_molecular_hamiltonian"

I am trying to get frozen cores working with an OpenFermion-PySCF workflow, and am having issues. As an example, here I am freezing two electrons (i.e., one core orbital, i.e. 2 qubits.) When I set N_e = 6 and N_qubits = 12, i.e. the full active space, I get matching results between CASCI in PySCF and diagonalization of the Hamiltonian that OF-PSCF gives me. In this example, I use N_e = 4 and N_qubits = 10, and get the wrong reference and CASCI energies from the OF-PSCF Hamiltonian.

def test_adapt_vqe():
"""Test ADAPT on H6."""
if os.path.exists('test') == False:
os.makedirs('test')

geom = 'H 0 0 0; H 0 0 1; H 0 0 2; H 0 0 3; H 0 0 4; H 0 0 5'

basis = "sto-3g"
reference = "rhf"
N_e = 4
N_qubits = 10
multiplicity = 1

#E_nuc, H_core, g, D, C, hf_energy = get_integrals(geom, basis, reference, chkfile = "scr.chk", read = False, active = (int(N_qubits/2), N_e))

#PySCF SCF and CASCI Calculations
mol = gto.M(atom = geom, basis = basis, verbose = False)
mol.build()
mf = scf.RHF(mol)
mf.conv_tol_grad = 1e-8
mf.max_cycle = 10000
mf.init_guess = 'atom'
print("PySCF HF Energy:")
print(mf.kernel())
mycas = mcscf.CASCI(mf, int(N_qubits/2), N_e)
casci = mycas.kernel(verbose=False)
print("PYSCF CASCI:")
print(casci[0])


H = generate_molecular_hamiltonian(geom, basis, multiplicity, n_active_electrons = N_e, n_active_orbitals = int(N_qubits/2))
H = of.linalg.get_sparse_operator(H).real

refstr = ''
for i in range(N_e, N_qubits):
    refstr += '0'
for i in range(0, N_e):
    refstr += '1'
ref = np.zeros(2**N_qubits)
ref[int(refstr,2)] = 1
ref = scipy.sparse.csc_matrix(ref).T

print("OpenFermion-PySCF HF Energy:")
print((ref.T@H@ref)[0,0])
print("OpenFermion-PySCF CASCI Energy:")
w, v = scipy.sparse.linalg.eigsh(H, which = "SA")
print(w[0])
exit()

Output:

PySCF HF Energy:
-3.1355322139663198
PYSCF CASCI:
-3.1981030445646623
OpenFermion-PySCF HF Energy:
-1.3744190019034384
OpenFermion-PySCF CASCI Energy:
-3.1614199163979224

run_pyscf does not work on PyscfMolecularData

Input:

from openfermionpyscf import PyscfMolecularData, run_pyscf

geometry = [('Li', (0., 0., 0.)), ('H', (0., 0., 1.4))]
basis = 'sto-3g'
multiplicity = 1
charge = 0

molecule = run_pyscf(
        PyscfMolecularData(geometry, basis, multiplicity, charge)
)

Output:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-bf13348427ff> in <module>()
      7 
      8 molecule = run_pyscf(
----> 9         PyscfMolecularData(geometry, basis, multiplicity, charge)
     10 )

~/Projects/OpenFermion-PySCF/openfermionpyscf/_run_pyscf.py in run_pyscf(molecule, run_scf, run_mp2, run_cisd, run_ccsd, run_fci, verbose)
    143 
    144     # Populate fields.
--> 145     molecule.canonical_orbitals = pyscf_scf.mo_coeff.astype(float)
    146     molecule.orbital_energies = pyscf_scf.mo_energy.astype(float)
    147 

AttributeError: can't set attribute

The reason is that PyscfMolecularData has canonical_orbitals, etc., as properties rather than attributes. One could fix this by adding setters, but I don't know what the correct design or intended usage is. If we can calculate stuff on the fly, then perhaps we don't even need to perform run_pyscf on a PyscfMolecularData? @sunqm

Permission denied: '08fd403b-e30d-4e78-97d5-dcb570445762.hdf5' -> '/usr/local/lib/python3.9/site-packages/openfermion/testing/data/H2_sto-3g_singlet_0.7414.hdf5'

The example generate_diatomic.py fails:

$ python3.9 generate_diatomic.py
Hartree-Fock energy for H2_sto-3g_singlet_0.7414 (2 electrons) is -1.1166843870853405.
MP2 energy for H2_sto-3g_singlet_0.7414 (2 electrons) is -1.1298551535553094.
CISD energy for H2_sto-3g_singlet_0.7414 (2 electrons) is -1.1372701746609026.
CCSD energy for H2_sto-3g_singlet_0.7414 (2 electrons) is -1.137270340640918.
FCI energy for H2_sto-3g_singlet_0.7414 (2 electrons) is -1.137270174660904.
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/shutil.py", line 825, in move
    os.rename(src, real_dst)
PermissionError: [Errno 13] Permission denied: '08fd403b-e30d-4e78-97d5-dcb570445762.hdf5' -> '/usr/local/lib/python3.9/site-packages/openfermion/testing/data/H2_sto-3g_singlet_0.7414.hdf5'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/disk-samsung/freebsd-ports/science/py-OpenFermion-PySCF/work-py39/OpenFermion-PySCF-0.5/examples/generate_diatomic.py", line 54, in <module>
    molecule = run_pyscf(molecule,
  File "/usr/local/lib/python3.9/site-packages/openfermionpyscf/_run_pyscf.py", line 205, in run_pyscf
    pyscf_molecular_data.save()
  File "/usr/local/lib/python3.9/site-packages/openfermion/chem/molecular_data.py", line 717, in save
    shutil.move("{}.hdf5".format(tmp_name), "{}.hdf5".format(self.filename))
  File "/usr/local/lib/python3.9/shutil.py", line 845, in move
    copy_function(src, real_dst)
  File "/usr/local/lib/python3.9/shutil.py", line 444, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/local/lib/python3.9/shutil.py", line 266, in copyfile
    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.9/site-packages/openfermion/testing/data/H2_sto-3g_singlet_0.7414.hdf5'

Version: 0.5
Python-3.9
FreeBSD 13.1

PyPI installation of PySCF unreliable

PySCF is not trivial to install on most systems. Most of the time I have found that installing via PyPI fails. Thus, if one has already managed to install PySCF they are in good shape but if they try to install OpenFermion-PySCF via PyPI without first making sure PySCF works, they might be in trouble since it is technically one of our requirements. I am not really sure what to do about this. Ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.