Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
Functions | Variables
shot_noise_measurement Namespace Reference

Functions

def generate_zz_xx_hamiltonian (n_qubits, h=0.5, topology=None, Jz=1.0, Jx=1.0, Jy=1.0)
 
def main ()
 

Variables

 linewidth
 

Detailed Description

Heisenberg VQE example and shot-noise energy estimator.

This example constructs a Heisenberg-style Hamiltonian (ZZ/XX/YY couplings
plus local Z fields), builds an instance of the C++-backed
`qgd_Variational_Quantum_Eigensolver_Base` wrapper, applies a parameterized
ansatz, and demonstrates both exact (ideal) and shot-noise energy estimation.

The file shows how to format the term lists passed to the C++ wrapper:
`zz_terms`, `xx_terms`, `yy_terms` each contain items of the form
`{"i": int, "j": int, "coeff": float}` and `z_terms` contains
`{"i": int, "coeff": float}`. The shot-noise API expects a dictionary
containing these lists together with `shots`, `p_readout`, and `seed`.

This script is intended for interactive runs and manual inspection. For
lightweight automated checks that do not require compiling the native
extension, see `tests/VQE/test_shot_noise_measurement.py` which provides
fallback implementations and fast unit tests.

Function Documentation

◆ generate_zz_xx_hamiltonian()

def shot_noise_measurement.generate_zz_xx_hamiltonian (   n_qubits,
  h = 0.5,
  topology = None,
  Jz = 1.0,
  Jx = 1.0,
  Jy = 1.0 
)
Create a Heisenberg-like Hamiltonian and a Pauli-format oplist.

The Hamiltonian built is:
    H = sum_{(i,j) in topology} [ Jz Z_i Z_j + Jx X_i X_j + Jy Y_i Y_j ]
        + sum_i h_i Z_i

Parameters
----------
n_qubits : int
    Number of qubits in the system.
h : float or array-like, optional
    Local Z field magnitude (scalar for uniform field or array-like for
    per-qubit fields). Default 0.5.
topology : sequence of (i, j) pairs, optional
    Edge list describing which qubit pairs are coupled. If ``None``, a
    nearest-neighbour ring topology is used.
Jz, Jx, Jy : float, optional
    Coupling strengths for the ZZ, XX and YY terms respectively.

Returns
-------
H_sparse : scipy.sparse.csr_matrix
    The full Hamiltonian as a sparse matrix in the computational (Z)
    basis. Suitable for small-system exact calculations.
oplist : list
    A list of tuples describing Pauli terms in the form expected by the
    wrapper and by :class:`qiskit.quantum_info.SparsePauliOp`:
    ("ZZ", [i, j], coeff), ("XX", [i, j], coeff), ("YY", [i, j], coeff),
    and ("Z", [i], coeff).

Notes
-----
The returned ``oplist`` is used to build dictionaries passed to the C++
wrapper shot-noise routine (see ``zz_terms_for_dict`` etc. in
:func:`main`). The sparse Hamiltonian is convenient for exact energy
evaluation using ``scipy.sparse.linalg.eigsh`` for small systems.

Definition at line 38 of file shot_noise_measurement.py.

Here is the caller graph for this function:

◆ main()

def shot_noise_measurement.main ( )
Run a full VQE example and shot-noise energy estimation.

Workflow:
- Build a Heisenberg Hamiltonian and decompose it to term lists
  consumable by the C++ wrapper.
- Instantiate the wrapped VQE object and configure optimizer/ansatz.
- Generate and apply the circuit to obtain the final state |psi>.
- Compute exact (ideal) energies and per-term contributions.
- Run the shot-noise estimator via the wrapper and print a summary.

This function prints human-readable diagnostics. For automated tests
prefer using the unit-tests under ``tests/VQE`` which include
lightweight fallbacks when the native extension is unavailable.

Definition at line 110 of file shot_noise_measurement.py.

Here is the call graph for this function:

Variable Documentation

◆ linewidth

shot_noise_measurement.linewidth

Definition at line 29 of file shot_noise_measurement.py.