View on GitHub
Open this notebook in GitHub to run it yourself
- Subsystem A (fragment/active region): The chemically relevant fragment (e.g., an enzyme active site or reaction center) that requires an accurate quantum treatment, such as correlated wave function or quantum computer algorithms (like VQE).
- Subsystem B (environment): The surrounding region, treated with a less expensive mean field method such as Hartree-Fock or density functional theory (DFT).
- The environment is treated using efficient numerical methods, yielding a mean-field description that serves as input to the quantum calculation.
- From this mean-field output, an embedding Hamiltonian, is constructed, which governs the dynamics of the active subsystem within its environment.
- is then solved using correlated methods, which take into account quantum effects, and can be evaluated efficiently utilizing quantum algorithms.
- Finally, the results are combined to recover the total system energy, ensuring that the fragment (system A) is accurately described while system B provides the correct environmental influence.
Background: Quantum Chemistry
One begins by solving for the ground state of the electronic time-independent Schrödinger equation (TISE). Within the Born–Oppenheimer approximation, the nuclei are treated as fixed point charges and the electronic Hamiltonian for electrons and nuclei is where and are the charge and position of nucleus , and the three terms represent the electronic kinetic energy, the electron–nucleus attraction, and the electron–electron repulsion, respectively (in atomic units). The eigenvalue problem reads , or in the position representation: where the electronic wave-function is given by and represents both the spatial coordinate and the spin of the ‘th electron. For a system of electrons, the electronic Hamiltonian describes a problem in -dimensional space, involving electron-electron interactions. Exact diagonalization techniques, such as full Configuration Interaction (CI), scale exponentially with the number of electrons As a result, an exact solution of the problem is computationally intractable for all but the smallest systems. To make progress, mean-field methods are introduced to reduce the computational complexity. In these approaches, the detailed interactions between electrons are replaced by an average, or “mean,” field, allowing each electron to move independently in the effective potential created by all the others. The reduction in complexity arises from neglecting explicit particle–particle correlations. This approximation is generally valid for a wide range of chemical systems and solid-state materials, where electron correlation effects are relatively small. Studied example: For a water molecule, involving a single Oxygen covalently bonded to two Hydrogens, there are a total of electrons, while , with nuclei charges , and, and .
Mean-Field Methods
Solving the electronic Schrödinger equation exactly scales exponentially with the number of electrons, so we rely on mean-field methods, in which each electron moves in the averaged field created by all the others. Two common methods underpin the embedding scheme:- Hartree–Fock (HF): approximates the many-electron wavefunction as a single Slater determinant and solves the resulting one-electron (Fock) eigenvalue problem self-consistently. It treats exchange exactly but neglects electron correlation beyond the mean field.
- Density functional theory (DFT): recasts the problem in terms of the electron density through the Kohn–Sham equations, folding the quantum many-body effects into an approximate exchange–correlation functional (here, B3LYP).
Studied example: mean-field with the Classiq SDK
We now run the full-system mean field for the water molecule. With the SDK we describe the molecule with aMoleculeSpec, create an EmbeddingCalculator, and
call run_dft.
MoleculeSpec — the molecular description (a frozen dataclass).
Its attributes are:
atom(str): the geometry, given as an inline PySCF atom string or the textual contents of a.pdb/.xyzfile.
MoleculeSpec.from_pdb_file / MoleculeSpec.from_xyz_file constructors to read a file client-side.
basis(str, default"cc-pVDZ"): the PySCF basis-set name.charge(int, default0): the net molecular charge.spin(int, default0):2S, the number of unpaired electrons (0= closed-shell singlet).unit(str, default"Angstrom"): the length unit of the coordinates inatom.
EmbeddingCalculator — the pipeline driver.
Its constructor takes:
spec(MoleculeSpec): the molecule defined above.spin_mode(SpinMode, defaultAUTO):RESTRICTED,UNRESTRICTED, orAUTO(resolves to restricted iffspec.spin == 0); the resolved value is exposed on the read-onlyeffective_spin_modeproperty.auto_validations(sequence ofValidationCheck, default empty): checks to run automatically at the end ofrun_dft_embedding. We leave this empty here and run the checks explicitly in a later section.
run_dftcorresponds step 1 above. It runs the full-system mean-field (DFT) calculation, returning aDFTState.run_dft_embeddingcorresponds to step 2. It partitions the system, builds the embedding potential, and constructs , returning(MeanFieldData, QuantumData).- Steps 3–4 (solving with VQE and recovering the total energy) are carried out explicitly in the notebook below.
run_validations: post-hoc consistency diagnostics on the embedding.
DFTState is a light
handle (resolved spin mode, functional, method), while the heavy converged SCF object
stays server-side and is threaded automatically into the embedding stage.
The
consistency checks are run later, in their own section.
Output:
Construction of the Embedding Hamiltonian
After performing the mean field calculation, we partition the total Hilbert space into an active (or alternatively “fragment”) space and the environment space. Following, we derive the embedding Hamiltonian, , which is an effective Hamiltonian of the active space, incorporating averaged environmental effects. Such a calculation is known as a WF-in-MF scheme, i.e., wave-function in a mean-field description. In the present tutorial, MF stands for HF or DFT, and the WF part is conducted by a VQE quantum calculation. There are a number of possible methods by which such an embedding Hamiltonian can be derived. In the present tutorial, we focus on the “Projection (Huzinaga) based embedding”. The key benefit of projection embedding compared to other embedding approaches is that it preserves additivity of the kinetic energy between the fragment (active space) and its environment. As a result, when both subsystems are treated at the same theoretical level, the fragment and environment energies combine to exactly reproduce the total energy of the full system. Within this framework, the total energy is given by: Where is the wave-function for subsystem . For a classical wave-function method is the single-electron reduced density matrix, associated with the state , . However, for the quantum calculation such as VQE, one does not generally have efficient access to the density matrix, but to the probablities in the computational basis. Therefore, in the following calculation, is obtained by an optimization procedure over the Fock operator of the embedded system (see details below) [2]. is evaluated by a correlated wave-function calculation, such as VQE. The embedding potential is where includes all the two-electron interactions. is a model hyperparameter, introducing an energy penalty on the environment states, and is the projection on the environment’s Hilbert space. The construction proceeds in three steps, all carried out automatically byrun_dft_embedding (the full derivation of each is collected in the
Technical Notes):
- Partition the occupied orbitals into the active fragment and the environment .
w_cut, yielding the fragment and environment density matrices .
- Build the embedded one-electron Hamiltonian , where is the embedding potential, projects onto the environment, and the level shift keeps the environment orbitals out of the active space.
- Select the active space and second-quantize. The fragment-occupied orbitals are augmented with a small set of active virtuals chosen by concentric localization (
n_active_virtuals/sv_tol), and the Hamiltonian is expressed in this basis as the embedded second-quantized Hamiltonian .
Studied example: building the embedding Hamiltonian with the SDK
The entire embedding construction — fragmentation of the occupied space, concentric localization of the active virtuals, assembly of the embedded one-electron operator , and projection to the second-quantized Hamiltonian — is performed in a singlerun_dft_embedding
call. We choose the oxygen atom (index 0) as the active fragment.
EmbeddingConfig exposes the following knob:
w_cut (Mulliken-weight threshold for assigning orbitals to the fragment),
n_active_virtuals (number of concentric-localized virtuals to keep), sv_tol
(SVD cutoff used when n_active_virtuals is None), and mu (the level-shift
projector strength).
The cached DFTState from run_dft is reused
automatically.
Output:
Consistency Tests
TheValidationCheck
diagnostics run through run_validations on the embedding state produced above.
We request the DFT-in-DFT energy match, two geometric sanity checks
(trace conservation and probability leakage), and the FCI-in-active-space
reference in a single call; the results are cached on calc.validation_results.
(Alternatively, the cheaper checks can be registered as auto_validations when
constructing the EmbeddingCalculator, in which case they run automatically at
the end of run_dft_embedding.)
Output:
dft_in_dft and trace_conservation, verifying physical consistency, while the rest of the validity checks are designed for more advanced usage.
dft_in_dft: Reconstructs the full-system DFT energy from the embedded fragment and environment contributions.
trace_term, leakage, and dE_mu indicate that no density leaked across the partition boundary.
trace_conservation: Verifies that .
probability_leak: Checks that the fragment density matrix has no weight on environment orbitals. A leak of confirms a clean separation.fci_active_space: Runs an exact (FCI) diagonalization of the embedded Hamiltonian within the 8-orbital active space ( Ha).
Quantum-ready Hamiltonians
The embedded and physical Hamiltonians are returned asopenfermion.FermionOperator objects on quantum_data, together
with the active-space particle numbers and the environment energy correction:
hamiltonian_emb: the embedded Hamiltonian, optimized over the fragment;hamiltonian_phys: the physical Hamiltonian (used to evaluate the energy);n_particles: the active-space(n_alpha, n_beta)electron counts;env_correction: the environment contribution added back to recover the total energy.
Output:
Theory
The Variational Quantum Eigensolver (VQE) is a hybrid algorithm that utilizes a quantum computer to prepare and measure quantum states while a classical computer optimizes them. It is primarily used to find the ground-state energy of a quantum system. The algorithm performs this task as follows (in the following, we omit the subscript for conciseness):- Determine an ansatz state by choosing a parameterized quantum circuit . A good ansatz must be expressive enough to represent the true ground state, while shallow enough to run on the contemporary noisy hardware.
- Prepare the quantum state
- Measure the expectation value .
- Classical optimization is performed, updating the parameters to reduce the energy.
- Repeats until convergence, the resulting state approximates the ground state (by the variational principle)
Mapping the embedded Hamiltonian to appropriate OpenFermion data structures
We employ theOpenFermion Python library to perform the VQE algorithm with Classiq. OpenFermion is an open-source Python library for working with fermionic systems on quantum computers.
Output:
Studied example: constructing the initial ansatz
We wrap the embedded Hamiltonian in aFermionHamiltonianProblem, taking the
active-space particle numbers directly from quantum_data.n_particles, and map
it to qubits.
Output:
Z2SymTaperMapper.
The transformation reduces the number of qubits from to . Moreover, the transformation modifies the form of the Hartree-Fock state.
Output:
Output:
Possibly Trimming the Hamiltonian
The computational resources can be reduced by trimming the qubit Hamiltonian. This corresponds to neglecting Pauli terms whose coefficient in the Hamiltonian is below a certain threshold. Below we trim terms with coefficients belowTHRESHOLD = 0.1.
This is a relatively aggressive
threshold that trades accuracy for reduced circuit depth. To preserve more accuracy, decrease the
threshold (e.g., 0.01) or comment out the trimming block entirely.
Output:
Exact Diagonalization
The exact diagonalization of the trimmed qubit Hamiltonian provides a classical reference for the VQE result. Note that this step scales exponentially with the number of qubits and takes approximately 30 minutes for the 14-qubit problem. The precomputed result is used below to avoid rerunning the expensive calculation.Solution of the active fragment by VQE
Output:
Output:
fci_active_space validation check above provides an equivalent classical reference and can be used in place of the exact diagonalization for benchmarking.
WF-in-DFT Energy Calculation
After obtaining an approximation for the ground state of the embedded Hamiltonian, utilizing the VQE algorithm, we evaluate the energy with respect to the physical Hamiltonian. We introduce anenergy_evaluation function which receives a set of parameters and Hamiltonian and evaluates the expectation value with respect to the Hamiltonian.
In order to evaluate (see Eq. (1)) we input the optimized parameters and qubit representation of the physical Hamiltonian, opt_params and qubit_ham_phys.
Output:
Output:
Output:
quantum_data.env_correction
supplies the environment term
, so
the manual recombination of trace and level-shift terms from the original
notebook collapses to a single addition:
Output:
Output:
Summary
This tutorial demonstrated the full projection-based embedding workflow for a water molecule:- Mean-field calculation: A DFT (B3LYP) SCF was run on the full system via
run_dft, yielding converged Kohn-Sham orbitals. - Embedding construction:
run_dft_embeddingpartitioned the occupied space into fragment and environment, built the embedding potential, and produced the second-quantized embedded Hamiltonian. - Validation: Four consistency checks (DFT-in-DFT energy match, trace conservation, probability leak, FCI reference) confirmed the embedding is exact and internally consistent.
- VQE optimization: A UCCS (singles) ansatz was optimized on the embedded Hamiltonian, and the result was evaluated against the physical Hamiltonian to recover the total WF-in-DFT energy.
Technical Notes
Hartree-Fock
The Hartree–Fock method provides an approximate, yet tractable, mean-field solution by representing the many-electron wavefunction as a single Slater determinant. The wave-function is approximated as a product of individual electron wave functions, known as the Hartree product: Since electrons are indistinguishable particles, we must incorporate the particle statistics by anti-symmetrizing the product form. The anti-symmetrization procedure is conveniently expressed in terms of the so-called Slater determinant where is the value of the ‘th spin–orbital evaluated at electron ‘th coordinates, and the prefactor ensures normalization. Each spin-orbital is a product of spatial and spin wave-functions The calculation of the system’s ground state energy and wavefunction is obtained by employing the variational principle:- The best approximation of the ground state wave-function minimizes the energy
- is the Coulomb operator (classical electron–electron repulsion)
- is the exchange operator (arises from antisymmetry).
- A set of basis functions is next defined and the molecular orbitals are expanded as a linear combination of basis functions :
Density functional theory
Density functional theory provides a major computational simplification of the electronic problem. The key insight is that the electron density, which is a function of only three coordinates, contains a lot of information that is actually observable from the full wave function, which is a function of coordinates. The theory is based on two fundamental theorems, proved by Kohn and Hohenberg:- The ground-state energy of the Schrodinger equation is a unique functional of the electron density, .
- The electron density that minimizes the energy of the overall functional is the true electron density, corresponding to the solution of the Schrodinger equation.
- We define an initial, trail electron density .
- Solve the Kohn-Sham equations to find the single-particle wave-function , termed the Kohn-Sham wave-functions.
- Calculate the electron density .
- Check the convergence. If the density converged, stop. Otherwise, update the electron density and return to step
- The major caveat of the theory is that the true form of the energy functional is not known and must be approximated. Luckily, for a uniform electron gas, the functional can be derived analytically, providing an initial approximation for the exchange-correlation potential. By evaluating for a uniform electron gas at the local density, we obtain the so-called local-density approximation (LDA). Alternatively, numerous higher-order approximations offer potentially better results.
Projection-based embedding: detailed derivation
The sections below give the full theory behind the three-step construction summarized in Construction of the Embedding Hamiltonian: partitioning the occupied space into fragment and environment, the projector-based embedding potential, and building the active-space embedded Hamiltonian (including concentric localization of the virtual orbitals). The expression for the embedded system energy, , can be understood as an extension of the DFT-in-DFT scheme. In this framework, one writes the total system energy as . Minimization of the total energy with respect to system’s density matrix, , leads to the expression of the Fock matrix of the embedded system, . Self-consistent optimization of with respect to , recovers subsystem’s original density matrix . In this sense, the embedding method is internally consistent. The expression for involves a costly re-evaluation of the embedding potential in each SCF iteration. Therefore, to bypass the expensive calculation, one expands the embedding potential to first-order, giving Here the embedding potential is , where collects all the two-electron mean-field interactions ( for HF, for DFT). The expression for the total energy of the WF-in-DFT can be understood as a generalization of the DFT-in-DFT method, where the DFT calculation over system is replaced by a correlated wavefunction approach. We divide the WF-in-DFT calculation into three main steps:- Fragmentation of the full system into an active fragment and environment, resulting in localized (or unlocalized) molecular orbitals of the two subsystems.
- The MOs of the first mean-field calculation are then used to evaluate the mean-field embedding potential, , and the associated embedded Fock operator .
- Evaluate the embedded Hamltonian in the optimized MOs basis.
Partition of the occupied orbitals into sub-system A (active fragment) and sub-system B (environment)
Before deriving the embedded Hamiltonian, we first must partition the system’s occupied molecular orbitals to the fragment and environment orbitals. Two possible methods are explored: (1) Fragmentation by localized molecular orbitals, and (2) by atomic orbitals.Fragmentation by localized orbitals
The occupied molecular orbitals are delocalized over the entire molecule because they diagonalize the Fock matrix. But chemically, we know the electrons tend to localize: e.g., each bond or lone pair “belongs” roughly to one region of space. To obtain orbitals that reflect this intuition, we rotate the occupied orbitals among themselves using a unitary transformation that spatially localizes each orbital. Formally, we define a unitary that defines new orbitals: . The localized orbitals (LOs) span the same occupied subspace (the transformation is unitary), but are much more spatially confined. The Boys and Pipek-Mezey localizations correspond to two different optimization procedures leading to an associated . Once one has the localized orbitals, we can define the fragment orbitals as the subset of LOs that are mostly on a given set of atoms. Each LO can be projected onto atoms of the fragment using the Mulliken population on the chosen AO subset which indicates the fraction of the ‘th MO density on the fragment atoms. Next, we select all localized orbitals for which the population is above a certain threshold, , those ‘s correspond to the fragment indices. These indicies allow defining the fragment , and environment , of occupied orbitals , , respectively. Finally, the associated density matrices are evaluated Note that the localization is performed only on the occupied MO’s, localization of virtual (unoccupied) is unstable and may lead to contradictions within the embedding method.Fragmentation by atomic orbital
In this fragmentation procedure, we first partition the atomic orbitals into fragment and environment orbitals. Following, we evaluate the Mulliken populations, , of the molecular orbitals. If is above a predetermined threshold, , the molecular orbital is included within the fragment Hilbert space. Otherwise, it is set as a part of the environment’s Hilbert space. Similarly, to the fragmentation by localized orbital, the partition of molecular orbitals into two sets, defines , , and the associated density matrices , .Projector-based embedding (PBE) via orthogonal complement
The projector-based embedding introduces a projection operator, allowing the construction of the fragment’s embedded Hamiltonian, . This Hamiltonian governs the dynamics of the fragment system, embedded within the environment. The embedded Hamiltonian includes three main physical contributions:- Kinetic and electron nuclei interaction term, included within the one-electron Hamiltonian term and projected onto the fragment’s Hilbert space.
- An embedding potential which represents the effective interaction between the fragment and environment electrons, projected onto the fragment’s Hilbert space.
- The Coulomb repulsion between the fragment electrons.
- Construct the projection operator, , where is the overlap matrix of the full system.
- Evaluate , the form of which depends on the chosen mean field method.
Construct the embedding Hamiltonian
The embedding Hamiltonian is constructed in terms of the system’s MOs, we denote these by :- Occupied (possibly localized) molecular orbitals
- Concentric localized virtual orbitals
Concentric localization of virtual orbitals
The partition of virtual orbitals into active fragment and environment virtual orbitals is achieved through concentric localization, which includes only orbitals that have a large overlap (in a pre-defined sense) with the occupied orbitals of the active fragment. Specifically, we employ a one-shell concentric localization procedure, where one selects the active virtual orbitals as the smallest set of virtual MOs that couple most strongly (via the Fock/overlap metric) to the fragment’s occupied localized orbitals, i.e., the first “shell” of virtuals surrounding the fragment. The calculation includes the following steps:- We first obtain a set of canonical virtual orbitals, which contain all the unoccupied MO orbitals.
C_virt_A, which contains the associated coefficients of the AO basis set.
- Compute the coupling matrix , where the columns of correspond to the active fragment’s occupied MOs, and the columns of correspond to the canonical virtual orbitals .
- Perform a singular value decomposition (SVD) of
M:
sv_tol, for the singular values.
These columns define the active virtual orbitals
Each column of contains the AO coefficients of a linear combination of canonical virtual orbitals with the largest coupling to the occupied space of subsystem , these are the “virtual-concentric localized” orbitals:
- Combine the fragment’s occupied MOs and the concentric localized virtual MOs: