ElectronicEnergy#
- class ElectronicEnergy(electronic_integrals, *, constants=None)[source]#
Bases:
Hamiltonian
The electronic energy Hamiltonian.
This class implements the following Hamiltonian:
\[\sum_{p, q} h_{pq} a^\dagger_p a_q + \sum_{p, q, r, s} g_{pqrs} a^\dagger_p a^\dagger_q a_r a_s ,\]where \(h_{pq}\) and \(g_{pqrs}\) are the one- and two-body electronic integrals, stored in an
ElectronicIntegrals
container. When dealing with separate coefficients for the \(\alpha\)- and \(\beta\)-spin electrons, the unrestricted-spin Hamiltonian can be obtained from the one above in a straight-forward manner, following any quantum chemistry textbook.You can construct an instance of this Hamiltonian in multiple ways:
With an existing instance of
ElectronicIntegrals
:
integrals: ElectronicIntegrals = ... from qiskit_nature.second_q.hamiltonians import ElectronicEnergy hamiltonian = ElectronicEnergy(integrals, constants={"nuclear_repulsion_energy": 1.0})
From a raw set of integral coefficient matrices:
# assuming, you have your one- and two-body integrals from somewhere h1_a, h2_aa, h1_b, h2_bb, h2_ba = ... hamiltonian = ElectronicEnergy.from_raw_integrals(h1_a, h2_aa, h1_b, h2_bb, h2_ba) hamiltonian.nuclear_repulsion_energy = 1.0
Note, how we specified the nuclear repulsion energy as a constant energy offset in the above examples. This term will not be included in the mapped qubit operator since it is a constant offset term and does not need to incur any errors from being measured on a quantum device. It is however possible to include constant energy terms inside of the
ElectronicIntegrals
container, if you want it to be included in the qubit operator, once mapping the second-quantized operator to the qubit space (see alsoQubitMapper
).from qiskit_nature.second_q.operators import PolynomialTensor e_nuc = hamiltonian.nuclear_repulsion_energy hamiltonian.electronic_integrals.alpha += PolynomialTensor({"": e_nuc}) hamiltonian.nuclear_repulsion_energy = None
It is also possible to add other constant energy offsets to the
constants
attribute of this Hamiltonian. All offsets registered in that dictionary will not be mapped to the qubit operator.hamiltonian.constants["my custom offset"] = 5.0 # be careful, the following overwrites the hamiltonian.nuclear_repulsion_energy value hamiltonian.constants["nuclear_repulsion_energy"] = 10.0
- electronic_integrals#
- constants#
A mapping of constant energy offsets, not mapped to the qubit operator.
- Parameters:
electronic_integrals (ElectronicIntegrals) – The container with the one- and two-body coefficients.
constants (MutableMapping[str, float]) – A mapping of constant energy offsets.
Attributes
- nuclear_repulsion_energy#
The nuclear repulsion energy.
This constant energy offset does not get included in the generated operator. Add it as a constant term to the
electronic_integrals
and remove it here, if you want to include it in the generated operator:from qiskit_nature.second_q.operators import PolynomialTensor hamiltonian = ElectronicEnergy(...) hamiltonian.electronic_integrals.alpha += PolynomialTensor({ "": hamiltonian.nuclear_repulsion_energy }) hamiltonian.nuclear_repulsion_energy = None
- register_length#
Methods
- coulomb(density)[source]#
Computes the Coulomb term for the given reduced density matrix.
\[J_{qr} = \sum g_{pqrs} D_{ps}\]- Parameters:
density (ElectronicIntegrals) – the reduced density matrix.
- Returns:
The Coulomb operator coefficients.
- Raises:
NotImplementedError – when encountering
SymmetricTwoBodyIntegrals
inside ofElectronicEnergy.electronic_integrals
.- Return type:
- exchange(density)[source]#
Computes the Exchange term for the given reduced density matrix.
\[K_{pr} = \sum g_{pqrs} D_{qs}\]- Parameters:
density (ElectronicIntegrals) – the reduced density matrix.
- Returns:
The Exchange operator coefficients.
- Raises:
NotImplementedError – when encountering
SymmetricTwoBodyIntegrals
inside ofElectronicEnergy.electronic_integrals
.- Return type:
- fock(density)[source]#
Computes the Fock operator for the given reduced density matrix.
\[F_{pq} = h_{pq} + J_{pq} - K_{pq}\]where \(J\) and \(K\) are the
coulomb()
andexchange()
terms, respectively.- Parameters:
density (ElectronicIntegrals) – the reduced density matrix.
- Returns:
The Fock operator coefficients.
- Return type:
- classmethod from_raw_integrals(h1_a, h2_aa, h1_b=None, h2_bb=None, h2_ba=None, *, validate=True, auto_index_order=True)[source]#
Constructs a hamiltonian instance from raw integrals.
This function simply calls
from_raw_integrals()
. See its documentation for more details.- Parameters:
h1_a (np.ndarray) – the alpha-spin one-body coefficients.
h2_aa (np.ndarray) – the alpha-alpha-spin two-body coefficients.
h1_b (np.ndarray | None) – the beta-spin one-body coefficients.
h2_bb (np.ndarray | None) – the beta-beta-spin two-body coefficients.
h2_ba (np.ndarray | None) – the beta-alpha-spin two-body coefficients.
validate (bool) – whether or not to validate the coefficient matrices.
auto_index_order (bool) – whether or not to automatically convert the matrices to physicists’ order.
- Returns:
The resulting
ElectronicEnergy
instance.- Return type:
- interpret(result)[source]#
Interprets an
EigenstateResult
.In particular, this adds the constant energy shifts stored in this hamiltonian to the result object.
- Parameters:
result (qiskit_nature.second_q.problems.EigenstateResult) – the result to add meaning to.