Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Slater determinant and fermionic Gaussian state initial states #483

Merged
merged 69 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
9a81c7d
add QuadraticHamiltonian class
kevinsung Dec 17, 2021
6d766fc
preparation of Slater determinants and fermionic Gaussian states
kevinsung Jan 13, 2022
03761bf
validate input
kevinsung Feb 14, 2022
43ab037
expose _fermionic_op as to_fermionic_op
kevinsung Feb 14, 2022
cc92944
use tuple labels and merge loops
kevinsung Feb 14, 2022
71b311d
update docs
kevinsung Feb 14, 2022
38b7bef
add num_modes argument
kevinsung Feb 14, 2022
1b84f1b
document new errors
kevinsung Feb 14, 2022
684d902
add num_modes property
kevinsung Feb 14, 2022
67dde7d
update doc
kevinsung Feb 14, 2022
b58a71b
Merge branch 'main' into quad-ham
kevinsung Feb 16, 2022
703673a
spelling
kevinsung Feb 16, 2022
59bb920
mypy
kevinsung Feb 21, 2022
4f60a79
from __future__ import annotations
kevinsung Feb 22, 2022
42aaf3b
Merge branch 'main' into quad-ham
kevinsung Feb 22, 2022
341ca0e
Merge branch 'main' into quad-ham
kevinsung Mar 1, 2022
2fdd7b6
Merge branch 'quad-ham' into slater-determinants
kevinsung Mar 1, 2022
7d12b70
Merge branch 'main' into quad-ham
Mar 15, 2022
d2e0a28
Merge branch 'main' into slater-determinants
Mar 15, 2022
bcbfb20
Merge branch 'main' into quad-ham
kevinsung Mar 23, 2022
96c4db1
add release note
kevinsung Mar 23, 2022
c7506a8
trigger CI
manoelmarques Mar 23, 2022
fe0ffec
fix spelling
manoelmarques Mar 23, 2022
610a226
Merge branch 'main' into quad-ham
Mar 24, 2022
9671df3
Merge branch 'quad-ham' into slater-determinants
kevinsung Mar 25, 2022
0bc4a39
update terra
kevinsung Mar 25, 2022
59eff26
Merge branch 'main' into slater-determinants
kevinsung Apr 8, 2022
1c97be4
split so each class has own file
kevinsung Apr 8, 2022
04a2abd
fix comments and error messages, don't name registers
kevinsung Apr 8, 2022
fe10114
revert library init description
kevinsung Apr 8, 2022
de7e875
run copyright check
kevinsung Apr 8, 2022
3cc50af
add release note
kevinsung Apr 8, 2022
d5c5475
spelling
kevinsung Apr 8, 2022
80e7639
spelling and docs
kevinsung Apr 8, 2022
dbd395c
make private functions hidden again
kevinsung Apr 8, 2022
c01f16b
mypy
kevinsung Apr 8, 2022
210b71a
improve docs and error messages
kevinsung Apr 14, 2022
59873d4
split test file
kevinsung Apr 14, 2022
bd4562e
add input validation
kevinsung Apr 14, 2022
3587600
mypy
kevinsung Apr 14, 2022
91e5e69
lint
kevinsung Apr 14, 2022
c01bc1e
add slater determinants test file
kevinsung Apr 14, 2022
568b2f4
create utils module
kevinsung Apr 27, 2022
2726ec4
test unsupported mappers fail gracefully
kevinsung Apr 27, 2022
c5e5400
fix imports
kevinsung Apr 27, 2022
c1691f1
raise NotImplementedError for unsupported mapper
kevinsung Apr 28, 2022
3a214c7
improve docs
kevinsung Apr 28, 2022
4f536e8
rewrite documentation
kevinsung May 2, 2022
6ec6d11
improve docs and error messages
kevinsung May 3, 2022
57fff13
factor out validation function
kevinsung May 3, 2022
02ea98e
improve slater determinant docs
kevinsung May 4, 2022
7074216
add tutorial notebook
kevinsung May 4, 2022
ad37380
typo
kevinsung May 4, 2022
88897de
fix warning in notebook
kevinsung May 4, 2022
9f3dab2
edit notebook
kevinsung May 10, 2022
d8ce8d1
comma
kevinsung May 10, 2022
e3c8939
spelling and format
kevinsung May 10, 2022
dc30b5b
add note to QuadraticHamiltonian class
kevinsung May 10, 2022
254b280
Update docs/tutorials/11_quadratic_hamiltonian_and_slater_determinant…
kevinsung May 11, 2022
ff08e8b
add hyperlinks
kevinsung May 16, 2022
bae6b0b
update print output in notebook
kevinsung May 16, 2022
72b97df
Update releasenotes/notes/slater-53415163fff84313.yaml
kevinsung May 16, 2022
335a03a
format
kevinsung May 18, 2022
da03eb4
edit notebook kernel to satisfy CI
kevinsung May 18, 2022
acb8a77
Merge branch 'main' into slater-determinants
manoelmarques May 18, 2022
7ec95d9
edit notebook
kevinsung May 19, 2022
519ee5f
edit notebook to say creation instead of annihilation
kevinsung May 19, 2022
a583c3e
Merge branch 'main' into slater-determinants
mrossinek May 20, 2022
8170258
Merge branch 'main' into slater-determinants
mergify[bot] May 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .pylintdict
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ cargs
cartesian
cbit
ccx
cdots
cfg
chc
chiral
Expand Down Expand Up @@ -100,6 +101,7 @@ debye
deepcopy
dft
diag
diagonalization
diagonalize
diagonalizes
diagonalizing
Expand All @@ -109,6 +111,7 @@ dimensionality
discoverable
distinguishability
dll
docstring
dof
doi
dt
Expand All @@ -122,6 +125,7 @@ eigensolvers
eigenstate
eigenstateresult
eigenstates
eigenvector
einact
einsum
endian
Expand Down Expand Up @@ -232,6 +236,7 @@ kwargs
kwds
labelled
lda
ldots
len
leucine
levinthal
Expand All @@ -246,6 +251,7 @@ ljik
lk
logfile
lookback
lvert
lysine
macos
majorana
Expand Down Expand Up @@ -322,6 +328,7 @@ ortho
orthonormal
otimes
outpath
overline
pac
param
parameterized
Expand Down Expand Up @@ -374,6 +381,7 @@ qubit
qubits
qutrit
radians
rangle
rcccx
rccx
readme
Expand Down Expand Up @@ -417,6 +425,7 @@ setia
setted
shende
sklearn
slater
spinop
springer
spsa
Expand Down
440 changes: 440 additions & 0 deletions docs/tutorials/11_quadratic_hamiltonian_and_slater_determinants.ipynb

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions qiskit_nature/circuit/library/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020, 2021.
# (C) Copyright IBM 2020, 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -25,7 +25,9 @@
:toctree: ../stubs/
:nosignatures:

FermionicGaussianState
HartreeFock
SlaterDeterminant
VSCF

Ansatzes
Expand Down Expand Up @@ -64,7 +66,7 @@
UVCCSD,
)

from .initial_states import HartreeFock, VSCF
from .initial_states import FermionicGaussianState, HartreeFock, SlaterDeterminant, VSCF

__all__ = [
"UCC",
Expand All @@ -76,4 +78,6 @@
"UVCC",
"UVCCSD",
"VSCF",
"FermionicGaussianState",
"SlaterDeterminant",
]
11 changes: 9 additions & 2 deletions qiskit_nature/circuit/library/initial_states/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020, 2021.
# (C) Copyright IBM 2020, 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -11,7 +11,14 @@
# that they have been altered from the originals.
"""Qiskit Nature Circuit Library Initial States."""

from .fermionic_gaussian_state import FermionicGaussianState
from .hartree_fock import HartreeFock
from .slater_determinants import SlaterDeterminant
from .vscf import VSCF

__all__ = ["HartreeFock", "VSCF"]
__all__ = [
"FermionicGaussianState",
"HartreeFock",
"SlaterDeterminant",
"VSCF",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Fermionic Gaussian states."""

from typing import Optional, Sequence

import numpy as np
from qiskit import QuantumCircuit, QuantumRegister
from qiskit_nature.converters.second_quantization import QubitConverter
from qiskit_nature.mappers.second_quantization import JordanWignerMapper

from .utils.givens_rotations import _prepare_fermionic_gaussian_state_jordan_wigner


def _validate_transformation_matrix(
mat: np.ndarray, rtol: float = 1e-5, atol: float = 1e-8
) -> None:
if not len(mat.shape) == 2:
raise ValueError(
"transformation_matrix must be a 2-dimensional array. "
f"Instead, got shape {mat.shape}."
)

n, p = mat.shape # pylint: disable=invalid-name
if p != n * 2:
raise ValueError(
"transformation_matrix must have shape (n_orbitals, 2 * n_orbitals). "
f"Instead, got shape {mat.shape}."
)

left = mat[:, :n]
right = mat[:, n:]
comm1 = left @ left.T.conj() + right @ right.T.conj()
comm2 = left @ right.T + right @ left.T
one = np.eye(n)
zero = np.zeros((n, n))
if not np.allclose(comm1, one, rtol=rtol, atol=atol) or not np.allclose(comm2, zero):
raise ValueError(
"transformation_matrix does not describe a valid transformation "
"of fermionic ladder operators. A valid matrix should have the block form "
"[W1 W2] where W1 @ W1.T.conj() + W2 @ W2.T.conj() = I and "
"W1 @ W2.T + W2 @ W1.T = 0."
)


class FermionicGaussianState(QuantumCircuit):
r"""A circuit that prepares a fermionic Gaussian state.

A fermionic Gaussian state is a state of the form

.. math::
b^\dagger_1 \cdots b^\dagger_{N_p} \lvert \overline{\text{vac}} \rangle

where

.. math::
\begin{pmatrix}
b^\dagger_1 \\
\vdots \\
b^\dagger_N \\
\end{pmatrix}
= W
\begin{pmatrix}
a^\dagger_1 \\
\vdots \\
a^\dagger_N \\
a_1 \\
\vdots \\
a_N
\end{pmatrix},

- :math:`a^\dagger_1, \ldots, a^\dagger_{N}` are the fermionic creation operators
- :math:`W` is an :math:`N \times 2N` matrix such that
:math:`b^\dagger_1, \ldots, b^\dagger_{N}` also satisfy the
fermionic anticommutation relations
- :math:`\lvert \overline{\text{vac}} \rangle` is the mutual 0-eigenvector of
the operators :math:`\{b_j^\dagger b_j\}`

The matrix :math:`W` has the block form

.. math::
\begin{pmatrix}
W_1 & W_2
\end{pmatrix}

where :math:`W_1` and :math:`W_2` must satisfy

.. math::
W_1 W_1^\dagger + W_2 W_2^\dagger = I \\
W_1 W_2^T + W_2 W_1^T = 0

The matrix :math:`W` is commonly obtained by calling the
:meth:`~.QuadraticHamiltonian.diagonalizing_bogoliubov_transform`
method of the :class:`~.QuadraticHamiltonian` class.
This matrix is used to create circuits that prepare eigenstates of the
quadratic Hamiltonian.

Currently, only the Jordan-Wigner Transformation is supported.

Reference: `arXiv:1711.05395`_

.. _arXiv:1711.05395: https://arxiv.org/abs/1711.05395
"""

def __init__(
self,
transformation_matrix: np.ndarray,
occupied_orbitals: Optional[Sequence[int]] = None,
qubit_converter: QubitConverter = None,
validate: bool = True,
rtol: float = 1e-5,
atol: float = 1e-8,
**circuit_kwargs,
) -> None:
r"""
Args:
transformation_matrix: The matrix :math:`W` that specifies the coefficients of the
new creation operators in terms of the original creation and annihilation operators.
This matrix must satisfy special constraints; see the main body of the docstring
of this class.
occupied_orbitals: The pseudo-particle orbitals to fill. These refer to the indices
of the operators :math:`\{b^\dagger_j\}` from the main body of the docstring
of this function. The default behavior is to use the empty set of orbitals,
which corresponds to a state with zero pseudo-particles.
qubit_converter: a QubitConverter instance.
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
validate: Whether to validate the inputs.
rtol: Relative numerical tolerance for input validation.
atol: Absolute numerical tolerance for input validation.
circuit_kwargs: Keyword arguments to pass to the QuantumCircuit initializer.

Raises:
ValueError: transformation_matrix must be a 2-dimensional array.
ValueError: transformation_matrix must have shape (n_orbitals, 2 * n_orbitals).
NotImplementedError: Currently, only the Jordan-Wigner Transform is supported.
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
Please use
:class:`qiskit_nature.mappers.second_quantization.JordanWignerMapper`
to construct the qubit mapper used to construct `qubit_converter`.
"""
if validate:
_validate_transformation_matrix(transformation_matrix, rtol=rtol, atol=atol)

if occupied_orbitals is None:
occupied_orbitals = []
if qubit_converter is None:
qubit_converter = QubitConverter(JordanWignerMapper())

n, _ = transformation_matrix.shape
register = QuantumRegister(n)
super().__init__(register, **circuit_kwargs)

if isinstance(qubit_converter.mapper, JordanWignerMapper):
operations = _prepare_fermionic_gaussian_state_jordan_wigner(
register, transformation_matrix, occupied_orbitals
)
for gate, qubits in operations:
self.append(gate, qubits)
else:
raise NotImplementedError(
"Currently, only the Jordan-Wigner Transform is supported. "
"Please use "
"qiskit_nature.mappers.second_quantization.JordanWignerMapper "
"to construct the qubit mapper used to construct qubit_converter."
)
Loading