ElectronicIntegrals#
- class ElectronicIntegrals(alpha=None, beta=None, beta_alpha=None, *, validate=True)[fuente]#
Bases:
LinearMixinA container class for electronic operator coefficients (a.k.a. electronic integrals).
This class contains multiple
qiskit_nature.second_q.operators.PolynomialTensorinstances, dealing with the specific case of storing electronic integrals, where the up- and down-spin electronic interactions need to be handled separately. These two spins are also commonly referred to by \(\alpha\) and \(\beta\), respectively.Specifically, this class stores three
PolynomialTensorinstances:alpha: which stores the up-spin integralsbeta: which stores the down-spin integralsbeta_alpha: which stores beta-alpha-spin two-body integrals
These tensors are subject to some expectations, namely:
for
alphaandbetaonly the following keys are allowed:"","+-","++--"for
beta_alphathe only allowed key is"++--"the reported
register_lengthattributes of all non-empty tensors must match
There are two ways of constructing the
ElectronicIntegrals:# assuming you already have your one- and two-body integrals from somewhere h1_a, h2_aa, h1_b, h2_bb, h2_ba = ... from qiskit_nature.second_q.operators import ElectronicIntegrals, PolynomialTensor alpha = PolynomialTensor({"+-": h1_a, "++--": h2_aa}) beta = PolynomialTensor({"+-": h1_b, "++--": h2_bb}) beta_alpha = PolynomialTensor({"++--": h2_ba}) integrals = ElectronicIntegrals(alpha, beta, beta_alpha) # alternatively, the following achieves the same effect: integrals = ElectronicIntegrals.from_raw_integrals(h1_a, h2_aa, h1_b, h2_bb, h2_ba)
This class then exposes common mathematical operations performed on these tensors allowing simple manipulation of the underlying data structures.
# addition integrals + integrals # scalar multiplication 2.0 * integrals
This class will substitute empty
betaandbeta_alphatensors with thealphatensor when necessary. For example, this means the following will happen:integrals_pure = ElectronicIntegrals(alpha) integrals_mixed = ElectronicIntegrals(alpha, beta, beta_alpha) sum = integrals_pure + integrals_mixed print(sum.beta.is_empty()) # False print(sum.beta_alpha.is_empty()) # False print(sum.beta.equiv(alpha + beta)) # True print(sum.beta_alpha.equiv(alpha + beta_alpha)) # True
The same logic holds for other mathematical operations involving multiple
ElectronicIntegrals.You can add a custom offset to be included in the operator generated from these coefficients like so:
from qiskit_nature.second_q.operators import PolynomialTensor integrals: ElectronicIntegrals offset = 2.5 integrals.alpha += PolynomialTensor({"": offset})
Any
None-valued argument will internally be replaced by an emptyPolynomialTensor(see alsoqiskit_nature.second_q.operators.PolynomialTensor.empty()).- Parámetros:
alpha (PolynomialTensor | None) – the up-spin electronic integrals
beta (PolynomialTensor | None) – the down-spin electronic integrals
beta_alpha (PolynomialTensor | None) – the beta-alpha-spin two-body electronic integrals. This may only contain the
++--key.validate (bool) – when set to False, no validation will be performed. Disable this setting with care!
- Muestra:
KeyError – if the
alphatensor contains keys other than"","+-", and"++--".KeyError – if the
betatensor contains keys other than"","+-", and"++--".KeyError – if the
beta_alphatensor contains keys other than"++--".ValueError – if the reported
register_lengthattributes of the alpha-, beta-, and beta-alpha-spin tensors do not all match.
Attributes
- alpha#
The up-spin electronic integrals.
- alpha_beta#
The alpha-beta-spin two-body electronic integrals.
These get reconstructed from
beta_alphaby transposing in the physicist” ordering convention.
- beta#
The down-spin electronic integrals.
- beta_alpha#
The beta-alpha-spin two-body electronic integrals.
- one_body#
Returns only the one-body integrals.
- register_length#
The size of the operator that can be generated from these ElectronicIntegrals.
- two_body#
Returns only the two-body integrals.
Methods
- classmethod apply(function, *operands, multi=False, validate=True)[fuente]#
Exposes the
qiskit_nature.second_q.operators.PolynomialTensor.apply()method.This behaves identical to the
applyimplementation of thePolynomialTensor, applied to thealpha,beta, andbeta_alphaattributes of the providedElectronicIntegralsoperands.This method is special, because it handles the scenario in which any operand has a non-empty
betaattribute, in which case the empty-beta attributes of any other operands will be filled withalphaattributes of those operands. Thebeta_alphaattributes will only be handled if they are non-empty in all supplied operands.- Parámetros:
function (Callable[[...], ndarray | SparseArray | complex]) – the function to apply to the internal arrays of the provided operands. This function must take numpy (or sparse) arrays as its positional arguments. The number of arguments must match the number of provided operands.
operands (ElectronicIntegrals) – a sequence of
ElectronicIntegralsinstances on which to operate.multi (bool) – when set to True this indicates that the provided numpy function will return multiple new numpy arrays which will each be wrapped into an
ElectronicIntegralsinstance separately.validate (bool) – when set to False, no validation will be performed. Disable this setting with care!
- Devuelve:
A new
ElectronicIntegrals.- Tipo del valor devuelto:
ElectronicIntegrals | list[qiskit_nature.second_q.operators.electronic_integrals.ElectronicIntegrals]
- classmethod einsum(einsum_map, *operands, validate=True)[fuente]#
Exposes the
qiskit_nature.second_q.operators.PolynomialTensor.einsum()method.This behaves identical to the
einsumimplementation of thePolynomialTensor, applied to thealpha,beta, andbeta_alphaattributes of the providedElectronicIntegralsoperands.This method is special, because it handles the scenario in which any operand has a non-empty
betaattribute, in which case the empty-beta attributes of any other operands will be filled withalphaattributes of those operands. Thebeta_alphaattributes will only be handled if they are non-empty in all supplied operands.- Parámetros:
einsum_map (dict[str, tuple[str, ...]]) – a dictionary, mapping from
numpy.einsum()subscripts to a tuple of strings. These strings correspond to the keys of matrices to be extracted from the providedElectronicIntegralsoperands. The last string in this tuple indicates the key under which to store the result in the returnedElectronicIntegrals.operands (ElectronicIntegrals) – a sequence of
ElectronicIntegralsinstances on which to operate.validate (bool) – when set to False, no validation will be performed. Disable this setting with care!
- Devuelve:
A new
ElectronicIntegrals.- Tipo del valor devuelto:
- classmethod from_raw_integrals(h1_a, h2_aa=None, h1_b=None, h2_bb=None, h2_ba=None, *, validate=True, auto_index_order=True)[fuente]#
Loads the provided integral matrices into an
ElectronicIntegralsinstance.When
auto_index_orderis enabled,qiskit_nature.second_q.operators.tensor_ordering.find_index_order()will be used to determine the index ordering of theh2_aamatrix, based on which the two-body matrices will automatically be transformed to the physicist” order, which is required by theqiskit_nature.second_q.operators.PolynomialTensor.- Parámetros:
h1_a (ndarray | SparseArray) – the alpha-spin one-body integrals.
h2_aa (ndarray | SparseArray | None) – the alpha-alpha-spin two-body integrals.
h1_b (ndarray | SparseArray | None) – the beta-spin one-body integrals.
h2_bb (ndarray | SparseArray | None) – the beta-beta-spin two-body integrals.
h2_ba (ndarray | SparseArray | None) – the beta-alpha-spin two-body integrals.
validate (bool) – whether or not to validate the integral matrices. Disable this setting with care!
auto_index_order (bool) – whether or not to automatically convert the matrices to physicists” order.
- Muestra:
QiskitNatureError – if auto_index_order=True, upon encountering an invalid
qiskit_nature.second_q.operators.tensor_ordering.IndexType.- Devuelve:
The resulting
ElectronicIntegrals.- Tipo del valor devuelto:
- second_q_coeffs()[fuente]#
Constructs the total
PolynomialTensorcontained the second-quantized coefficients.This function constructs the spin-orbital basis tensor as a
qiskit_nature.second_q.operators.PolynomialTensor, by arranging thealphaandbetaattributes in a block-ordered fashion (up-spin integrals cover the first part, down-spin integrals the second part of the resulting register space).If the
betaand/orbeta_alphaattributes are empty, thealphadata will be used in their place.- Devuelve:
The
PolynomialTensorrepresenting the entire system.- Tipo del valor devuelto:
- split(function, indices_or_sections, *, validate=True)[fuente]#
Exposes the
qiskit_nature.second_q.operators.PolynomialTensor.split()method.This behaves identical to the
splitimplementation of thePolynomialTensor, applied to thealpha,beta, andbeta_alphaattributes of the providedElectronicIntegralsoperands.Nota
When splitting arrays this will likely lead to array shapes which would fail the shape validation check. This is considered an advanced use case which is why the user is left to disable this check themselves, to ensure they know what they are doing.
- Parámetros:
function (Callable[[...], ndarray | SparseArray | Number]) – the splitting function to use. This function must take a single numpy (or sparse) array as its first input followed by a sequence of indices to split on. You should use
functools.partialif you need to provide keyword arguments (e.g.partial(np.split, axis=-1)). Common methods to use here arenumpy.hsplit()andnumpy.vsplit().indices_or_sections (int | Sequence[int]) – a single index or sequence of indices to split on.
validate (bool) – when set to False, no validation will be performed. Disable this setting with care!
- Devuelve:
The new
ElectronicIntegralsinstances.- Tipo del valor devuelto:
list[qiskit_nature.second_q.operators.electronic_integrals.ElectronicIntegrals]
- classmethod stack(function, operands, *, validate=True)[fuente]#
Exposes the
qiskit_nature.second_q.operators.PolynomialTensor.stack()method.This behaves identical to the
stackimplementation of thePolynomialTensor, applied to thealpha,beta, andbeta_alphaattributes of the providedElectronicIntegralsoperands.This method is special, because it handles the scenario in which any operand has a non-empty
betaattribute, in which case the empty-beta attributes of any other operands will be filled withalphaattributes of those operands. Thebeta_alphaattributes will only be handled if they are non-empty in all supplied operands.Nota
When stacking arrays this will likely lead to array shapes which would fail the shape validation check. This is considered an advanced use case which is why the user is left to disable this check themselves, to ensure they know what they are doing.
- Parámetros:
function (Callable[[...], ndarray | SparseArray | Number]) – the stacking function to apply to the internal arrays of the provided operands. This function must take a sequence of numpy (or sparse) arrays as its first argument. You should use
functools.partialif you need to provide keyword arguments (e.g.partial(np.stack, axis=-1)). Common methods to use here arenumpy.hstack()andnumpy.vstack().operands (Sequence[ElectronicIntegrals]) – a sequence of
ElectronicIntegralsinstances on which to operate.validate (bool) – when set to False, no validation will be performed. Disable this setting with care!
- Devuelve:
A new
ElectronicIntegrals.- Tipo del valor devuelto:
- trace_spin()[fuente]#
Returns a
PolynomialTensorwhere the spin components have been traced out.This will sum the
alphaandbetacomponents, tracing out the spin.- Devuelve:
A
PolynomialTensorwith the spin traced out.- Tipo del valor devuelto: