Repository: quantumlib/OpenFermion
Pull request #589 (2020-04-22 09:50:33)

Issue #542: Implemented get_majorana_operator
Implemented get_majorana_operator(operator) and relative tests.
Some indent changes are due to linter.

googlebot: 
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: **Please visit <https://cla.developers.google.com/> to sign.**

Once you've signed (or fixed any issues), please reply here with `@googlebot I signed it!` and we'll verify it.

----

#### What to do if you already signed the CLA

##### Individual signers

*   It's possible we don't have your GitHub username or you're using a different email address on your commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).

##### Corporate signers

*   Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the Google project maintainer to [go/cla#troubleshoot](http://go/cla#troubleshoot) ([Public version](https://opensource.google/docs/cla/#troubleshoot)).
*   The email used to register you as an authorized contributor must be the email used for the Git commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).
*   The email used to register you as an authorized contributor must also be [attached to your GitHub account](https://github.com/settings/emails).
		

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Fquantumlib%2FOpenFermion%2Fpull%2F589) for more info**.

<!-- need_sender_cla -->
StefanoPolla: @googlebot I signed it!
googlebot: All (the pull request submitter and all commit authors) CLAs are signed, **but** one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project.  Please have them confirm that by leaving a comment that contains only `@googlebot I consent.` in this pull request.

*Note to project maintainer:* There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent.  In those cases, you can manually confirm consent of the commit author(s), and set the `cla` label to `yes` (if enabled on your project).

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Fquantumlib%2FOpenFermion%2Fpull%2F589) for more info**.

<!-- need_author_consent -->
StefanoPolla: @googlebot I consent.
xabomon: @googlebot I consent
googlebot: CLAs look good, thanks!

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Fquantumlib%2FOpenFermion%2Fpull%2F589) for more info**.

<!-- ok -->
xabomon: CI failed due to formatting.

In my last commit I used linter to format the code and it might have changed multiple lines that break something in CI. Feedback or comments welcome to solve this.

Best,
Xavi

ncrubin: @xabomon Go ahead and make the changes the CI linter suggests (https://travis-ci.org/github/quantumlib/OpenFermion/jobs/678090635).  You can run this linter by changing directory to the top-level-dir for openfermion and running ./check/pylint

Patch:
diff --git a/src/openfermion/transforms/__init__.py b/src/openfermion/transforms/__init__.py
index 3f290fd..e1f19ef 100644
--- a/src/openfermion/transforms/__init__.py
+++ b/src/openfermion/transforms/__init__.py
@@ -43,6 +43,7 @@ from ._conversion import (
     get_interaction_rdm,
     get_interaction_operator,
     get_quadratic_hamiltonian,
+    get_majorana_operator,
     get_molecular_data,
     get_number_preserving_sparse_operator,
     get_sparse_operator,
diff --git a/src/openfermion/transforms/_conversion.py b/src/openfermion/transforms/_conversion.py
index 47c46ec..22ee771 100644
--- a/src/openfermion/transforms/_conversion.py
+++ b/src/openfermion/transforms/_conversion.py
@@ -13,6 +13,7 @@
 """Transformations acting on operators and RDMs."""
 
 import itertools
+from typing import Union
 
 import numpy
 import scipy
@@ -432,6 +433,103 @@ def _majorana_term_to_fermion_operator(term):
     return converted_term
 
 
+def get_majorana_operator(
+        operator: Union[PolynomialTensor, DiagonalCoulombHamiltonian,
+                        FermionOperator]) -> MajoranaOperator:
+    """
+    Convert to MajoranaOperator.
+
+    Uses the convention of even + odd indexing of Majorana modes derived from
+    a fermionic mode:
+        fermion annhil.  c_k  -> ( gamma_{2k} + 1.j * gamma_{2k+1} ) / 2
+        fermion creation c^_k -> ( gamma_{2k} - 1.j * gamma_{2k+1} ) / 2
+
+    Args:
+        operator (PolynomialTensor,
+            DiagonalCoulombHamiltonian or
+            FermionOperator): Operator to write as Majorana Operator.
+
+    Returns:
+        majorana_operator: An instance of the MajoranaOperator class.
+
+    Raises:
+        TypeError: If operator is not of PolynomialTensor,
+            DiagonalCoulombHamiltonian or FermionOperator.
+    """
+    if isinstance(operator, FermionOperator):
+        return _fermion_operator_to_majorana_operator(operator)
+    elif isinstance(operator, (PolynomialTensor, DiagonalCoulombHamiltonian)):
+        return _fermion_operator_to_majorana_operator(
+            get_fermion_operator(operator))
+    raise TypeError('{} cannot be converted to MajoranaOperator'.format(
+        type(operator)))
+
+
+def _fermion_operator_to_majorana_operator(fermion_operator: FermionOperator
+                                          ) -> MajoranaOperator:
+    """
+    Convert FermionOperator to MajoranaOperator.
+
+    Auxiliar function of get_majorana_operator.
+
+    Args:
+        fermion_operator (FermionOperator): To convert to MajoranaOperator.
+
+    Returns:
+        majorana_operator object.
+
+    Raises:
+        TypeError: if input is not a FermionOperator.
+    """
+    if not isinstance(fermion_operator, FermionOperator):
+        raise TypeError('Input a FermionOperator.')
+
+    majorana_operator = MajoranaOperator()
+    for term, coeff in fermion_operator.terms.items():
+        converted_term = _fermion_term_to_majorana_operator(term)
+        converted_term *= coeff
+        majorana_operator += converted_term
+
+    return majorana_operator
+
+
+def _fermion_term_to_majorana_operator(term: tuple) -> MajoranaOperator:
+    """
+    Convert single terms of FermionOperator to Majorana.
+    (Auxiliary function of get_majorana_operator.)
+
+    Convention: even + odd indexing of Majorana modes derived from a
+    fermionic mode:
+        fermion annhil.  c_k  -> ( gamma_{2k} + 1.j * gamma_{2k+1} ) / 2
+        fermion creation c^_k -> ( gamma_{2k} - 1.j * gamma_{2k+1} ) / 2
+
+    Args:
+        term (tuple): single FermionOperator term.
+
+    Returns:
+        converted_term: single MajoranaOperator term.
+
+    Raises:
+        TypeError: if term is a tuple.
+    """
+    if not isinstance(term, tuple):
+        raise TypeError('Term does not have the correct Type.')
+
+    converted_term = MajoranaOperator(())
+    for index, action in term:
+        converted_op = MajoranaOperator((2 * index,), 0.5)
+
+        if action:
+            converted_op += MajoranaOperator((2 * index + 1,), -0.5j)
+
+        else:
+            converted_op += MajoranaOperator((2 * index + 1,), 0.5j)
+
+        converted_term *= converted_op
+
+    return converted_term
+
+
 def get_molecular_data(interaction_operator,
                        geometry=None, basis=None, multiplicity=None,
                        n_electrons=None, reduce_spin=True,
@@ -641,10 +739,8 @@ def get_number_preserving_sparse_operator(
             sparse_op += constant
 
         else:
-            term_op = _build_term_op_(term,
-                                        state_array,
-                                        int_state_array,
-                                        sorting_indices)
+            term_op = _build_term_op_(term, state_array, int_state_array,
+                                      sorting_indices)
 
             sparse_op += coefficient * term_op
 
@@ -693,7 +789,6 @@ def _iterate_basis_(reference_determinant, excitation_level, spin_preserving):
                     yield determinant
 
 
-
 def _iterate_basis_order_(reference_determinant, order):
     """A helper for iterating over determinants of a fixed excitation rank.
 
@@ -829,7 +924,6 @@ def _build_term_op_(term, state_array, int_state_array, sorting_indices):
         raise ValueError(
             "The supplied operator doesn't preserve particle number")
 
-
     # We search for every state which has the necessary orbitals occupied and
     # unoccupied in order to not be immediately zeroed out based on the
     # creation and annihilation operators specified in term.


Test patch:
diff --git a/src/openfermion/transforms/_conversion_test.py b/src/openfermion/transforms/_conversion_test.py
index 4877d02..dcef57d 100644
--- a/src/openfermion/transforms/_conversion_test.py
+++ b/src/openfermion/transforms/_conversion_test.py
@@ -36,21 +36,16 @@ from openfermion.utils import (is_hermitian,
 from openfermion.hamiltonians._molecular_data import MolecularData
 from openfermion.ops._interaction_operator import InteractionOperatorError
 from openfermion.ops._quadratic_hamiltonian import QuadraticHamiltonianError
-from openfermion.utils._testing_utils import (
-        random_hermitian_matrix,
-        random_quadratic_hamiltonian)
+from openfermion.utils._testing_utils import (random_hermitian_matrix,
+                                              random_quadratic_hamiltonian)
 from openfermion.config import THIS_DIRECTORY
 
 from openfermion.transforms._conversion import (
-        get_boson_operator,
-        get_diagonal_coulomb_hamiltonian,
-        get_fermion_operator,
-        get_interaction_operator,
-        get_quad_operator,
-        get_quadratic_hamiltonian,
-        get_sparse_operator,
-        get_number_preserving_sparse_operator,
-        _iterate_basis_)
+    get_boson_operator, get_diagonal_coulomb_hamiltonian, get_fermion_operator,
+    get_interaction_operator, get_majorana_operator,
+    _fermion_operator_to_majorana_operator, _fermion_term_to_majorana_operator,
+    get_quad_operator, get_quadratic_hamiltonian, get_sparse_operator,
+    get_number_preserving_sparse_operator, _iterate_basis_)
 
 
 class GetInteractionOperatorTest(unittest.TestCase):
@@ -174,13 +169,11 @@ class GetQuadraticHamiltonianTest(unittest.TestCase):
         ferm_op = (FermionOperator('0^ 2') + FermionOperator('2^ 0') +
                    FermionOperator('1^ 0^ 2') + FermionOperator('1^ 0^ 2 1') +
                    FermionOperator('0^ 0 1^ 1') + FermionOperator('1^ 2^ 1 2'))
-        converted_op = get_quadratic_hamiltonian(
-                ferm_op,
-                ignore_incompatible_terms=True)
-        self.assertTrue(numpy.allclose(converted_op.hermitian_part,
-                        numpy.array([[0, 0, 1],
-                                     [0, 0, 0],
-                                     [1, 0, 0]])))
+        converted_op = get_quadratic_hamiltonian(ferm_op,
+                                                 ignore_incompatible_terms=True)
+        self.assertTrue(
+            numpy.allclose(converted_op.hermitian_part,
+                           numpy.array([[0, 0, 1], [0, 0, 0], [1, 0, 0]])))
 
 
 class GetDiagonalCoulombHamiltonianTest(unittest.TestCase):
@@ -199,20 +192,18 @@ class GetDiagonalCoulombHamiltonianTest(unittest.TestCase):
                                       periodic)
 
         self.assertTrue(
-                normal_ordered(hubbard_model) ==
-                normal_ordered(
-                    get_fermion_operator(
-                        get_diagonal_coulomb_hamiltonian(hubbard_model))))
+            normal_ordered(hubbard_model) == normal_ordered(
+                get_fermion_operator(
+                    get_diagonal_coulomb_hamiltonian(hubbard_model))))
 
     def test_random_quadratic(self):
         n_qubits = 5
         quad_ham = random_quadratic_hamiltonian(n_qubits, True)
         ferm_op = get_fermion_operator(quad_ham)
         self.assertTrue(
-                normal_ordered(ferm_op) ==
-                normal_ordered(
-                    get_fermion_operator(
-                        get_diagonal_coulomb_hamiltonian(ferm_op))))
+            normal_ordered(ferm_op) == normal_ordered(
+                get_fermion_operator(get_diagonal_coulomb_hamiltonian(
+                    ferm_op))))
 
     def test_ignore_incompatible_terms(self):
 
@@ -220,16 +211,14 @@ class GetDiagonalCoulombHamiltonianTest(unittest.TestCase):
                    FermionOperator('1^ 0^ 2') + FermionOperator('1^ 0^ 2 1') +
                    FermionOperator('0^ 0 1^ 1') + FermionOperator('1^ 2^ 1 2'))
         converted_op = get_diagonal_coulomb_hamiltonian(
-                ferm_op,
-                ignore_incompatible_terms=True)
-        self.assertTrue(numpy.allclose(converted_op.one_body,
-                        numpy.array([[0, 0, 1],
-                                     [0, 0, 0],
-                                     [1, 0, 0]])))
-        self.assertTrue(numpy.allclose(converted_op.two_body,
-                        numpy.array([[0, 0.5, 0],
-                                     [0.5, 0, -0.5],
-                                     [0, -0.5, 0]])))
+            ferm_op, ignore_incompatible_terms=True)
+        self.assertTrue(
+            numpy.allclose(converted_op.one_body,
+                           numpy.array([[0, 0, 1], [0, 0, 0], [1, 0, 0]])))
+        self.assertTrue(
+            numpy.allclose(
+                converted_op.two_body,
+                numpy.array([[0, 0.5, 0], [0.5, 0, -0.5], [0, -0.5, 0]])))
 
     def test_exceptions(self):
         op1 = QubitOperator()
@@ -518,6 +507,46 @@ def test_get_fermion_operator_wrong_type():
         _ = get_fermion_operator(QubitOperator())
 
 
+class GetMajoranaOperatorTest(unittest.TestCase):
+    """Test class get Majorana Operator."""
+
+    def test_raises(self):
+        """Test raises errors."""
+        with self.assertRaises(TypeError):
+            get_majorana_operator(1.0)
+        with self.assertRaises(TypeError):
+            _fermion_operator_to_majorana_operator([1.0])
+        with self.assertRaises(TypeError):
+            _fermion_term_to_majorana_operator(1.0)
+
+    def test_get_majorana_operator_fermion_operator(self):
+        """Test conversion FermionOperator to MajoranaOperator."""
+        fermion_op = (-2j * (FermionOperator(
+            ((0, 0), (1, 0))) - FermionOperator(
+                ((0, 0), (1, 1))) + FermionOperator(
+                    ((0, 1), (1, 0))) - FermionOperator(
+                        ((0, 1), (1, 1)))) - 2 * FermionOperator(
+                            ((0, 0), (1, 1), (1, 0))) + 2 * FermionOperator(
+                                ((0, 1), (1, 1), (1, 0))) + FermionOperator(
+                                    (0, 0)) - FermionOperator((0, 1)))
+
+        majorana_op = get_majorana_operator(fermion_op)
+        expected_op = (MajoranaOperator((0, 3), 2.0) + MajoranaOperator(
+            (1, 2, 3)))
+        self.assertTrue(majorana_op == expected_op)
+
+    def test_get_majorana_operator_diagonalcoulomb(self):
+        """Test get majorana from Diagonal Coulomb."""
+        fermion_op = (FermionOperator('0^ 1', 1.0) +
+                      FermionOperator('1^ 0', 1.0))
+
+        diagonal_ham = get_diagonal_coulomb_hamiltonian(fermion_op)
+
+        self.assertTrue(
+            get_majorana_operator(diagonal_ham) == get_majorana_operator(
+                fermion_op))
+
+
 class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
 
     def setUp(self):
@@ -540,7 +569,6 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
             magnetic_field=0.0,
             spinless=False)
 
-
     def test_number_on_reference(self):
         sum_n_op = FermionOperator()
         sum_sparse_n_op = get_number_preserving_sparse_operator(
@@ -584,7 +612,6 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
         assert reference.dot(sum_sparse_n_op.dot(reference)) - \
             self.molecule.n_electrons < 1E-9
 
-
     def test_space_size_correct(self):
         hamiltonian_fop = get_fermion_operator(self.molecular_hamiltonian)
 
@@ -599,7 +626,6 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
         # Naive Hilbert space size is 2**12, or 4096.
         assert space_size == 225
 
-
     def test_hf_energy(self):
         hamiltonian_fop = get_fermion_operator(self.molecular_hamiltonian)
 
@@ -618,7 +644,6 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
         assert numpy.linalg.norm(sparse_hf_energy -
                                  self.molecule.hf_energy) < 1E-9
 
-
     def test_one_body_hf_energy(self):
         one_body_part = self.molecular_hamiltonian
         one_body_part.two_body_tensor = numpy.zeros_like(
@@ -652,7 +677,6 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
         assert numpy.linalg.norm(sparse_hf_energy -
                                  regular_sparse_hf_energy) < 1E-9
 
-
     def test_ground_state_energy(self):
         hamiltonian_fop = get_fermion_operator(self.molecular_hamiltonian)
 
@@ -666,7 +690,6 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
 
         assert numpy.abs(eig_val[0] - self.molecule.fci_energy) < 1E-9
 
-
     def test_doubles_are_subset(self):
         reference_determinants = [
             [True, True, True, True, False, False,
@@ -678,16 +701,18 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
         for reference_determinant in reference_determinants:
             reference_determinant = numpy.asarray(reference_determinant)
             doubles_state_array = numpy.asarray(
-                list(_iterate_basis_(reference_determinant,
-                                       excitation_level=2,
-                                       spin_preserving=True)))
+                list(
+                    _iterate_basis_(reference_determinant,
+                                    excitation_level=2,
+                                    spin_preserving=True)))
             doubles_int_state_array = doubles_state_array.dot(
                 1 << numpy.arange(doubles_state_array.shape[1])[::-1])
 
             all_state_array = numpy.asarray(
-                list(_iterate_basis_(reference_determinant,
-                                       excitation_level=4,
-                                       spin_preserving=True)))
+                list(
+                    _iterate_basis_(reference_determinant,
+                                    excitation_level=4,
+                                    spin_preserving=True)))
             all_int_state_array = all_state_array.dot(
                 1 << numpy.arange(all_state_array.shape[1])[::-1])
 
@@ -697,16 +722,18 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
         for reference_determinant in reference_determinants:
             reference_determinant = numpy.asarray(reference_determinant)
             doubles_state_array = numpy.asarray(
-                list(_iterate_basis_(reference_determinant,
-                                       excitation_level=2,
-                                       spin_preserving=True)))
+                list(
+                    _iterate_basis_(reference_determinant,
+                                    excitation_level=2,
+                                    spin_preserving=True)))
             doubles_int_state_array = doubles_state_array.dot(
                 1 << numpy.arange(doubles_state_array.shape[1])[::-1])
 
             all_state_array = numpy.asarray(
-                list(_iterate_basis_(reference_determinant,
-                                       excitation_level=4,
-                                       spin_preserving=False)))
+                list(
+                    _iterate_basis_(reference_determinant,
+                                    excitation_level=4,
+                                    spin_preserving=False)))
             all_int_state_array = all_state_array.dot(
                 1 << numpy.arange(all_state_array.shape[1])[::-1])
 
@@ -716,47 +743,46 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
         for reference_determinant in reference_determinants:
             reference_determinant = numpy.asarray(reference_determinant)
             doubles_state_array = numpy.asarray(
-                list(_iterate_basis_(reference_determinant,
-                                       excitation_level=2,
-                                       spin_preserving=False)))
+                list(
+                    _iterate_basis_(reference_determinant,
+                                    excitation_level=2,
+                                    spin_preserving=False)))
             doubles_int_state_array = doubles_state_array.dot(
                 1 << numpy.arange(doubles_state_array.shape[1])[::-1])
 
             all_state_array = numpy.asarray(
-                list(_iterate_basis_(reference_determinant,
-                                       excitation_level=4,
-                                       spin_preserving=False)))
+                list(
+                    _iterate_basis_(reference_determinant,
+                                    excitation_level=4,
+                                    spin_preserving=False)))
             all_int_state_array = all_state_array.dot(
                 1 << numpy.arange(all_state_array.shape[1])[::-1])
 
             for item in doubles_int_state_array:
                 assert item in all_int_state_array
 
-
     def test_full_ham_hermitian(self):
         hamiltonian_fop = get_fermion_operator(self.molecular_hamiltonian)
 
         sparse_ham = get_number_preserving_sparse_operator(
             hamiltonian_fop,
-           self.molecule.n_qubits,
-           self.molecule.n_electrons,
+            self.molecule.n_qubits,
+            self.molecule.n_electrons,
             spin_preserving=True)
 
         assert scipy.sparse.linalg.norm(sparse_ham - sparse_ham.getH()) < 1E-9
 
-
     def test_full_ham_hermitian_non_spin_preserving(self):
         hamiltonian_fop = get_fermion_operator(self.molecular_hamiltonian)
 
         sparse_ham = get_number_preserving_sparse_operator(
             hamiltonian_fop,
-           self.molecule.n_qubits,
-           self.molecule.n_electrons,
+            self.molecule.n_qubits,
+            self.molecule.n_electrons,
             spin_preserving=False)
 
         assert scipy.sparse.linalg.norm(sparse_ham - sparse_ham.getH()) < 1E-9
 
-
     def test_singles_simple_one_body_term_hermitian(self):
         fop = FermionOperator(((3, 1), (1, 0)))
         fop_conj = FermionOperator(((1, 1), (3, 0)))
@@ -778,7 +804,6 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
         assert scipy.sparse.linalg.norm(sparse_op -
                                         sparse_op_conj.getH()) < 1E-9
 
-
     def test_singles_simple_two_body_term_hermitian(self):
         fop = FermionOperator(((3, 1), (8, 1), (1, 0), (4, 0)))
         fop_conj = FermionOperator(((4, 1), (1, 1), (8, 0), (3, 0)))
@@ -800,7 +825,6 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
         assert scipy.sparse.linalg.norm(sparse_op -
                                         sparse_op_conj.getH()) < 1E-9
 
-
     def test_singles_repeating_two_body_term_hermitian(self):
         fop = FermionOperator(((3, 1), (1, 1), (5, 0), (1, 0)))
         fop_conj = FermionOperator(((5, 1), (1, 1), (3, 0), (1, 0)))
@@ -822,7 +846,6 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
         assert scipy.sparse.linalg.norm(sparse_op -
                                         sparse_op_conj.getH()) < 1E-9
 
-
     def test_singles_ham_hermitian(self):
         hamiltonian_fop = get_fermion_operator(self.molecular_hamiltonian)
 
@@ -835,7 +858,6 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
 
         assert scipy.sparse.linalg.norm(sparse_ham - sparse_ham.getH()) < 1E-9
 
-
     def test_singles_ham_hermitian_non_spin_preserving(self):
         hamiltonian_fop = get_fermion_operator(self.molecular_hamiltonian)
 
@@ -848,7 +870,6 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
 
         assert scipy.sparse.linalg.norm(sparse_ham - sparse_ham.getH()) < 1E-9
 
-
     def test_cisd_energy(self):
         hamiltonian_fop = get_fermion_operator(self.molecular_hamiltonian)
 
@@ -863,7 +884,6 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
 
         assert numpy.abs(eig_val[0] - self.molecule.cisd_energy) < 1E-9
 
-
     def test_cisd_energy_non_spin_preserving(self):
         hamiltonian_fop = get_fermion_operator(self.molecular_hamiltonian)
 
@@ -910,7 +930,7 @@ class GetNumberPreservingSparseOperatorIntegrationTestLiH(unittest.TestCase):
             2,
             spin_preserving=True,
             excitation_level=2,
-            reference_determinant = numpy.asarray(
+            reference_determinant=numpy.asarray(
                 [False, False, True, True, False, False, False, False]))
 
         sparse_ham_fci = get_sparse_operator(