qpe_toolbox.hamiltonian.pyscf_converter¶
PySCF integral conversion utilities.
Functions for extracting one- and two-electron integrals from PySCF mean-field objects (RHF, UHF, ROHF, CASCI) and assembling them into openfermion.ops.InteractionOperator Hamiltonians, with optional single factorization (SF) and double factorization (DF).
Functions¶
|
Obtain one- and two-electron integrals for spin-restricted systems. |
|
Obtain one- and two-electron integrals for spin-unrestricted systems. |
|
Obtain one- and two-electron integrals for spin-restricted active-space systems. |
|
Obtain one- and two-electron integrals for spin-unrestricted active-space systems. |
|
Construct an openfermion.ops.InteractionOperator from RHF/CASCI integrals. |
|
Construct an openfermion.ops.InteractionOperator from UHF/UCASCI integrals. |
|
Construct an openfermion.ops.InteractionOperator from any PySCF mean-field object. |
|
Perform eigenvalue-based single factorization of the two-electron integral tensor. |
|
Perform double factorization of the two-electron integral tensor. |
Module Contents¶
- qpe_toolbox.hamiltonian.pyscf_converter.get_integrals_rhf(rhf)[source]¶
Obtain one- and two-electron integrals for spin-restricted systems.
- Parameters:
rhf (pyscf.scf.RHF) – Converged restricted Hartree-Fock object.
- Returns:
ncas (int) – Number of molecular orbitals.
nelec (int) – Total number of electrons.
nuclear_energy (float) – Nuclear repulsion energy (constant term).
hpq (numpy.ndarray) – One-electron integrals in the MO basis, shape
(norb, norb).hpqrs (numpy.ndarray) – Two-electron integrals in chemist notation, shape
(norb, norb, norb, norb).
- qpe_toolbox.hamiltonian.pyscf_converter.get_integrals_uhf(uhf)[source]¶
Obtain one- and two-electron integrals for spin-unrestricted systems.
- Parameters:
uhf (pyscf.scf.UHF) – Converged unrestricted Hartree-Fock object.
- Returns:
ncas (int) – Number of molecular orbitals.
nelec (int) – Total number of electrons.
nuclear_energy (float) – Nuclear repulsion energy (constant term).
hpq (tuple of numpy.ndarray) – One-electron integrals
(h_up, h_down), each of shape(norb, norb).hpqrs (tuple of numpy.ndarray) – Two-electron integrals in chemist notation
(hpqrs_uu, hpqrs_ud, hpqrs_dd), each of shape(norb, norb, norb, norb).
- qpe_toolbox.hamiltonian.pyscf_converter.get_integrals_rhf_cas(rhf, ncas, nelecas, *, ncore=None)[source]¶
Obtain one- and two-electron integrals for spin-restricted active-space systems.
- Parameters:
- Returns:
ncas (int) – Number of active-space orbitals (as resolved by CASCI).
nelec (int or tuple of int) – Number of active-space electrons (as resolved by CASCI).
nuclear_energy (float) – Nuclear repulsion energy (constant term).
hpq (numpy.ndarray) – One-electron integrals in the active-space MO basis, shape
(ncas, ncas).hpqrs (numpy.ndarray) – Two-electron integrals in chemist notation, shape
(ncas, ncas, ncas, ncas).
- qpe_toolbox.hamiltonian.pyscf_converter.get_integrals_uhf_cas(uhf, ncas, nelecas, *, ncore=None)[source]¶
Obtain one- and two-electron integrals for spin-unrestricted active-space systems.
- Parameters:
- Returns:
ncas (int) – Number of active-space orbitals (as resolved by UCASCI).
nelec (int or tuple of int) – Number of active-space electrons (as resolved by UCASCI).
nuclear_energy (float) – Nuclear repulsion energy (constant term).
hpq (tuple of numpy.ndarray) – One-electron integrals
(h_up, h_down), each of shape(ncas, ncas).hpqrs (tuple of numpy.ndarray) – Two-electron integrals in chemist notation
(hpqrs_uu, hpqrs_ud, hpqrs_dd), each of shape(ncas, ncas, ncas, ncas).
- qpe_toolbox.hamiltonian.pyscf_converter.make_fermionic_hamiltonian_rhf(constant, hpq, hpqrs, *, orbital_major=True)[source]¶
Construct an openfermion.ops.InteractionOperator from RHF/CASCI integrals.
Assembles the fermionic second-quantised Hamiltonian from the outputs of
get_integrals_rhf()orget_integrals_rhf_cas().- Parameters:
constant (float) – Zero-body (nuclear repulsion / core energy) term.
hpq (numpy.ndarray) – One-electron integrals in the MO basis, shape
(norb, norb).hpqrs (numpy.ndarray) – Two-electron integrals in chemist notation, shape
(norb, norb, norb, norb).orbital_major (bool, default: True) – Spin-to-qubit mapping convention. If
True, qubits[0, norb)carry spin-up and qubits[norb, 2*norb)carry spin-down. IfFalse, even qubits carry spin-up and odd qubits carry spin-down.
- Returns:
Second-quantised fermionic Hamiltonian.
- Return type:
- qpe_toolbox.hamiltonian.pyscf_converter.make_fermionic_hamiltonian_uhf(energy_constant, hpq, hpqrs, *, orbital_major=True)[source]¶
Construct an openfermion.ops.InteractionOperator from UHF/UCASCI integrals.
Assembles the fermionic second-quantised Hamiltonian from the outputs of
get_integrals_uhf()orget_integrals_uhf_cas().- Parameters:
energy_constant (float) – Zero-body (nuclear repulsion / core energy) term.
hpq (tuple of numpy.ndarray) – One-electron integrals
(h_up, h_down), each of shape(norb, norb).hpqrs (tuple of numpy.ndarray) – Two-electron integrals in chemist notation
(hpqrs_uu, hpqrs_ud, hpqrs_dd), each of shape(norb, norb, norb, norb).orbital_major (bool, default: True) – Spin-to-qubit mapping convention. If
True, qubits[0, norb)carry spin-up and qubits[norb, 2*norb)carry spin-down. IfFalse, even qubits carry spin-up and odd qubits carry spin-down.
- Returns:
Second-quantised fermionic Hamiltonian.
- Return type:
- qpe_toolbox.hamiltonian.pyscf_converter.make_fermionic_hamiltonian_auto(mf, *, orbital_major=True)[source]¶
Construct an openfermion.ops.InteractionOperator from any PySCF mean-field object.
Dispatches to
make_fermionic_hamiltonian_rhf()for pyscf.scf.RHF / pyscf.scf.ROHF objects and tomake_fermionic_hamiltonian_uhf()for pyscf.scf.UHF objects.- Parameters:
mf (pyscf.scf.RHF or pyscf.scf.ROHF or pyscf.scf.UHF) – Converged PySCF mean-field object.
orbital_major (bool, default: True) – Spin-to-qubit mapping convention passed through to the underlying assembly function. See
make_fermionic_hamiltonian_rhf().
- Returns:
Second-quantised fermionic Hamiltonian.
- Return type:
- qpe_toolbox.hamiltonian.pyscf_converter.do_sf(hpqrs, *, threshold=0.0016)[source]¶
Perform eigenvalue-based single factorization of the two-electron integral tensor.
Decomposes
hpqrsvia eigendecomposition of its matrix representation and truncates eigenvectors until the Frobenius-norm reconstruction error falls belowthreshold.- Parameters:
hpqrs (numpy.ndarray) – Two-electron integrals in chemist notation, shape
(ncas, ncas, ncas, ncas).threshold (float, default: 1.6e-3) – Frobenius-norm convergence threshold for the truncated reconstruction.
- Returns:
rank (int) – Number of eigenvectors retained.
diff (float) – Frobenius norm of the truncation error.
hpqrs_truncated (numpy.ndarray) – Truncated two-electron integral tensor, shape
(ncas, ncas, ncas, ncas).
- qpe_toolbox.hamiltonian.pyscf_converter.do_df(hpqrs, *, threshold=0.0016)[source]¶
Perform double factorization of the two-electron integral tensor.
First applies an outer eigendecomposition (single factorization), then diagonalises each factor and discards eigenvalues whose scaled magnitude falls below
threshold. Algorithm followsopenfermion.resource_estimates.df.factorize_df.- Parameters:
hpqrs (numpy.ndarray) – Two-electron integrals in chemist notation, shape
(ncas, ncas, ncas, ncas).threshold (float, default: 1.6e-3) – Per-factor eigenvalue truncation threshold.
- Returns:
neig (int) – Total number of eigenvalues retained across all factors.
rank (int) – Number of outer factors retained.
df_factors (numpy.ndarray) – Double-factorized tensor factors, shape
(ncas, ncas, rank_retained).hpqrs_truncated (numpy.ndarray) – Truncated two-electron integral tensor, shape
(ncas, ncas, ncas, ncas).diff (float) – Frobenius norm of the truncation error.