VQEHyperparameterSweep¶
- class VQEHyperparameterSweep(ansatze, molecule_transformer=None, hamiltonians=None, optimizer=None, max_iterations=10, **kwargs)[source]¶
Bases:
ProgramEnsembleAllows user to carry out a grid search across different values for the ansatz and the bond length used in a VQE program.
Initialize a VQE hyperparameter sweep.
- Parameters:
ansatze (
Sequence[Ansatz]) – A sequence of ansatz circuits to test.hamiltonians (
Sequence[Operator] |None) – A sequence of Hamiltonians to use for the VQE runs. IfNone(the default), no Hamiltonians are provided explicitly and molecule-based VQE runs will use their default Hamiltonians.molecule_transformer (
MoleculeTransformer|None) – A MoleculeTransformer object defining the configuration for generating the molecule variants. IfNone(the default), the providedhamiltoniansare used directly and no molecular transformation is performed.optimizer (
Optimizer|None) – The optimization algorithm for the VQE runs.max_iterations (
int) – The maximum number of optimizer iterations for each VQE run.**kwargs – Forwarded to the parent class.
Methods Summary
Find the best ansatz and bond configuration from all VQE runs.
Create VQE programs for all combinations of ansätze and molecule variants.
visualize_results([graph_type])Visualize the results of the VQE problem.
Methods Documentation
- aggregate_results()[source]¶
Find the best ansatz and bond configuration from all VQE runs.
Compares the final energies across all ansatz/molecule combinations and returns the configuration that achieved the lowest ground state energy.
- Returns:
- A tuple containing:
best_config (tuple): (ansatz_name, bond_modifier) of the best result.
best_energy (float): The lowest energy achieved.
- Return type:
- Raises:
RuntimeError – If programs haven’t been run or have empty losses.
- create_programs()[source]¶
Create VQE programs for all combinations of ansätze and molecule variants.
Generates molecule variants using the configured MoleculeTransformer, then creates a VQE program for each (ansatz, molecule_variant) pair.
Note
Program IDs are tuples of (ansatz_name, bond_modifier_value).