Calculate Energies With PRIME-SqDRIFT and QSCI

Note

This is a how-to guide on the quantum-selected configuration interaction (QSCI) calculators. For the background, see QSCI, SqDRIFT and PRIME-SqDRIFT.

Goal

Calculate ground state energies with PRIME-SqDRIFT enhancements, baseline SqDRIFT or custom QSCI, and the lowest state energies with baseline SqDRIFT or custom QSCI.

Prerequisites

Overview of the QSCI calculators

All QSCI calculators start from qc.calculator_creator().quantum_selected_configuration_interaction(), and are selected with one of:

Selector

Calculator

.sqdrift()

SqDRIFT: Krylov-subspace QSCI where the Krylov states are prepared with qDRIFT time evolution.

.prime_sqdrift()

PRIME-SqDRIFT enhancements: Kvantify’s proprietary SqDRIFT functionality.

.custom()

Custom QSCI: choose the subspace state generator yourself (Krylov with qDRIFT, or the identity generator, which samples only the reference circuit).

Steps

  1. Calculate with SqDRIFT

    import qrunch as qc
    
    calculator = (
        qc.calculator_creator()
        .quantum_selected_configuration_interaction()
        .sqdrift()
        .create()
    )
    result = calculator.calculate(ground_state_problem)
    print(f"Total energy = {result.total_energy:.6f}")
    

    The result is a QuantumSelectedConfigurationInteractionGroundStateProblemCalculatorResult. Reaction path problems are also supported.

    Besides the energies, every QSCI result has a run_summary (SamplingRunSummary) describing the sampling:

    summary = result.run_summary
    print(f"{summary.number_of_circuits} circuits, {summary.number_of_shots} shots requested")
    print(f"{summary.number_of_kept_shots} shots kept after error mitigation")
    print(f"{summary.number_of_determinants} determinants in the final subspace")
    print(f"{summary.number_of_determinants_outside_reference_sector} sampled determinants outside the reference sector")
    

    A large number of determinants outside the reference sector (wrong numbers of alpha or beta electrons) points to hardware noise. For a reaction path, each geometry’s result has its own run_summary.

  2. Tune SqDRIFT

    Set the qDRIFT compilation and Krylov sequence options with SqDriftOptions. Set the time step, sampler and number of shots per circuit on the builder:

    options = qc.options.SqDriftOptions(
        subsequence_length=20,
        maximum_krylov_order=3,
        number_of_randomizations=5,
        seed=42,
    )
    
    calculator = (
        qc.calculator_creator()
        .quantum_selected_configuration_interaction()
        .sqdrift()
        .with_options(options)
        .with_time_step(0.5)
        .with_shots_per_circuit(1000)
        .with_sampler(my_sampler)
        .create()
    )
    

    with_time_step(time_step) sets the interval \(\tau\) between Krylov evolution times. Order \(k\) evolves for \(k\tau\). The time step must be positive and finite and defaults to 1.0.

    With one reference, the Krylov circuits use maximum_krylov_order * number_of_randomizations * shots_per_circuit shots. The default sampler is a memory-restricted simulator; see Create a Sampler for alternatives, including hardware.

    Increasing maximum_krylov_order, number_of_randomizations and subsequence_length generally improves the energy, at the cost of more circuits and deeper circuits. See QSCI, SqDRIFT and PRIME-SqDRIFT for what each option does.

  3. Calculate with PRIME-SqDRIFT enhancements

    PRIME-SqDRIFT brings together Kvantify’s proprietary SqDRIFT functionality. The .prime_sqdrift() selector configures these enhancements. It takes the same SqDriftOptions via with_sqdrift_options and supports the same with_time_step setting, plus options controlling the adaptive run:

    calculator = (
        qc.calculator_creator()
        .quantum_selected_configuration_interaction()
        .prime_sqdrift()
        .with_sqdrift_options(
            qc.options.SqDriftOptions(
                maximum_krylov_order=3,
                number_of_randomizations=10,
                use_qeb_gates=False,
            )
        )
        .with_time_step(0.5)
        .with_update_frequency(5)
        .with_passes(2)
        .with_disconnected_reference(include=False)
        .create()
    )
    

    Available builder methods in addition to with_sampler, with_shots_per_circuit and with_time_step:

    • with_sqdrift_options(options): the SqDRIFT settings, including use_qeb_gates (default True). Set it to False to use fermionic term evolution instead of qubit-excitation-based (QEB) gates.

    • with_update_frequency(n): number of circuits sampled between updates of the sampling strategy (default 10).

    • with_passes(passes): number of passes over the Krylov sequence (a positive integer, default 1). Each additional pass samples another full sequence while continuing the adaptive run.

    • with_disconnected_reference(include=...): when enabled (default True), prepare the initial reference as a superposition of Hartree-Fock and the lowest-diagonal-energy spin-conserving single excitation in a disconnected sector, if its diagonal energy is below Hartree-Fock’s. Set include=False to start from Hartree-Fock alone.

    • with_state_encoding_options(beam_search_options, minimum_state_encoding_coefficient=1e-4): re-encode the

      subspace ground state in the reference state. Enabled by default; improves accuracy but deepens circuits.

    • disable_state_encoding(): skip re-encoding and reuse the initial reference (shallower circuits).

    • with_minimum_determinant_weight(w): Do not consider determinants with weight \(c_d^2 < w\) when performing Hamiltonian term reweighing.

    • with_natural_orbital_transformation(...) / disable_natural_orbital_transformation(): rotate to natural

      orbitals at each update (disabled by default).

    Note

    Adaptive updates repeatedly diagonalize the subspace found so far, adding classical cost compared with baseline SqDRIFT. Pruning and natural orbitals can reduce this cost.

    PRIME-SqDRIFT can also report its adaptive updates; see the step on following the progress of a run below.

  4. Calculate with a custom QSCI calculator

    With .custom() you pick the subspace state generator with .choose_subspace_state_generator():

    calculator = (
        qc.calculator_creator()
        .quantum_selected_configuration_interaction()
        .custom()
        .choose_subspace_state_generator()
        .krylov_qdrift(maximum_krylov_order=3, time_step=1.0, number_of_randomizations=2, qdrift_subsequence_length=8)
        .with_shots_per_circuit(500)
        .create()
    )
    

    Use .identity() instead of .krylov_qdrift(...) to sample only the reference state (plain QSCI). Unlike .sqdrift(), this builder exposes the generator settings directly instead of via SqDriftOptions.

  5. Start from a VQE result

    By default, the Krylov circuits start from the Hartree-Fock state. All QSCI calculators can instead start from a better state, such as an orbital-optimized BEAST (OO-BEAST) result, by passing it as initial_vqe_result:

    beast_result = (
        qc.calculator_creator()
        .vqe()
        .iterative_with_orbital_optimization()
        .beast()
        .create()
        .calculate(ground_state_problem)
    )
    calculator = (
        qc.calculator_creator()
        .quantum_selected_configuration_interaction()
        .prime_sqdrift()
        .create()
    )
    result = calculator.calculate(ground_state_problem, beast_result)
    

    The final state of the VQE result is the reference evolved by the Krylov circuits, and its final operator, which holds the orbital-optimized orbitals for OO-BEAST, defines the Hamiltonian. A paired-electron result, such as BEAST, is converted to fermions unless the calculator uses the paired-electron approximation. For a reaction path problem, pass the reaction path result of the VQE calculator.

    The reported initial (Hartree-Fock) energy is still that of the input problem in its original orbitals. The VQE state is not a single determinant, so it is sampled once with the calculator’s sampler, and the disconnected reference enhancement of PRIME-SqDRIFT is skipped. For baseline SqDRIFT, the VQE state replaces the reference circuit providers, so initial_vqe_result cannot be combined with .choose_reference_circuit_providers().

  6. Calculate the lowest states

    SqDRIFT and custom QSCI can also calculate the energies of the lowest states, the ground state included. Use lowest_states_calculator_creator() to select only calculators supporting the lowest states; the paths and builders are the same as from calculator_creator(). Pass n_lowest to calculate():

    calculator = (
        qc.lowest_states_calculator_creator()
        .quantum_selected_configuration_interaction()
        .sqdrift()
        .with_options(qc.options.SqDriftOptions(maximum_krylov_order=3, number_of_randomizations=10))
        .with_shots_per_circuit(1000)
        .create()
    )
    result = calculator.calculate(ground_state_problem, n_lowest=3)
    print(f"Total energies = {result.total_energies}")
    

    The result is a QuantumSelectedConfigurationInteractionLowestStatesResult with one run_summary shared by all the states, or a ReactionPathLowestStatesResult for a reaction path problem. Use .custom() instead of .sqdrift() for custom QSCI. Its generator must sample determinants spanning the excited states, e.g. .krylov_qdrift(...); the identity generator only samples the reference state, so it cannot give more than one state. The enhanced PRIME-SqDRIFT calculator currently supports only the ground state.

Follow the progress of a run

Baseline SqDRIFT, enhanced PRIME-SqDRIFT and custom QSCI all accept a callback in calculate(). The callback object’s record_circuit_sampled method is called with named metrics after every sampled circuit. This works for ground-state and lowest-states calculations.

class PrintProgress:
    def record_circuit_sampled(self, *, number_of_circuits: int, **_other_metrics: object) -> None:
        print(f"{number_of_circuits} circuits sampled")

result = calculator.calculate(ground_state_problem, n_lowest=2, callback=PrintProgress())

Each keyword argument is an integer. Name only the metrics you read and accept the rest with **_other_metrics so new metrics do not break your callback:

  • number_of_circuits: circuits sampled so far.

  • number_of_shots: shots requested across those circuits.

  • number_of_kept_shots: shots kept after error mitigation, such as post-selection.

  • number_of_determinants: determinants in the current subspace.

  • number_of_determinants_outside_reference_sector: distinct sampled determinants whose alpha and beta electron counts do not match those of any reference determinant.

Use it to follow progress on hardware, spot noise, and see when the subspace stops growing. Along a reaction path, the counts restart for every geometry. A callback that raises stops the run.

SHARP-qDRIFT (ground state only) also reports every update of its sampling strategy. Its callback has both hooks, as documented by SubspaceUpdateCallback, also available in qrunch.type_defs:

class PrintSharpProgress(PrintProgress):
    def record_subspace_update(
        self,
        update_index: int,
        number_of_circuits_sampled: int,
        subspace_size_before_update: int,
        subspace_size_after_update: int,
        energy: float,
    ) -> None:
        print(f"Update {update_index}: {number_of_circuits_sampled} circuits, energy {energy:.6f}")

result = sharp_calculator.calculate(ground_state_problem, callback=PrintSharpProgress())

The update energy is the lowest eigenvalue of the active space Hamiltonian, so it excludes the nuclear repulsion and non-active electron energies included in result.total_energy. SqDRIFT and custom QSCI have no updates, so they report no energy during the run.

Choosing reference circuits

SqDRIFT evolves and samples reference states to find determinants for its diagonalization subspace. The reference circuits therefore influence which states the calculation can resolve: a reference family with insufficient support for an excited state cannot be repaired simply by increasing the shot count. Using several references can help cover more of the low-energy states.

Select a reference family with .choose_reference_circuit_providers() on the SqDRIFT builder. Each choice returns to the calculator builder. Calling it again replaces the previous family, rather than appending providers. Built-in choices require no provider implementation imports.

Available choices

  • hartree_fock(): a single Hartree-Fock (HF) reference. This remains the default and is the simplest starting point for ground-state calculations, but may provide insufficient support for excited states.

  • configuration_interaction_singles(number_of_references=None, ...): HF followed by the lowest configuration interaction singles (CIS) states, prepared approximately as circuits. CIS diagonalizes the Hamiltonian in the space of single excitations and does not require dipole transition strength. With None, the reference count follows the requested number of states, including HF; an explicit count also includes HF. The count is capped by the available single-excitation space.

  • dipole(axis=None, ...): HF followed by usable X/Y/Z dipole-excited references. These favor bright, singles-like states and require dipole integrals. There are at most four references, independently of n_lowest. Set axis="x", "y" or "z" to use only one direction alongside HF.

  • custom(providers): a nonempty sequence of custom providers implementing qc.type_defs.ReferenceCircuitProvider.

Recommendation

For excited-state calculations, we recommend starting with configuration_interaction_singles(number_of_references=None). It adapts the reference count to the requested states and, unlike the dipole family, is not limited to three excitation directions or to states with dipole transition strength:

import qrunch as qc

calculator = (
    qc.lowest_states_calculator_creator()
    .quantum_selected_configuration_interaction()
    .sqdrift()
    .choose_reference_circuit_providers()
    .configuration_interaction_singles(number_of_references=None)
    .with_shots_per_circuit(1000)
    .create()
)
result = calculator.calculate(ground_state_problem, n_lowest=3)

CIS is still a singles-based approximation, not a guarantee of support for every requested state. States with substantial double-excitation character or other missing reference support may require a different reference strategy. Preparing many or dense reference states also has a classical and circuit-depth cost.

Preparation and sampling cost

For CIS and dipole references, minimum_coefficient controls compression of normalized amplitudes (default 1e-4). state_preparation_options accepts qc.options.FixedParticleNumberStatePrepBeamSearchOptions to control approximate circuit preparation. Increasing compression can shorten circuits at the cost of reference fidelity.

All reference samples are pooled for one multi-root diagonalization. With multiple references the total shot count is number_of_references * maximum_krylov_order * number_of_randomizations * shots_per_circuit. Here, number_of_references is the actual number of reference circuits, which may differ from the requested state count. Reference selection, requested energies and sampling/evolution settings remain separate controls.

Dipole-specific requirements and limitations

The dipole provider keeps HF first, followed by the usable selected Cartesian directions. Zero directions and duplicate normalized states are omitted with warnings, never replaced by extra HF copies. HF remains present even when every direction vanishes. Paired-electron dipole preparation is unsupported.

Each added reference approximates the normalized state obtained by applying the signed fermionic dipole operator to HF and removing its HF component. Nuclear and frozen-electron scalar contributions are not stored: they vanish under that projection. The matrices alone are not a total molecular dipole moment.

Compression fidelity is logged, and preparation budgets too small to reach the retained support produce a warning. This family does not systematically cover dark states, additional sectors, or double-excitation character. Preparing dense dipole states can be expensive, even though the number of directions is small.

Choosing between the calculators

  • Start with .sqdrift(): it has few options and a modest classical cost.

  • Enable PRIME-SqDRIFT enhancements with .prime_sqdrift() for harder problems when baseline SqDRIFT needs

    many samples to converge, or you want to improve accuracy at a fixed gate budget and / or circuit depth.

  • Use .custom() for plain QSCI or to experiment with generator settings.

Other calculators available on calculator_creator() are described in Build a VQE Calculator; classical references (CI, MP2, CC) are covered in Calculate Classical Reference Energies (CI, CC).

See Also