Preparing the trial state
Chapter focus
How do we prepare a state that lets phase estimation return the ground-state energy reliably?
Learning objectives
After completing this chapter, you will be able to:
Explain why phase estimation requires an input state.
Define state overlap and fidelity.
Explain how ground-state fidelity measures target-state weight and influences phase-estimation outcomes.
Construct a sparse trial wavefunction from important determinants.
Generate a state-preparation logical circuit with the QDK/Chemistry sparse-isometry implementation.
Distinguish trial-state quality from state-preparation logical circuit cost.
Lab notebook assignment
Complete Trial state. Record trial-state fidelity and state-preparation logical circuit statistics as separate quantities. Explain how determinant truncation changes the ground-state weight, its influence on phase-estimation outcomes, and the cost of preparing the trial state.
Example download
Download tutorial_prepare_trial_state.py and tutorial_prepare_trial_state.ipynb, and save both files in the tutorial working directory that contains tutorial_choose_active_space.py and tutorial_orbital_coordinates.py.
Open the files in Visual Studio Code and review the complete trial-state script, including imports and helper functions omitted from the excerpts below.
The script imports the tested active-space workflow so that this chapter uses the same selected Hamiltonian and CASCI reference.
The Jupyter notebook runs that workflow, renders the one-, two-, and four-determinant logical circuits, and validates their reported structure and gate statistics.
Connection to the selected-space workflow
The selected-space CASCI calculation produced a normalized ground-state wavefunction spanning the \((n_\alpha,n_\beta)=(3,3)\) determinant sector introduced in Mapping the problem to qubits. Each determinant represents one pattern of occupations among the selected active spin orbitals, and its coefficient is the corresponding amplitude in the wavefunction. The Jordan–Wigner encoding represents the same occupation patterns on the compute register sized in Mapping the problem to qubits.
Why phase estimation needs a trial state
Quantum phase estimation (QPE) estimates an eigenphase of a unitary operator. For molecular energies, that unitary represents evolution under the Hamiltonian: each Hamiltonian eigenstate is also an eigenstate of the time-evolution operator, and its phase depends on its energy. The phase-to-energy relationship and the QPE logical circuit are developed in the next chapter. For now, the important point is that the compute register must contain a chosen quantum state before phase estimation can begin.
A state-preparation logical circuit initializes the compute register in this chosen normalized quantum state. Here, logical means gates in the generated algorithmic circuit before error-correction code synthesis and hardware mapping. This input is the trial state. It is an approximation intended to contain a substantial contribution from the target ground state; QPE cannot begin from an unspecified state or create the ground state by searching through all possible wavefunctions.
The trial state can be written as a linear combination of the eigenstates \(\{\vert\Psi_j\rangle\}\) of the active-space Hamiltonian:
To isolate the effect of the input state, first assume that the requested trial state is prepared exactly, time evolution is exact, and phase readout has enough resolution to distinguish the relevant eigenphases. Under these assumptions, an input eigenstate \(\vert\Psi_j\rangle\) produces the phase corresponding to \(E_j\). For a trial state containing several eigenstates, a textbook coherent phase-estimation measurement samples the energy \(E_j\) with probability \(\left\vert a_j\right\vert^2\) [vBLHaner+21]. This probability statement assumes that one prepared system state produces one complete phase result.
Why can phase estimation return an excited-state energy even when the ground-state energy is the target?
A trial state can contain both ground- and excited-state eigenvectors. Under the assumptions above, phase estimation returns each represented eigenvalue with probability equal to the squared magnitude of that eigenstate’s amplitude in the trial state.
Ground-state fidelity
As introduced in the tutorial overview, the ground-state fidelity is the squared overlap
Both states are normalized, so \(0\leq F\leq 1\). The fidelity \(F\) is the weight of the target ground state in the trial-state eigenstate expansion. For the textbook coherent measurement described above, it is also the probability of sampling the ground-state eigenphase.
The QDK/Chemistry iterative quantum phase estimation (IQPE) implementation used later performs a different sampling procedure. Each phase bit is one binary digit of the estimated phase fraction. The implementation builds a separate circuit for each phase bit, and every circuit execution freshly prepares the trial state. Each phase bit is selected by a majority vote over a specified number of circuit executions, then used as feedback for the next bit. The final bit string therefore combines bitwise decisions from many state preparations rather than recording one eigenstate sample.
Fidelity remains a useful trial-state quality measure because it controls the ground-state contribution to those bit statistics. However, it is not by itself the probability that one complete implemented IQPE run returns the ground-state energy, so it does not determine a trial count. The complete result also depends on the other eigenstate weights and phases, the number of phase bits, shots per bit, phase feedback, and the Hamiltonian-simulation approximation. The next chapter develops this bitwise sampling procedure and evaluates repeated complete IQPE runs.
Imperfect logical state preparation can also change the state actually loaded. Residual logical faults after error correction can introduce further errors on a fault-tolerant machine, but they are not modeled by this tutorial’s simulator. These effects should be evaluated separately from the fidelity of the intended trial state.
A sparse trial wavefunction
The selected-space CASCI wavefunction is classically tractable in this teaching example, so it provides a controlled reference for comparing trial states.
The script ranks its determinants by coefficient magnitude and retains the largest one, two, or four.
These determinant counts are examples rather than restrictions of the projected calculation or state-preparation method.
To compare other choices, change determinant_counts in the Jupyter notebook and rerun its cells.
In a larger problem where exact CASCI is unavailable, an approximate classical method must supply the candidate determinants and amplitudes for the trial state.
The script first prints the leading terms in the selected-space wavefunction.
Each occupation string contains one symbol for each selected active spatial orbital: 2 means doubly occupied, u means occupied by one \(\alpha\) electron, d means occupied by one \(\beta\) electron, and 0 means unoccupied.
The amplitude is the signed coefficient \(c_I\) in \(\vert\Psi_0\rangle=\sum_I c_I\vert\Phi_I\rangle\), while the weight \(\left\vert c_I\right\vert^2\) is that determinant’s contribution to the squared norm.
The cumulative weight shows how much of the norm is captured by the listed determinants.
The script computes these quantities directly from the leading CASCI coefficients.
Simply discarding coefficients and renormalizing would not optimize the wavefunction within the retained determinant space because the full-space amplitudes are not generally the amplitudes that minimize energy after determinants are removed. A projected multi-configuration (PMC) calculation is a configuration-interaction calculation restricted to a user-specified set of determinants. The QDK/Chemistry PMC calculator instead constructs the Hamiltonian matrix in the retained determinant space and solves its eigenvalue problem for the lowest-energy normalized eigenvector. The resulting projected wavefunction has zero amplitude on every omitted determinant. When using the projected wavefunction as a trial state, its overlap with the complete selected-space CASCI wavefunction therefore quantifies how much fidelity is retained after determinant truncation.
Under the Jordan–Wigner encoding, each retained determinant becomes one computational-basis state of the compute register. The trial wavefunction is therefore
where \(\vert b_I\rangle\) is the occupation bitstring for retained determinant \(\Phi_I\), and \(\widetilde{c}_I\) is its reoptimized amplitude.
The script constructs each projected trial state, forms the reference and trial coefficient vectors for the same retained determinants, and evaluates their squared inner product directly:
# The leading reference determinants define the trial-state support;
# PMC then reoptimizes their amplitudes within that restricted space.
top_determinants = leading_determinants(
reference_wavefunction, num_determinants
)
projected_calculator = create(
"projected_multi_configuration_calculator", "macis_pmc"
)
_, trial_wavefunction = projected_calculator.run(
active_hamiltonian, list(top_determinants)
)
retained_determinants = trial_wavefunction.get_active_determinants()
# Read both vectors in PMC determinant order. Without this alignment,
# np.vdot() could multiply coefficients belonging to different determinants.
reference_coefficients = np.asarray(
[
reference_wavefunction.get_coefficient(determinant)
for determinant in retained_determinants
]
)
trial_coefficients = np.asarray(
[
trial_wavefunction.get_coefficient(determinant)
for determinant in retained_determinants
]
)
# The trial vector is normalized on the retained support. The reference
# entries keep their full-state normalization, so their restricted norm
# records weight omitted by truncation.
fidelity = float(abs(np.vdot(reference_coefficients, trial_coefficients)) ** 2)
Why must fidelity be calculated separately from the PMC energy?
The PMC calculation chooses the lowest-energy wavefunction within the retained determinant space, but it does not directly maximize overlap with the complete selected-space ground state. Energy and overlap measure different properties, so the script evaluates fidelity explicitly.
The trial state preparation logical circuit
The QDK/Chemistry sparse-isometry implementation converts the retained determinants into a binary matrix whose rows represent qubits and whose columns represent occupied-or-unoccupied patterns. The method uses binary row operations to reduce the determinant patterns while recording controlled-NOT (CNOT) and X operations, prepares the reduced set of amplitudes, and reverses the recorded operations to expand the state across the compute register, in an optimized version of approaches introduced by Malvetti et al. [MIC21]. Students do not need to reproduce this synthesis by hand; it is implemented natively in QDK/Chemistry. The important input is the normalized sparse wavefunction and the output is a logical circuit that prepares its amplitudes on the corresponding occupation states.
Some compute-register wires may have no gates in the state-preparation circuit. The register begins in the all-zero occupation state, so a wire needs no preparation operation when the selected sparse wavefunction does not require that occupation bit to change or become entangled. This does not make the qubit unnecessary: every compute qubit represents an active spin orbital on which the mapped active-space Hamiltonian acts. The later controlled time evolution in QPE therefore requires the complete compute register and can couple the prepared determinant support to other configurations in the same sector. Removing a gate-free preparation wire would change the Hamiltonian representation and the molecular problem, rather than merely simplify state preparation.
Before answering the next question, download and open tutorial_prepare_trial_state.ipynb in Visual Studio Code.
Save it in the tutorial working directory alongside tutorial_prepare_trial_state.py, tutorial_choose_active_space.py, and tutorial_orbital_coordinates.py.
Choose Select Kernel, select Python Environments, and choose the .venv environment created in Before you begin.
Then select Run All to execute the shared trial-state workflow and render the one-, two-, and four-determinant logical circuits.
Compare the gate types and circuit structure before revealing the answer below.
Generated logical state-preparation circuits for the one-determinant trial state (left) and two-determinant trial state (right). Both use the same twelve-qubit compute register; the additional operations prepare multiple amplitudes rather than additional spin orbitals.
Why does one-determinant state preparation look so different from multi-determinant preparation?
One determinant is one occupation bit string and therefore one computational-basis state. Starting from the all-zero state, X gates only need to flip the qubits representing occupied spin orbitals. A multi-determinant wavefunction is instead a coherent superposition of distinct occupation bit strings. Because X gates can only map one basis state to another, rotations are needed to create amplitudes, phase operations establish relative signs or phases, and entangling gates correlate occupation changes across qubits. The exact gate sequence depends on the synthesis method, but the distinction between preparing one basis state and preparing a coherent superposition is general.
To measure the generated logical-circuit cost, the script traverses the decomposed Q# circuit representation, counts displayed gate records that have no nested child operations, and identifies controlled X gates as CNOT gates. The script creates the QDK/Chemistry sparse-isometry implementation and inspects the generated Q# logical circuit. The factory key sparse_isometry_gf2x is the implementation’s current API identifier using a helper function to count gates:
state_preparation = create("state_prep", "sparse_isometry_gf2x")
circuit = state_preparation.run(trial_wavefunction)
num_compute_qubits, num_logical_gates, logical_gate_counts = circuit_statistics(
circuit
)
The reported preparation logical gate count is the number of these childless gate records in the generated Q# logical-circuit representation after the state-preparation operation has been decomposed. This software-level logical gate count is not logical-circuit depth, a fault-tolerant resource estimate, or a physical-resource estimate. It can change if the state-preparation or circuit-decomposition implementation changes; error correction affects downstream fault-tolerant and physical costs instead.
Trial-state quality and preparation cost
Trial-state truncation introduces a separate cost–quality tradeoff within the selected active space. Retaining more determinants can improve fidelity with the selected-space ground state, but preparing more nonzero amplitudes generally requires more logical gates. The relevant question is therefore how much fidelity is gained for each increase in state-preparation cost.
All three trial states describe the same selected active spin-orbital space, so they use the same compute register size. Changing the number of retained determinants changes amplitudes and logical-circuit structure, not the number of spin orbitals represented.
Does retaining more determinants require more compute qubits?
No. Each trial state represents the same selected active spin-orbital space, so the compute-register size is unchanged. The number of retained determinants affects state-preparation operations rather than the compute-register size.
Running the preparation
With the Python environment from Before you begin active, run the complete script from the Visual Studio Code integrated terminal:
python tutorial_prepare_trial_state.py
How do fidelity and preparation cost change as determinants are retained?
The one-, two-, and four-determinant fidelities are approximately \(0.4825\), \(0.5864\), and \(0.7324\), respectively. Their generated logical circuits have preparation logical gate counts of 6, 14, and 30, respectively, while every logical circuit uses twelve compute qubits. From one to two determinants, fidelity increases by approximately \(0.104\) while the gate count increases by eight. From two to four determinants, fidelity increases by approximately \(0.146\) while the gate count increases by sixteen. For these three generated circuits, the second expansion provides less fidelity gain per additional preparation gate than the first.
What does the single-determinant fidelity reveal about multireference character?
Its fidelity is approximately \(0.4825\), equal to the weight of the leading 222000 determinant.
No single determinant therefore carries a majority of the selected-space ground-state weight at this geometry.
The substantial weight distributed among additional determinants provides direct evidence of multireference character in the selected active-space orbital representation.
Record the leading reference determinants and all three determinant counts, fidelities, compute-qubit counts, preparation logical gate counts, and logical gate-family counts in the trial-state section of the lab notebook. Explain what the leading determinant weight reveals about multireference character, and distinguish the fidelity improvement from the increased logical-circuit cost. The final IQPE calculation uses the four-determinant trial state. In the lab notebook, use your measured fidelities and preparation logical gate counts to evaluate this choice and describe what would be gained or lost by using one of the smaller trial states instead.