Skip to content

Commit 15db333

Browse files
Strilancbabbush
authored andcommitted
Configuring Travis (#32)
* Configuring Travis * other versions * Build bage * Both badges
1 parent 9fa1a11 commit 15db333

6 files changed

Lines changed: 109 additions & 73 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pip-log.txt
3939
pip-delete-this-directory.txt
4040

4141
# Unit test / coverage reports
42+
.pytest_cache/
4243
htmlcov/
4344
.tox/
4445
.coverage

.travis.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
sudo: false
2+
language: python
3+
matrix:
4+
include:
5+
- os: linux
6+
python: "2.7"
7+
addons:
8+
apt:
9+
sources: ['ubuntu-toolchain-r-test']
10+
packages: ['gcc-4.9', 'g++-4.9']
11+
env: CC=gcc-4.9 CXX=g++-4.9 PYTHON=2.7
12+
- os: linux
13+
python: "3.4"
14+
addons:
15+
apt:
16+
sources: ['ubuntu-toolchain-r-test']
17+
packages: ['gcc-4.9', 'g++-4.9']
18+
env: CC=gcc-4.9 CXX=g++-4.9 PYTHON=3.4
19+
- os: linux
20+
python: "3.5"
21+
addons:
22+
apt:
23+
sources: ['ubuntu-toolchain-r-test']
24+
packages: ['gcc-4.9', 'g++-4.9']
25+
env: CC=gcc-4.9 CXX=g++-4.9 PYTHON=3.5
26+
- os: linux
27+
python: "3.6"
28+
addons:
29+
apt:
30+
sources: ['ubuntu-toolchain-r-test']
31+
packages: ['gcc-4.9', 'g++-4.9']
32+
env: CC=gcc-4.9 CXX=g++-4.9 PYTHON=3.6
33+
34+
before_install:
35+
- pip install --upgrade pip setuptools wheel
36+
37+
install:
38+
- pip install -r requirements.txt
39+
- pip install .
40+
41+
script: pytest .

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ OpenFermion-PySCF
44
.. image:: https://badge.fury.io/py/openfermionpyscf.svg
55
:target: https://badge.fury.io/py/openfermionpyscf
66

7-
.. image:: https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5%2C%203.6-brightgreen.svg
7+
.. image:: https://travis-ci.org/quantumlib/OpenFermion-PySCF.svg?branch=master
8+
:target: https://travis-ci.org/quantumlib/OpenFermion-PySCF
89

910
`OpenFermion <http://openfermion.org>`__ is an open source library (licensed under Apache 2) for compiling and analyzing quantum algorithms which simulate fermionic systems.
1011
This plugin library allows the electronic structure package `PySCF <http://github.com/sunqm/pyscf>`__ (licensed under BSD-2-Clause) to interface with OpenFermion.

openfermionpyscf/tests/_pyscf_molecular_data_test.py

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,64 +14,61 @@
1414
from __future__ import absolute_import
1515

1616
import numpy
17-
import unittest
1817

1918
from openfermionpyscf import prepare_pyscf_molecule
2019
from openfermionpyscf import PyscfMolecularData
2120
from pyscf import scf, mp, ci, cc, fci
2221

2322

24-
class PyscfMolecularDataTest(unittest.TestCase):
23+
geometry = [('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))]
24+
basis = '6-31g'
25+
multiplicity = 1
26+
charge = 0
27+
molecule = PyscfMolecularData(geometry,
28+
basis,
29+
multiplicity,
30+
charge)
2531

26-
def setUp(self):
27-
geometry = [('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))]
28-
basis = '6-31g'
29-
multiplicity = 1
30-
charge = 0
31-
self.molecule = PyscfMolecularData(geometry,
32-
basis,
33-
multiplicity,
34-
charge)
32+
mol = prepare_pyscf_molecule(molecule)
33+
mol.verbose = 0
34+
molecule._pyscf_data['mol'] = mol
35+
molecule._pyscf_data['scf'] = mf = scf.RHF(mol).run()
36+
molecule._pyscf_data['mp2'] = mp.MP2(mf).run()
37+
molecule._pyscf_data['cisd'] = ci.CISD(mf).run()
38+
molecule._pyscf_data['ccsd'] = cc.CCSD(mf).run()
39+
molecule._pyscf_data['fci'] = fci.FCI(mf).run()
3540

36-
mol = prepare_pyscf_molecule(self.molecule)
37-
mol.verbose = 0
38-
self.molecule._pyscf_data['mol'] = mol
39-
self.molecule._pyscf_data['scf'] = mf = scf.RHF(mol).run()
40-
self.molecule._pyscf_data['mp2'] = mp.MP2(mf).run()
41-
self.molecule._pyscf_data['cisd'] = ci.CISD(mf).run()
42-
self.molecule._pyscf_data['ccsd'] = cc.CCSD(mf).run()
43-
self.molecule._pyscf_data['fci'] = fci.FCI(mf).run()
4441

45-
def test_accessing_rdm(self):
46-
molecule = self.molecule
47-
mo = molecule.canonical_orbitals
48-
overlap = molecule.overlap_integrals
49-
h1 = molecule.one_body_integrals
50-
h2 = molecule.two_body_integrals
51-
mf = molecule._pyscf_data['scf']
52-
e_core = mf.energy_nuc()
42+
def test_accessing_rdm():
43+
mo = molecule.canonical_orbitals
44+
overlap = molecule.overlap_integrals
45+
h1 = molecule.one_body_integrals
46+
h2 = molecule.two_body_integrals
47+
mf = molecule._pyscf_data['scf']
48+
e_core = mf.energy_nuc()
5349

54-
rdm1 = molecule.cisd_one_rdm
55-
rdm2 = molecule.cisd_two_rdm
56-
e_ref = molecule._pyscf_data['cisd'].e_tot
57-
e_tot = (numpy.einsum('pq,pq', h1, rdm1) +
58-
numpy.einsum('pqrs,pqrs', h2, rdm2) * .5 + e_core)
59-
self.assertAlmostEqual(e_tot, e_ref, 9)
50+
rdm1 = molecule.cisd_one_rdm
51+
rdm2 = molecule.cisd_two_rdm
52+
e_ref = molecule._pyscf_data['cisd'].e_tot
53+
e_tot = (numpy.einsum('pq,pq', h1, rdm1) +
54+
numpy.einsum('pqrs,pqrs', h2, rdm2) * .5 + e_core)
55+
numpy.testing.assert_almost_equal(e_tot, e_ref, 9)
6056

61-
rdm1 = molecule.ccsd_one_rdm
62-
rdm2 = molecule.ccsd_two_rdm
63-
e_ref = molecule._pyscf_data['ccsd'].e_tot
64-
e_tot = (numpy.einsum('pq,pq', h1, rdm1) +
65-
numpy.einsum('pqrs,pqrs', h2, rdm2) * .5 + e_core)
66-
self.assertAlmostEqual(e_tot, e_ref, 7)
57+
rdm1 = molecule.ccsd_one_rdm
58+
rdm2 = molecule.ccsd_two_rdm
59+
e_ref = molecule._pyscf_data['ccsd'].e_tot
60+
e_tot = (numpy.einsum('pq,pq', h1, rdm1) +
61+
numpy.einsum('pqrs,pqrs', h2, rdm2) * .5 + e_core)
62+
numpy.testing.assert_almost_equal(e_tot, e_ref, 7)
6763

68-
rdm1 = molecule.fci_one_rdm
69-
rdm2 = molecule.fci_two_rdm
70-
#e_ref = molecule._pyscf_data['fci'].e_tot
71-
e_tot = (numpy.einsum('pq,pq', h1, rdm1) +
72-
numpy.einsum('pqrs,pqrs', h2, rdm2) * .5 + e_core)
73-
self.assertAlmostEqual(e_tot, -1.1516827321, 9)
64+
rdm1 = molecule.fci_one_rdm
65+
rdm2 = molecule.fci_two_rdm
66+
#e_ref = molecule._pyscf_data['fci'].e_tot
67+
e_tot = (numpy.einsum('pq,pq', h1, rdm1) +
68+
numpy.einsum('pqrs,pqrs', h2, rdm2) * .5 + e_core)
69+
numpy.testing.assert_almost_equal(e_tot, -1.1516827321, 9)
70+
71+
ccsd_t1 = molecule.ccsd_single_amps
72+
ccsd_t2 = molecule.ccsd_double_amps
7473

75-
ccsd_t1 = molecule.ccsd_single_amps
76-
ccsd_t2 = molecule.ccsd_double_amps
7774

openfermionpyscf/tests/_run_pyscf_test.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,27 @@
1313
"""Tests many modules to call pyscf functions."""
1414
from __future__ import absolute_import
1515

16-
import numpy
17-
import unittest
18-
1916
from openfermion.hamiltonians import MolecularData
2017
from openfermionpyscf import run_pyscf
2118
from openfermionpyscf import PyscfMolecularData
2219

2320

24-
class RunPyscfTest(unittest.TestCase):
25-
26-
def setUp(self):
27-
geometry = [('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))]
28-
basis = '6-31g'
29-
multiplicity = 1
30-
charge = 0
31-
self.molecule = MolecularData(geometry,
32-
basis,
33-
multiplicity,
34-
charge)
35-
36-
def test_run_pyscf(self):
37-
new_mole = run_pyscf(self.molecule,
38-
run_scf=True,
39-
run_mp2=True,
40-
run_cisd=True,
41-
run_ccsd=True,
42-
run_fci=True,
43-
verbose=1)
44-
self.assertTrue(isinstance(new_mole, PyscfMolecularData))
45-
21+
geometry = [('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))]
22+
basis = '6-31g'
23+
multiplicity = 1
24+
charge = 0
25+
molecule = MolecularData(geometry,
26+
basis,
27+
multiplicity,
28+
charge)
29+
30+
31+
def test_run_pyscf():
32+
new_mole = run_pyscf(molecule,
33+
run_scf=True,
34+
run_mp2=True,
35+
run_cisd=True,
36+
run_ccsd=True,
37+
run_fci=True,
38+
verbose=1)
39+
assert isinstance(new_mole, PyscfMolecularData)

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
openfermion>=0.5
2+
pyscf
3+
pytest

0 commit comments

Comments
 (0)