qcmet.benchmarks.VQE#
- class qcmet.benchmarks.VQE(VQEName, qubits, hamiltonian=None, ansatz=None, init_circuit=None, n_layers=1, seed=None, save_path=None)[source]#
Variational Quantum Eigensolver (VQE) benchmark class.
This class implements a general VQE bencharking workflow, including estimating the ground state energy of a given Hamiltonian using a parameterized ansatz and initialization circuits and compares the result to the exact energy expectation value.
Concrete VQE instances should either inherit from this base class and overwrite the hamiltonian, _apply_ansatz_circuit and initial_state properties/functions, or pass in the hamiltonian (as openfermion.QubitOperator), ansatz (as qiskit circuit), and init_circuit (as qiskit circuit) components into the constructor.
- __init__(VQEName, qubits, hamiltonian=None, ansatz=None, init_circuit=None, n_layers=1, seed=None, save_path=None)[source]#
Initialize the VQE benchmark instance with configuration and circuits.
Stores the Hamiltonian, ansatz, and initial circuit, if these are not passed in, the respective properties/functions should be overwritten in inheriting classes. Sets the number of layers for the application of the variational ansatz.
- Parameters:
VQEName (str) – Name identifier for the VQE instance.
hamiltonian (openfermion.QubitOperator, optional) – Hamiltonian to be evaluated.
ansatz (QuantumCircuit, optional) – Single layer of the ansatz circuit.
init_circuit (QuantumCircuit, optional) – Initial state preparation circuit.
n_layers (int) – Number of ansatz layers to apply.
seed (int, optional) – Seed used for initialization of random parameters.
save_path (str | Path | FileManager | None, optional) – Directory path to save results. Defaults to None.
Methods
__init__(VQEName, qubits[, hamiltonian, ...])Initialize the VQE benchmark instance with configuration and circuits.
analyze()Analyze measurements to return benchmark results.
generate_circuits()Generate benchmark circuits, user facing.
Compute the expectation value of the Hamiltonian from shot data.
has_plotting()Check if _plot function is implemented in benchmark.
load_circuit_measurements(circuit_measurements)Load measurement counts into the experiment_data DataFrame.
measurements_to_probabilities()Convert raw measurement counts to normalized probabilities.
plot([axes])Plot benchmark result, user facing.
run([device, num_shots, max_circs_per_job])Run benchmark.
save()Save benchmark current state.
set_save_path(save_path)Set benchmark save path if not set in class constructor.
Compute the expectation value of the Hamiltonian using statevector simulation.
Attributes
circuitsGets all benchmark circuits.
experiment_dataGetter for experiment_data dataframe.
Accessor for the full ansatz circuit (init + layers).
Accessor for the Hamiltonian.
Return the initial quantum circuit for state preparation.
num_qubitsNumber of qubits in this benchmark.
Get or initialize the variational parameters for the ansatz circuit.
- property variational_parameters#
Get or initialize the variational parameters for the ansatz circuit.
This property ensures that the ansatz circuit is set up before accessing the parameters. If the parameters have not been initialized yet, it generates a random vector of appropriate length and stores it.
- Returns:
The current variational parameters.
- Return type:
np.ndarray
- property full_ansatz_circuit#
Accessor for the full ansatz circuit (init + layers).
- Returns:
The full quantum circuit ansatz.
- Return type:
QuantumCircuit
- statevector_energy()[source]#
Compute the expectation value of the Hamiltonian using statevector simulation.
- Returns:
Real-valued energy expectation from the simulated statevector.
- Return type:
- property hamiltonian#
Accessor for the Hamiltonian.
- Returns:
The Hamiltonian as an OpenFermion qubit operator.
- Return type:
openfermion.QubitOperator
- get_energy()[source]#
Compute the expectation value of the Hamiltonian from shot data.
Uses measurement probabilities and parity to evaluate each Pauli-string expectation value.
- Returns:
The estimated energy value from device measurements.
- Return type:
- property initial_state#
Return the initial quantum circuit for state preparation.
- Returns:
The initial state circuit or a default empty circuit.
- Return type:
QuantumCircuit