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

get_integrals_rhf(rhf)

Obtain one- and two-electron integrals for spin-restricted systems.

get_integrals_uhf(uhf)

Obtain one- and two-electron integrals for spin-unrestricted systems.

get_integrals_rhf_cas(rhf, ncas, nelecas, *[, ncore])

Obtain one- and two-electron integrals for spin-restricted active-space systems.

get_integrals_uhf_cas(uhf, ncas, nelecas, *[, ncore])

Obtain one- and two-electron integrals for spin-unrestricted active-space systems.

make_fermionic_hamiltonian_rhf(constant, hpq, hpqrs, *)

Construct an openfermion.ops.InteractionOperator from RHF/CASCI integrals.

make_fermionic_hamiltonian_uhf(energy_constant, hpq, ...)

Construct an openfermion.ops.InteractionOperator from UHF/UCASCI integrals.

make_fermionic_hamiltonian_auto(mf, *[, orbital_major])

Construct an openfermion.ops.InteractionOperator from any PySCF mean-field object.

do_sf(hpqrs, *[, threshold])

Perform eigenvalue-based single factorization of the two-electron integral tensor.

do_df(hpqrs, *[, threshold])

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:
  • rhf (pyscf.scf.RHF) – Converged restricted Hartree-Fock object.

  • ncas (int) – Number of active-space orbitals.

  • nelecas (int or tuple of int) – Number of active-space electrons.

  • ncore (int or None, default: None) – Number of frozen core orbitals. Inferred from nelecas if None.

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:
  • uhf (pyscf.scf.UHF) – Converged unrestricted Hartree-Fock object.

  • ncas (int) – Number of active-space orbitals.

  • nelecas (int or tuple of int) – Number of active-space electrons.

  • ncore (int or None, default: None) – Number of frozen core orbitals. Inferred from nelecas if None.

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() or get_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. If False, even qubits carry spin-up and odd qubits carry spin-down.

Returns:

Second-quantised fermionic Hamiltonian.

Return type:

openfermion.ops.InteractionOperator

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() or get_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. If False, even qubits carry spin-up and odd qubits carry spin-down.

Returns:

Second-quantised fermionic Hamiltonian.

Return type:

openfermion.ops.InteractionOperator

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 to make_fermionic_hamiltonian_uhf() for pyscf.scf.UHF objects.

Parameters:
Returns:

Second-quantised fermionic Hamiltonian.

Return type:

openfermion.ops.InteractionOperator

qpe_toolbox.hamiltonian.pyscf_converter.do_sf(hpqrs, *, threshold=0.0016)[source]

Perform eigenvalue-based single factorization of the two-electron integral tensor.

Decomposes hpqrs via eigendecomposition of its matrix representation and truncates eigenvectors until the Frobenius-norm reconstruction error falls below threshold.

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 follows openfermion.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.