Skip to content

Commit

Permalink
fixed sparse efficiency warning (#13)
Browse files Browse the repository at this point in the history
* fixed sparse efficiency warning

* slightly upped test coverage
  • Loading branch information
babbush committed Oct 3, 2017
1 parent a2b4acf commit 5e1052d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ To start using OpenFermion, clone this git repo, change directory to the top lev
python -m pip install -e .
Alternatively, one can install using pip with the command
Alternatively, one can install the last major release using pip with the command

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ Further examples can be found in the docs (`Examples` in the panel on the left)
Plugins
-------

In order to generate molecular hamiltonians in Gaussian basis sets and perform other complicated electronic structure calculations, one can install plugins. We currently support Psi4 (plugin `here <www.openfermion.org>`__, recommended) and PySCF (plugin `here <www.openfermion.org>`__).
In order to simulate and compile quantum circuits or perform other complicated electronic structure calculations, one can install OpenFermion plugins. We currently support a circuit simulation plugin for `ProjectQ <https://projectq.ch>`__, which you can find at `OpenFermion-ProjectQ <http://github.com/quantumlib/OpenFermion-ProjectQ>`__. We also support electronic structure plugins for `Psi4 <http://psicode.org>`__, which you can find at `OpenFermion-Psi4 <http://github.com/quantumlib/OpenFermion-Psi4>`__ (recommended), and for `PySCF <https://github.com/sunqm/pyscf>`__, which you can find at `OpenFermion-PySCF <http://github.com/quantumlib/OpenFermion-PySCF>`__.
20 changes: 20 additions & 0 deletions src/openfermion/ops/_interaction_tensor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,26 @@ def test_iter_and_str(self):
self.assertEqual(interaction_tensor.__str__(), want_str)
self.assertEqual(interaction_tensor.__repr__(), want_str)

def test_init_none(self):
n_qubits = 2
constant = 23.0

one_body = numpy.zeros((self.n_qubits, self.n_qubits))
two_body = numpy.zeros((self.n_qubits, self.n_qubits,
self.n_qubits, self.n_qubits))
one_body[0, 1] = 2
one_body[1, 0] = 3
two_body[0, 1, 0, 1] = 4
two_body[1, 1, 0, 0] = 5
interaction_tensor = InteractionTensor(None,
one_body, two_body)
self.assertAlmostEqual(interaction_tensor.constant, 0.)

self.interaction_tensor_a[()] = 0.
self.assertAlmostEqual(self.interaction_tensor_a, interaction_tensor)
self.interaction_tensor_a[()] = self.constant


def test_rotate_basis_identical(self):
rotation_matrix_identical = numpy.zeros((self.n_qubits, self.n_qubits))
rotation_matrix_identical[0, 0] = 1
Expand Down
4 changes: 4 additions & 0 deletions src/openfermion/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@
sparse_eigenspectrum)

from ._trotter_error import error_bound, error_operator

# Imports out of alphabetical order to avoid circular dependancy.
from ._jellium_hf_state import hartree_fock_state_jellium

8 changes: 4 additions & 4 deletions src/openfermion/utils/_jellium_hf_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from openfermion.utils import (count_qubits, jellium_model,
inverse_fourier_transform, plane_wave_kinetic)

from scipy.sparse import csr_matrix
from scipy.sparse import csr_matrix, dok_matrix

import numpy

Expand Down Expand Up @@ -94,15 +94,15 @@ def hartree_fock_state_jellium(grid, n_electrons, spinless=True,
dual_basis_hf_creation_operator)

# Initialize the HF state as a sparse matrix.
hartree_fock_state = csr_matrix(
([], ([], [])), shape=(2 ** count_qubits(hamiltonian), 1),
dtype=complex)
hartree_fock_state = dok_matrix(
(2 ** count_qubits(hamiltonian), 1), dtype=complex)

# Populate the elements of the HF state in the dual basis.
for term in dual_basis_hf_creation.terms:
index = 0
for operator in term:
index += 2 ** operator[0]
hartree_fock_state[index, 0] = dual_basis_hf_creation.terms[term]
hartree_fock_state = hartree_fock_state.tocsr()

return hartree_fock_state
8 changes: 3 additions & 5 deletions src/openfermion/utils/_jellium_hf_state_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

from openfermion.transforms import get_sparse_operator
from openfermion.utils import (expectation, get_ground_state,
Grid, jellium_model)
from openfermion.utils._plane_wave_hamiltonian import wigner_seitz_length_scale
from openfermion.utils._sparse_tools import jw_number_restrict_operator

from openfermion.utils._jellium_hf_state import hartree_fock_state_jellium
Grid, hartree_fock_state_jellium,
jellium_model, jw_number_restrict_operator,
wigner_seitz_length_scale)


class JelliumHartreeFockStateTest(unittest.TestCase):
Expand Down

0 comments on commit 5e1052d

Please sign in to comment.