From 64d6e94a0d2400ccef567bf8151e5c993bf046e5 Mon Sep 17 00:00:00 2001 From: soranjh Date: Thu, 2 Jun 2022 15:19:19 -0400 Subject: [PATCH 01/17] add 1-norm function --- pennylane/resources/double_factorization.py | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 pennylane/resources/double_factorization.py diff --git a/pennylane/resources/double_factorization.py b/pennylane/resources/double_factorization.py new file mode 100644 index 00000000000..08f7dbe3630 --- /dev/null +++ b/pennylane/resources/double_factorization.py @@ -0,0 +1,56 @@ +# Copyright 2018-2022 Xanadu Quantum Technologies Inc. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +This module contains the functions needed for resource estimation with double factorization method. +""" + +from pennylane import numpy as np + + +def norm(one, two, eigvals): + r"""Return the 1-norm of a molecular Hamiltonian from the one- and two-electron and factorized + two-electron integrals. + + Args: + one (array[array[float]]): one-electron integrals + two (array[array[float]]): two-electron integrals + eigvals (array[float]): eigenvalues of the matrices obtained from factorizing the + two-electron integral tensor + + + Returns: + array[float]: 1-norm of the Hamiltonian + + **Example** + + >>> symbols = ['H', 'H', 'O'] + >>> geometry = np.array([[0.0, 0.000000000, 0.150166845], + >>> [0.0, 0.768778665, -0.532681406], + >>> [0.0, -0.768778665, -0.532681406]], requires_grad = False) / 0.529177 + >>> mol = qml.qchem.Molecule(symbols, geometry, basis_name='sto-3g') + >>> core, one, two = qml.qchem.electron_integrals(mol)() + >>> two = np.swapaxes(two, 1, 3) # convert to the chemists notation + >>> l, w, v = factorize(two, 1e-5) + >>> print(norm(one, two, w)) + 52.98762043980203 + """ + lambda_one = 0.25 * np.sum([np.sum(abs(val)) ** 2 for val in eigvals]) + + l_inv = one - 0.5 * np.einsum('illj', two) + np.einsum('llij', two) + + val, vec = np.linalg.eigh(l_inv) + + lambda_two = np.sum(abs(val)) + + return lambda_one + lambda_two From c8339369ee7c20a406eeacd0c0aacad1467f7d80 Mon Sep 17 00:00:00 2001 From: soranjh Date: Thu, 2 Jun 2022 15:52:11 -0400 Subject: [PATCH 02/17] add docstring to norm --- pennylane/resources/double_factorization.py | 35 ++++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/pennylane/resources/double_factorization.py b/pennylane/resources/double_factorization.py index 08f7dbe3630..2b2314ca990 100644 --- a/pennylane/resources/double_factorization.py +++ b/pennylane/resources/double_factorization.py @@ -19,8 +19,34 @@ def norm(one, two, eigvals): - r"""Return the 1-norm of a molecular Hamiltonian from the one- and two-electron and factorized - two-electron integrals. + r"""Return the 1-norm of a molecular Hamiltonian from the one- and two-electron integrals and + eigenvalues of the factorized two-electron integral tensor. + + The 1-norm of a double-factorized molecular Hamiltonian is computed as + [`arXiv:2007.14460 `_] + + .. math:: + + \lambda = ||T|| + \frac{1}{4} \sum_r ||L^{(r)}||^2, + + where the Schatten norm, :math:`||L||`, is defined as + + .. math:: + + ||L|| = \sum_k |\text{eigvals}[L]_k|. + + The matrices :math:`L^{(r)}` are obtained from a rank-r factorizing the two-electron integral + tensor :math:`h`, arranged in the chemist notation, such that + + .. math:: + + h_{ijkl} = \sum_r L_{ij}^{(r)} L_{kl}^{(r) T}. + + The matrix :math:`T` is constructed from the one-and two electron integrals as + + .. math:: + + T = h_{ij} - \frac{1}{2} \sum_l h_{illj} + \sum_l h_{llij}. Args: one (array[array[float]]): one-electron integrals @@ -28,7 +54,6 @@ def norm(one, two, eigvals): eigvals (array[float]): eigenvalues of the matrices obtained from factorizing the two-electron integral tensor - Returns: array[float]: 1-norm of the Hamiltonian @@ -47,9 +72,9 @@ def norm(one, two, eigvals): """ lambda_one = 0.25 * np.sum([np.sum(abs(val)) ** 2 for val in eigvals]) - l_inv = one - 0.5 * np.einsum('illj', two) + np.einsum('llij', two) + t_mat = one - 0.5 * np.einsum('illj', two) + np.einsum('llij', two) - val, vec = np.linalg.eigh(l_inv) + val, vec = np.linalg.eigh(t_mat) lambda_two = np.sum(abs(val)) From 8c8126461124d0aa7843fe90fb1103f077088c0c Mon Sep 17 00:00:00 2001 From: soranjh Date: Thu, 2 Jun 2022 15:56:30 -0400 Subject: [PATCH 03/17] change file name and run black --- pennylane/resources/__init__.py | 1 + pennylane/resources/{double_factorization.py => df.py} | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) rename pennylane/resources/{double_factorization.py => df.py} (97%) diff --git a/pennylane/resources/__init__.py b/pennylane/resources/__init__.py index 0f2138fc834..f7468697ae6 100644 --- a/pennylane/resources/__init__.py +++ b/pennylane/resources/__init__.py @@ -14,3 +14,4 @@ """ This subpackage provides the functionality for algorithm resource estimation. """ +from .df import norm \ No newline at end of file diff --git a/pennylane/resources/double_factorization.py b/pennylane/resources/df.py similarity index 97% rename from pennylane/resources/double_factorization.py rename to pennylane/resources/df.py index 2b2314ca990..fad86074266 100644 --- a/pennylane/resources/double_factorization.py +++ b/pennylane/resources/df.py @@ -69,10 +69,10 @@ def norm(one, two, eigvals): >>> l, w, v = factorize(two, 1e-5) >>> print(norm(one, two, w)) 52.98762043980203 - """ + """ lambda_one = 0.25 * np.sum([np.sum(abs(val)) ** 2 for val in eigvals]) - t_mat = one - 0.5 * np.einsum('illj', two) + np.einsum('llij', two) + t_mat = one - 0.5 * np.einsum("illj", two) + np.einsum("llij", two) val, vec = np.linalg.eigh(t_mat) From cb0b2079920186daaa8a1715420c5e020deb2a63 Mon Sep 17 00:00:00 2001 From: soranjh Date: Thu, 2 Jun 2022 16:29:46 -0400 Subject: [PATCH 04/17] add test for norm --- pennylane/__init__.py | 1 + tests/resources/test_df.py | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/resources/test_df.py diff --git a/pennylane/__init__.py b/pennylane/__init__.py index d0b45857723..47ca40bd24d 100644 --- a/pennylane/__init__.py +++ b/pennylane/__init__.py @@ -30,6 +30,7 @@ import pennylane.math import pennylane.operation import pennylane.qnn +import pennylane.resources import pennylane.templates import pennylane.hf import pennylane.qchem diff --git a/tests/resources/test_df.py b/tests/resources/test_df.py new file mode 100644 index 00000000000..6015ddd7165 --- /dev/null +++ b/tests/resources/test_df.py @@ -0,0 +1,51 @@ +# Copyright 2018-2021 Xanadu Quantum Technologies Inc. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +Unit tests for functions needed for resource estimation with double factorization method. +""" +import pytest +import pennylane as qml +from pennylane import numpy as np + + +@pytest.mark.parametrize( + ("one", "two", "eigvals", "lamb_ref"), + [ + ( + np.array([[-1.25330961e00, 4.01900735e-14], [4.01900735e-14, -4.75069041e-01]]), + # two-electron integral is arranged in the chemist notation [11|22] + np.array( + [ + [ + [[6.74755872e-01, -4.60742555e-14], [-4.60742555e-14, 6.63711349e-01]], + [[-4.61020111e-14, 1.81210478e-01], [1.81210478e-01, -4.26325641e-14]], + ], + [ + [[-4.60464999e-14, 1.81210478e-01], [1.81210478e-01, -4.25215418e-14]], + [[6.63711349e-01, -4.28546088e-14], [-4.24105195e-14, 6.97651447e-01]], + ], + ] + ), + np.tensor( + [[-0.10489852, 0.10672343], [-0.42568824, 0.42568824], [-0.82864211, -0.81447282]] + ), + 1.6570518796336895, # lambda value obtained from openfermion + ) + ], +) +def test_df_norm(one, two, eigvals, lamb_ref): + r"""Test that the norm function returns the correct 1-norm.""" + lamb = qml.resources.norm(one, two, eigvals) + + assert np.allclose(lamb, lamb_ref) From fa22053cde86d587f732a0712b2215cd1c90c060 Mon Sep 17 00:00:00 2001 From: soranjh Date: Thu, 2 Jun 2022 16:35:37 -0400 Subject: [PATCH 05/17] add resources to docs --- doc/code/qml_resources.rst | 15 +++++++++++++++ doc/index.rst | 1 + 2 files changed, 16 insertions(+) create mode 100644 doc/code/qml_resources.rst diff --git a/doc/code/qml_resources.rst b/doc/code/qml_resources.rst new file mode 100644 index 00000000000..70eb657f998 --- /dev/null +++ b/doc/code/qml_resources.rst @@ -0,0 +1,15 @@ +qml.resources +============= + +Overview +-------- + +The resources module provides the functionality to estimate the cost of implementing quantum +algorithms. + +.. currentmodule:: pennylane.resources + +.. automodapi:: pennylane.resources + :no-heading: + :include-all-objects: + :no-inheritance-diagram: diff --git a/doc/index.rst b/doc/index.rst index 5043bdedb0d..cdf405f7dc4 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -189,6 +189,7 @@ PennyLane is **free** and **open source**, released under the Apache License, Ve code/qml_hf code/qml_qchem code/qml_qnn + code/qml_resources code/qml_tape code/qml_transforms code/qml_drawer From 1be7689dbfa6462cce78325eed30f3d95961b8ea Mon Sep 17 00:00:00 2001 From: soranjh Date: Thu, 2 Jun 2022 17:00:47 -0400 Subject: [PATCH 06/17] run isort and black --- pennylane/resources/__init__.py | 2 +- pennylane/resources/df.py | 2 +- tests/resources/test_df.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pennylane/resources/__init__.py b/pennylane/resources/__init__.py index f7468697ae6..12cd32ea806 100644 --- a/pennylane/resources/__init__.py +++ b/pennylane/resources/__init__.py @@ -14,4 +14,4 @@ """ This subpackage provides the functionality for algorithm resource estimation. """ -from .df import norm \ No newline at end of file +from .df import norm diff --git a/pennylane/resources/df.py b/pennylane/resources/df.py index fad86074266..b0581fe6a59 100644 --- a/pennylane/resources/df.py +++ b/pennylane/resources/df.py @@ -74,7 +74,7 @@ def norm(one, two, eigvals): t_mat = one - 0.5 * np.einsum("illj", two) + np.einsum("llij", two) - val, vec = np.linalg.eigh(t_mat) + val, _ = np.linalg.eigh(t_mat) lambda_two = np.sum(abs(val)) diff --git a/tests/resources/test_df.py b/tests/resources/test_df.py index 6015ddd7165..e1262ffd42f 100644 --- a/tests/resources/test_df.py +++ b/tests/resources/test_df.py @@ -15,6 +15,7 @@ Unit tests for functions needed for resource estimation with double factorization method. """ import pytest + import pennylane as qml from pennylane import numpy as np From d9a596f44c5727005347d83cd38a5f580bff12d0 Mon Sep 17 00:00:00 2001 From: soranjh Date: Fri, 3 Jun 2022 09:49:55 -0400 Subject: [PATCH 07/17] correct rst file format --- doc/code/qml_resources.rst | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/code/qml_resources.rst b/doc/code/qml_resources.rst index 70eb657f998..2296c8b71f1 100644 --- a/doc/code/qml_resources.rst +++ b/doc/code/qml_resources.rst @@ -1,15 +1,15 @@ qml.resources -============= - -Overview --------- - -The resources module provides the functionality to estimate the cost of implementing quantum -algorithms. - -.. currentmodule:: pennylane.resources - -.. automodapi:: pennylane.resources - :no-heading: - :include-all-objects: - :no-inheritance-diagram: +============= + +Overview +-------- + +The resources module provides the functionality to estimate the cost of implementing quantum +algorithms. + +.. currentmodule:: pennylane.resources + +.. automodapi:: pennylane.resources + :no-heading: + :include-all-objects: + :no-inheritance-diagram: From 30c6b4aa1623b6f6edb415ff1070c2fa29dd0e45 Mon Sep 17 00:00:00 2001 From: soranjh Date: Fri, 3 Jun 2022 10:25:38 -0400 Subject: [PATCH 08/17] correct docstring format --- pennylane/resources/df.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pennylane/resources/df.py b/pennylane/resources/df.py index b0581fe6a59..235aad74a06 100644 --- a/pennylane/resources/df.py +++ b/pennylane/resources/df.py @@ -29,25 +29,27 @@ def norm(one, two, eigvals): \lambda = ||T|| + \frac{1}{4} \sum_r ||L^{(r)}||^2, - where the Schatten norm, :math:`||L||`, is defined as + where the Schatten norm for a given matrix :math:`T` is defined as .. math:: - ||L|| = \sum_k |\text{eigvals}[L]_k|. + ||T|| = \sum_k |\text{eigvals}[T]_k|. The matrices :math:`L^{(r)}` are obtained from a rank-r factorizing the two-electron integral - tensor :math:`h`, arranged in the chemist notation, such that + tensor :math:`h` such that .. math:: - h_{ijkl} = \sum_r L_{ij}^{(r)} L_{kl}^{(r) T}. + h_{ijkl} = \sum_r L_{ij}^{(r)} L_{kl}^{(r) T}, - The matrix :math:`T` is constructed from the one-and two electron integrals as + and the matrix :math:`T` is constructed from the one- and two-electron integrals .. math:: T = h_{ij} - \frac{1}{2} \sum_l h_{illj} + \sum_l h_{llij}. + Note that the two-electron integral tensor must be arranged in the chemist notation [11|22]. + Args: one (array[array[float]]): one-electron integrals two (array[array[float]]): two-electron integrals From f74b7562c039ffd7e38e4c020f3c8241126e3583 Mon Sep 17 00:00:00 2001 From: soranjh Date: Fri, 3 Jun 2022 10:43:40 -0400 Subject: [PATCH 09/17] correct docstring format --- pennylane/resources/df.py | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/pennylane/resources/df.py b/pennylane/resources/df.py index 235aad74a06..c5393519aab 100644 --- a/pennylane/resources/df.py +++ b/pennylane/resources/df.py @@ -50,27 +50,27 @@ def norm(one, two, eigvals): Note that the two-electron integral tensor must be arranged in the chemist notation [11|22]. - Args: - one (array[array[float]]): one-electron integrals - two (array[array[float]]): two-electron integrals - eigvals (array[float]): eigenvalues of the matrices obtained from factorizing the - two-electron integral tensor - - Returns: - array[float]: 1-norm of the Hamiltonian - - **Example** - - >>> symbols = ['H', 'H', 'O'] - >>> geometry = np.array([[0.0, 0.000000000, 0.150166845], - >>> [0.0, 0.768778665, -0.532681406], - >>> [0.0, -0.768778665, -0.532681406]], requires_grad = False) / 0.529177 - >>> mol = qml.qchem.Molecule(symbols, geometry, basis_name='sto-3g') - >>> core, one, two = qml.qchem.electron_integrals(mol)() - >>> two = np.swapaxes(two, 1, 3) # convert to the chemists notation - >>> l, w, v = factorize(two, 1e-5) - >>> print(norm(one, two, w)) - 52.98762043980203 + Args: + one (array[array[float]]): one-electron integrals + two (array[array[float]]): two-electron integrals + eigvals (array[float]): eigenvalues of the matrices obtained from factorizing the + two-electron integral tensor + + Returns: + array[float]: 1-norm of the Hamiltonian + + **Example** + + >>> symbols = ['H', 'H', 'O'] + >>> geometry = np.array([[0.0, 0.000000000, 0.150166845], + >>> [0.0, 0.768778665, -0.532681406], + >>> [0.0, -0.768778665, -0.532681406]], requires_grad = False) / 0.529177 + >>> mol = qml.qchem.Molecule(symbols, geometry, basis_name='sto-3g') + >>> core, one, two = qml.qchem.electron_integrals(mol)() + >>> two = np.swapaxes(two, 1, 3) # convert to the chemists notation + >>> l, w, v = factorize(two, 1e-5) + >>> print(norm(one, two, w)) + 52.98762043980203 """ lambda_one = 0.25 * np.sum([np.sum(abs(val)) ** 2 for val in eigvals]) From bf197afc441917d98dab92d4ec00a6cbe6ee9d85 Mon Sep 17 00:00:00 2001 From: soranjh Date: Thu, 9 Jun 2022 11:06:52 -0400 Subject: [PATCH 10/17] modify docstring --- doc/code/qml_resources.rst | 4 ++-- pennylane/resources/df.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/code/qml_resources.rst b/doc/code/qml_resources.rst index 2296c8b71f1..e6014ff4ccb 100644 --- a/doc/code/qml_resources.rst +++ b/doc/code/qml_resources.rst @@ -4,8 +4,8 @@ qml.resources Overview -------- -The resources module provides the functionality to estimate the cost of implementing quantum -algorithms. +The resources module provides the functionality to estimate the cost of implementing advanced +quantum algorithms. .. currentmodule:: pennylane.resources diff --git a/pennylane/resources/df.py b/pennylane/resources/df.py index c5393519aab..d76b7d37292 100644 --- a/pennylane/resources/df.py +++ b/pennylane/resources/df.py @@ -36,19 +36,19 @@ def norm(one, two, eigvals): ||T|| = \sum_k |\text{eigvals}[T]_k|. The matrices :math:`L^{(r)}` are obtained from a rank-r factorizing the two-electron integral - tensor :math:`h` such that + tensor :math:`V`, in the chemist notation, such that .. math:: - h_{ijkl} = \sum_r L_{ij}^{(r)} L_{kl}^{(r) T}, + V_{ijkl} = \sum_r L_{ij}^{(r)} L_{kl}^{(r) T}. - and the matrix :math:`T` is constructed from the one- and two-electron integrals + The matrix :math:`T` is constructed from the one- and two-electron integrals .. math:: - T = h_{ij} - \frac{1}{2} \sum_l h_{illj} + \sum_l h_{llij}. + T = h_{ij} - \frac{1}{2} \sum_l V_{illj} + \sum_l V_{llij}. - Note that the two-electron integral tensor must be arranged in the chemist notation [11|22]. + Note that the two-electron integral tensor must be arranged in the chemist notation. Args: one (array[array[float]]): one-electron integrals From fdbcdf341e0da46abb195ec03aabf3774cb293b6 Mon Sep 17 00:00:00 2001 From: soranjh Date: Thu, 9 Jun 2022 14:32:28 -0400 Subject: [PATCH 11/17] correct notation --- pennylane/resources/df.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pennylane/resources/df.py b/pennylane/resources/df.py index d76b7d37292..5083956f098 100644 --- a/pennylane/resources/df.py +++ b/pennylane/resources/df.py @@ -62,22 +62,20 @@ def norm(one, two, eigvals): **Example** >>> symbols = ['H', 'H', 'O'] - >>> geometry = np.array([[0.0, 0.000000000, 0.150166845], - >>> [0.0, 0.768778665, -0.532681406], - >>> [0.0, -0.768778665, -0.532681406]], requires_grad = False) / 0.529177 + >>> geometry = np.array([[0.00000000, 0.00000000, 0.28377432], + >>> [0.00000000, 1.45278171, -1.00662237], + >>> [0.00000000, -1.45278171, -1.00662237]], requires_grad=False) >>> mol = qml.qchem.Molecule(symbols, geometry, basis_name='sto-3g') >>> core, one, two = qml.qchem.electron_integrals(mol)() >>> two = np.swapaxes(two, 1, 3) # convert to the chemists notation - >>> l, w, v = factorize(two, 1e-5) - >>> print(norm(one, two, w)) + >>> _, eigvals, _ = factorize(two, 1e-5) + >>> print(norm(one, two, eigvals)) 52.98762043980203 """ - lambda_one = 0.25 * np.sum([np.sum(abs(val)) ** 2 for val in eigvals]) + lambda_one = 0.25 * np.sum([np.sum(abs(v)) ** 2 for v in eigvals]) t_mat = one - 0.5 * np.einsum("illj", two) + np.einsum("llij", two) - - val, _ = np.linalg.eigh(t_mat) - - lambda_two = np.sum(abs(val)) + eigvals_t, _ = np.linalg.eigh(t_mat) + lambda_two = np.sum(abs(eigvals_t)) return lambda_one + lambda_two From 34f4a71cc29af154518b68f8d5a4e227bfb00212 Mon Sep 17 00:00:00 2001 From: soranjh Date: Thu, 9 Jun 2022 15:41:35 -0400 Subject: [PATCH 12/17] modify notation --- pennylane/resources/df.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pennylane/resources/df.py b/pennylane/resources/df.py index 5083956f098..4d36de01bb3 100644 --- a/pennylane/resources/df.py +++ b/pennylane/resources/df.py @@ -74,8 +74,8 @@ def norm(one, two, eigvals): """ lambda_one = 0.25 * np.sum([np.sum(abs(v)) ** 2 for v in eigvals]) - t_mat = one - 0.5 * np.einsum("illj", two) + np.einsum("llij", two) - eigvals_t, _ = np.linalg.eigh(t_mat) - lambda_two = np.sum(abs(eigvals_t)) + t_matrix = one - 0.5 * np.einsum("illj", two) + np.einsum("llij", two) + t_eigvals, _ = np.linalg.eigh(t_matrix) + lambda_two = np.sum(abs(t_eigvals)) return lambda_one + lambda_two From bad0e901d4b19c6cd8e8e3e7cc869aa15ef0a6ea Mon Sep 17 00:00:00 2001 From: soranjh Date: Thu, 9 Jun 2022 15:45:42 -0400 Subject: [PATCH 13/17] modify docstring --- pennylane/resources/df.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pennylane/resources/df.py b/pennylane/resources/df.py index 4d36de01bb3..83f9fe7cfa4 100644 --- a/pennylane/resources/df.py +++ b/pennylane/resources/df.py @@ -35,14 +35,14 @@ def norm(one, two, eigvals): ||T|| = \sum_k |\text{eigvals}[T]_k|. - The matrices :math:`L^{(r)}` are obtained from a rank-r factorizing the two-electron integral - tensor :math:`V`, in the chemist notation, such that + The matrices :math:`L^{(r)}` are obtained from factorization of the two-electron integral + tensor :math:`V` such that .. math:: V_{ijkl} = \sum_r L_{ij}^{(r)} L_{kl}^{(r) T}. - The matrix :math:`T` is constructed from the one- and two-electron integrals + The matrix :math:`T` is constructed from the one- and two-electron integrals as .. math:: From 94c85097edc171143afb783d4655b9c32983fcbc Mon Sep 17 00:00:00 2001 From: soranjh Date: Mon, 13 Jun 2022 16:53:20 -0400 Subject: [PATCH 14/17] change module name --- pennylane/resources/__init__.py | 2 +- pennylane/resources/{df.py => second_quantization.py} | 0 tests/resources/{test_df.py => test_second_quantization.py} | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename pennylane/resources/{df.py => second_quantization.py} (100%) rename tests/resources/{test_df.py => test_second_quantization.py} (100%) diff --git a/pennylane/resources/__init__.py b/pennylane/resources/__init__.py index 12cd32ea806..71938662dde 100644 --- a/pennylane/resources/__init__.py +++ b/pennylane/resources/__init__.py @@ -14,4 +14,4 @@ """ This subpackage provides the functionality for algorithm resource estimation. """ -from .df import norm +from .second_quantization import norm diff --git a/pennylane/resources/df.py b/pennylane/resources/second_quantization.py similarity index 100% rename from pennylane/resources/df.py rename to pennylane/resources/second_quantization.py diff --git a/tests/resources/test_df.py b/tests/resources/test_second_quantization.py similarity index 100% rename from tests/resources/test_df.py rename to tests/resources/test_second_quantization.py From 9ecfb3b491e06260fa826860e2e09cfedc099c5f Mon Sep 17 00:00:00 2001 From: soranjh Date: Mon, 13 Jun 2022 17:03:50 -0400 Subject: [PATCH 15/17] modify docstring --- pennylane/resources/second_quantization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane/resources/second_quantization.py b/pennylane/resources/second_quantization.py index 83f9fe7cfa4..dea1209ac4f 100644 --- a/pennylane/resources/second_quantization.py +++ b/pennylane/resources/second_quantization.py @@ -29,7 +29,7 @@ def norm(one, two, eigvals): \lambda = ||T|| + \frac{1}{4} \sum_r ||L^{(r)}||^2, - where the Schatten norm for a given matrix :math:`T` is defined as + where the Schatten 1-norm for a given matrix :math:`T` is defined as .. math:: From 5167ed48a1335f465d140471a201c1564e3204cd Mon Sep 17 00:00:00 2001 From: soranjh Date: Mon, 13 Jun 2022 17:57:44 -0400 Subject: [PATCH 16/17] change norm to norm_df --- pennylane/resources/__init__.py | 2 +- pennylane/resources/second_quantization.py | 2 +- tests/resources/test_second_quantization.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pennylane/resources/__init__.py b/pennylane/resources/__init__.py index 71938662dde..b72cc88dcf5 100644 --- a/pennylane/resources/__init__.py +++ b/pennylane/resources/__init__.py @@ -14,4 +14,4 @@ """ This subpackage provides the functionality for algorithm resource estimation. """ -from .second_quantization import norm +from .second_quantization import norm_df diff --git a/pennylane/resources/second_quantization.py b/pennylane/resources/second_quantization.py index dea1209ac4f..1c4c8c4dd87 100644 --- a/pennylane/resources/second_quantization.py +++ b/pennylane/resources/second_quantization.py @@ -18,7 +18,7 @@ from pennylane import numpy as np -def norm(one, two, eigvals): +def norm_df(one, two, eigvals): r"""Return the 1-norm of a molecular Hamiltonian from the one- and two-electron integrals and eigenvalues of the factorized two-electron integral tensor. diff --git a/tests/resources/test_second_quantization.py b/tests/resources/test_second_quantization.py index e1262ffd42f..64585b258ff 100644 --- a/tests/resources/test_second_quantization.py +++ b/tests/resources/test_second_quantization.py @@ -47,6 +47,6 @@ ) def test_df_norm(one, two, eigvals, lamb_ref): r"""Test that the norm function returns the correct 1-norm.""" - lamb = qml.resources.norm(one, two, eigvals) + lamb = qml.resources.norm_df(one, two, eigvals) assert np.allclose(lamb, lamb_ref) From fd3d63247138f08257188a77b7dde4e2f7bcf621 Mon Sep 17 00:00:00 2001 From: soranjh Date: Sat, 18 Jun 2022 13:21:56 -0400 Subject: [PATCH 17/17] modify docstring and fix doc build --- doc/code/qml_resources.rst | 6 ------ pennylane/resources/second_quantization.py | 2 +- tests/resources/test_second_quantization.py | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/doc/code/qml_resources.rst b/doc/code/qml_resources.rst index 44e265bb471..28783400b9b 100644 --- a/doc/code/qml_resources.rst +++ b/doc/code/qml_resources.rst @@ -4,12 +4,6 @@ qml.resources Overview -------- -<<<<<<< HEAD -The resources module provides the functionality to estimate the cost of implementing advanced -quantum algorithms. - -======= ->>>>>>> resource_estimation_algorithms .. currentmodule:: pennylane.resources .. automodapi:: pennylane.resources diff --git a/pennylane/resources/second_quantization.py b/pennylane/resources/second_quantization.py index dea1209ac4f..7675548e453 100644 --- a/pennylane/resources/second_quantization.py +++ b/pennylane/resources/second_quantization.py @@ -48,7 +48,7 @@ def norm(one, two, eigvals): T = h_{ij} - \frac{1}{2} \sum_l V_{illj} + \sum_l V_{llij}. - Note that the two-electron integral tensor must be arranged in the chemist notation. + Note that the two-electron integral tensor must be arranged in chemist notation. Args: one (array[array[float]]): one-electron integrals diff --git a/tests/resources/test_second_quantization.py b/tests/resources/test_second_quantization.py index e1262ffd42f..161aff607ca 100644 --- a/tests/resources/test_second_quantization.py +++ b/tests/resources/test_second_quantization.py @@ -25,7 +25,7 @@ [ ( np.array([[-1.25330961e00, 4.01900735e-14], [4.01900735e-14, -4.75069041e-01]]), - # two-electron integral is arranged in the chemist notation [11|22] + # two-electron integral is arranged in chemist notation np.array( [ [