Skip to content

Commit

Permalink
Bring qchem inside pennylane (#2420)
Browse files Browse the repository at this point in the history
  • Loading branch information
soranjh committed Apr 13, 2022
1 parent cbbf946 commit afc9adc
Show file tree
Hide file tree
Showing 89 changed files with 169 additions and 1,245 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
with:
docs-folder: "doc/"
repo-token: "${{ secrets.GITHUB_TOKEN }}"
pre-build-command: "apt install -y graphviz && pip3 install -r doc/requirements.txt && pip3 install . && pip3 install -r qchem/requirements.txt && pip3 install ./qchem"
pre-build-command: "apt install -y graphviz && pip3 install -r doc/requirements.txt && pip3 install . pip3 install openfermionpyscf"
build-command: "sphinx-build -b html . _build -W --keep-going"
1 change: 0 additions & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ jobs:
run: |
black -l 100 pennylane/ --check
black -l 100 tests/ --check
black -l 100 qchem/ --check
57 changes: 6 additions & 51 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- {python-version: 3.9, interfaces: []}
- {python-version: '3.10', interfaces: []}


steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.4.1
Expand All @@ -46,6 +47,10 @@ jobs:
pip install -r requirements-ci.txt
pip install wheel pytest pytest-cov pytest-mock flaky --upgrade
- name: Conditionally install openfermionpyscf
if: contains(' 3.9', matrix.config.python-version)
run: pip3 install openfermionpyscf

- name: Conditionally install PyTorch
if: contains(matrix.config.interfaces, 'torch')
run: pip3 install torch==$TORCH_VERSION -f https://download.pytorch.org/whl/torch_stable.html
Expand Down Expand Up @@ -148,54 +153,4 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml


qchem-tests:
runs-on: ubuntu-latest

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.4.1
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Setup conda
uses: s-weigand/setup-conda@v1
with:
activate-conda: true
python-version: 3.7
conda-channels: anaconda, conda-forge

- name: Install dependencies
run: |
conda install psi4 psi4-rt python=3.7 -c psi4
pip uninstall h5py -y
pip install pytest pytest-cov pytest-mock flaky h5py==3.2.1
- name: Install QChem
run: |
pip install -r requirements-ci.txt
python setup.py bdist_wheel
pip install dist/PennyLane*.whl
cd qchem && python setup.py bdist_wheel && cd ../
pip install qchem/dist/PennyLane_Qchem*.whl
- name: Run tests
run: |
python -m pytest tests/hf --cov=pennylane $COVERAGE_FLAGS
cd qchem && python -m pytest tests --cov=pennylane_qchem $COVERAGE_FLAGS
- name: Upload HF coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./qchem/coverage.xml
file: ./coverage.xml
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ doc/code/api/*
!doc/_static/code.png
*.DS_Store
/.vscode/*
pennylane_qchem/build/*
pennylane_qchem/dist/*
pennylane_qchem/.pytest_cache/*
qchem/tmp/*
qchem/timer.dat
qchem/tests/tmp/*
qchem/tests/qchem_tests/tmp/*
qchem/tests/tmp/timer.dat
timer.dat
tmp/*
benchmark/revisions/
Expand Down
3 changes: 0 additions & 3 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ python:
version: 3.8
install:
- requirements: doc/requirements.txt
- requirements: qchem/requirements.txt
- method: pip
path: .
- method: pip
path: qchem

build:
image: latest
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ clean:
rm -rf .coverage coverage_html_report/
rm -rf tmp
rm -rf *.dat
make -C qchem clean

docs:
make -C doc html
Expand Down
7 changes: 2 additions & 5 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
fixes:
- "pennylane_qchem/::qchem/pennylane_qchem/"

ignore:
- "pennylane/devices/tests/*"

codecov:
notify:
after_n_builds: 10
after_n_builds: 9

comment:
after_n_builds: 10
after_n_builds: 9
11 changes: 1 addition & 10 deletions doc/code/qml_qchem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,9 @@ qml.qchem

The PennyLane quantum chemistry library.

.. note::

To access the ``qml.qchem`` package, ``pennylane-qchem`` must be installed
via pip:

.. code-block:: bash
pip install pennylane-qchem
.. currentmodule:: pennylane.qchem

.. automodapi:: pennylane_qchem.qchem
.. automodapi:: pennylane.qchem
:no-heading:
:include-all-objects:
:no-inheritance-diagram:
25 changes: 0 additions & 25 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,6 @@

import pennylane

try:
import pennylane_qchem
except ImportError:
from unittest.mock import MagicMock

class Mock(MagicMock):
__name__ = 'foo'
__repr__ = lambda self: __name__

@classmethod
def __getattr__(cls, name):
return MagicMock()

MOCK_MODULES = [
'pennylane_qchem',
'pennylane_qchem.qchem',
]

mock_fn = Mock(__name__='foo')
mock_fns = {"__all__": list(), "__dir__": list(), "__dict__": dict()}

mock = Mock(**mock_fns)
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = mock

# The full version, including alpha/beta/rc tags.
release = pennylane.__version__

Expand Down
3 changes: 1 addition & 2 deletions doc/development/guide/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,7 @@ the following additional packages are required:
In addition, some pages in the documentation have additional dependencies:

* The latest version of PyTorch and TensorFlow are required to build the interface documentation,
* The latest version of TensorNetwork is required to build the ``default.tensor`` documentation, and
* PennyLane-QChem must be installed to build the quantum chemistry documentation.
* The latest version of TensorNetwork is required to build the ``default.tensor`` documentation.

These can all be installed via ``pip``:

Expand Down
28 changes: 0 additions & 28 deletions doc/development/guide/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ using development mode:
cd pennylane
pip install -e .
If also developing for the QChem package, this will need to installed as well:

.. code-block:: bash
pip install -e qchem
The ``-e`` flag ensures that edits to the source code will be reflected when
importing PennyLane in Python.

Expand Down Expand Up @@ -155,25 +149,3 @@ Build a PennyLane image with a plugin
.. code-block:: bash
make -f docker/Makefile build-plugin plugin-name=qiskit
Build a PennyLane-Qchem image
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- You can also build an image with the PennyLane Qchem package and its
dependencies. Use the following commands:

.. code-block:: bash
make -f docker/Makefile build-qchem
- To check all available interfaces, run the following:

.. code-block:: bash
make -f docker/Makefile available-interfaces
- To check all available plugins, run the following:

.. code-block:: bash
make -f docker/Makefile available-plugins
27 changes: 11 additions & 16 deletions doc/introduction/chemistry.rst
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
Quantum Chemistry
=================

PennyLane provides a differentiable Hartree-Fock solver module :mod:`~.hf` and a quantum chemistry
module :mod:`~.qchem` to perform quantum simulations of the electronic structure of molecules. These
modules contain tools to construct the electronic Hamiltonian of molecules that can be used to
implement the Variational Quantum Eigensolver (VQE) algorithm.
PennyLane provides a differentiable Hartree-Fock solver module :mod:`~.qchem` to perform quantum
simulations of the electronic structure of molecules. This module contain tools to construct the
electronic Hamiltonian of molecules that can be used to implement the Variational Quantum
Eigensolver (VQE) algorithm.

.. figure:: ../_static/sketch_pennylane_qchem.png
:width: 80%
:align: center

.. note::

To access the ``qchem`` module, the ``PennyLane-QChem`` plugin must be installed separately:

.. code-block::
pip install pennylane-qchem
Building the electronic Hamiltonian
-----------------------------------

Expand Down Expand Up @@ -49,7 +41,7 @@ where:
Internally, :func:`~.molecular_hamiltonian` calls the following functions in order
to generate the qubit Hamiltonian:

.. currentmodule:: pennylane_qchem.qchem
.. currentmodule:: pennylane.qchem

.. autosummary::

Expand Down Expand Up @@ -88,7 +80,8 @@ using the electronic structure packages `PySCF <https://github.com/sunqm/pyscf>`
<http://psicode.org/>`_, respectively.

For this, it is required to specify a string to label the molecule. Furthermore, the net charge,
the `spin multiplicity <https://en.wikipedia.org/wiki/Multiplicity_(chemistry)>`_ and the `atomic basis functions <https://www.basissetexchange.org/>`_ can also be specified.
the `spin multiplicity <https://en.wikipedia.org/wiki/Multiplicity_(chemistry)>`_ and the
`atomic basis functions <https://www.basissetexchange.org/>`_ can also be specified.

.. code-block:: python
Expand All @@ -111,7 +104,8 @@ Mapping the Hamiltonian to the Pauli basis

The function :func:`~.active_space` is used to create an `active space <https://en.wikipedia
.org/wiki/Complete_active_space>`__ by classifying the Hartree-Fock molecular orbitals as
core, active, and external orbitals. Within this approximation, a certain number of *active electrons* can populate the *active orbitals*.
core, active, and external orbitals. Within this approximation, a certain number of
*active electrons* can populate the *active orbitals*.

.. code-block:: python
Expand Down Expand Up @@ -140,7 +134,8 @@ and map it to a linear combination of Pauli operators via the `Jordan-Wigner
active=active
)
Here, ``qubit_hamiltonian`` is an instance of the QubitOperator class of `OpenFermion <https://github.com/quantumlib/OpenFermion>`_.
Here, ``qubit_hamiltonian`` is an instance of the QubitOperator class of
`OpenFermion <https://github.com/quantumlib/OpenFermion>`_.

.. _pl_qchem_vqe:

Expand Down
2 changes: 2 additions & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ toml
torch==1.9.0+cpu
torchvision==0.10.0+cpu
jinja2==3.0.3
retworkx==0.10.2
networkx==2.6
5 changes: 0 additions & 5 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
help:
@echo "Makefile commands:"
@echo "build-base"
@echo "build-qchem"
@echo "build-interface"
@echo "build-interface-gpu"

Expand All @@ -20,10 +19,6 @@ available-plugins:
build-base:
@docker build -t pennylane/base -f docker/pennylane.dockerfile .

build-qchem:
@docker build -t pennylane/base -f docker/pennylane.dockerfile . \
&& docker build -t pennylane/qchem -f docker/qchem.dockerfile .

build-interface:
@docker build -t pennylane/base -f docker/pennylane.dockerfile . \
&& docker build -t pennylane/$(interface-name) -f docker/interfaces/build_interface.dockerfile \
Expand Down
1 change: 1 addition & 0 deletions docker/pennylane.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ RUN git submodule update --init --recursive \
&& python3 setup.py install \
&& pip install pytest pytest-cov pytest-mock flaky \
&& pip install -i https://test.pypi.org/simple/ pennylane-lightning --pre --upgrade \
&& pip install openfermionpyscf \
&& make test && make coverage

# create Second small build.
Expand Down
31 changes: 0 additions & 31 deletions docker/qchem.dockerfile

This file was deleted.

Loading

0 comments on commit afc9adc

Please sign in to comment.