uniqc.algorithms.workflows.vqe_workflow module¶
Lightweight VQE workflow built on ansatz fragments + pauli_expectation.
Unlike uniqc.algorithms.core.training.vqe_torch, this workflow does
not require torch or torchquantum: it uses scipy.optimize for
the classical minimisation step and uniqc.simulator for the quantum part.
Use this when you want a zero-extras VQE driver. Use the torch-based version when you want autodiff parameter-shift gradients and PyTorch interop.
- class uniqc.algorithms.workflows.vqe_workflow.VQEResult(energy, params, history=<factory>, n_iter=0, success=True, message='')[source]¶
Bases:
objectOutcome of
run_vqe_workflow().- Variables:
energy (float) – Final (minimum) energy ⟨H⟩.
params (numpy.ndarray) – Optimal ansatz parameters (numpy array).
history (list[float]) – Per-iteration energies in evaluation order. Useful for convergence plots.
n_iter (int) – Number of objective evaluations.
success (bool) – Whether the underlying scipy optimiser reported success.
message (str) – Optimiser termination message.
- Parameters:
- uniqc.algorithms.workflows.vqe_workflow.run_vqe_workflow(hamiltonian, *, n_qubits=None, ansatz=None, depth=1, ansatz_type='hea', ansatz_options=None, init_params=None, shots=None, method='COBYLA', options=None)[source]¶
Run a scipy-driven VQE on
hamiltonian.- Parameters:
hamiltonian (Sequence[tuple[str, float]]) – Iterable of
(pauli_string, coefficient)pairs. The Pauli string length must matchn_qubits.n_qubits (int | None) – Number of qubits. Required when
ansatzisNone; inferred from the first term’s pauli length otherwise.ansatz (Callable[[ndarray], Circuit] | None) – Optional
params -> Circuitbuilder. IfNonethe workflow uses theansatz_typewithansatz_options.depth (int) – Layers in the default ansatz. Ignored when
ansatzis supplied.ansatz_type (str) – Type of ansatz to use when
ansatzisNone. Options:"hea"(default),"hva","uccsd".ansatz_options (dict | None) – Additional options passed to the ansatz builder. For HEA: supports
rotation_gates,entangling_gate,topology,custom_edges,backend_info.init_params (ndarray | None) – Optional initial parameter vector. If
Nonea small uniform random vector in[-π/8, π/8]is sampled.shots (int | None) – Shots per Pauli-term expectation.
Noneuses the analytic statevector estimator (recommended for early development).method (str) –
scipy.optimize.minimizemethod.COBYLAandPowellare good gradient-free choices; switch toL-BFGS-Bonly when you supply a custom analytical gradient viaoptions.options (dict | None) – Optional dict forwarded to
scipy.optimize.minimize. Defaults to{"maxiter": 200, "rhobeg": 0.1}for COBYLA.
- Returns:
VQEResultwith the minimum energy and parameters.- Return type:
Example
>>> # H = -1.0523 ZZ + 0.39793 ZI - 0.39793 IZ + 0.18093 XX >>> H = [("ZZ", -1.0523), ("ZI", 0.39793), ... ("IZ", -0.39793), ("XX", 0.18093)] >>> result = run_vqe_workflow(H, n_qubits=2, depth=2) >>> result.energy < -1.0 True
With enhanced HEA options: >>> result = run_vqe_workflow( … H, n_qubits=2, depth=2, … ansatz_type=”hea”, … ansatz_options={“rotation_gates”: [“rx”, “ry”], “entangling_gate”: “cz”}, … )