qxmt.models.vqe.base module#
- class qxmt.models.vqe.base.BaseVQE(device, hamiltonian, ansatz, diff_method='adjoint', max_steps=100, min_steps=None, tol=1e-06, verbose=True, optimizer_settings=None, init_params_config=None, logger=<Logger qxmt.models.vqe.base (INFO)>)
Bases:
ABC
Base class for Variational Quantum Eigensolver (VQE).
This abstract base class provides the foundation for implementing VQE algorithms. It handles the setup of quantum circuits, parameter optimization, and tracking of optimization history.
- Parameters:
device (BaseDevice) – Quantum device to use for the VQE calculation.
hamiltonian (BaseHamiltonian) – Hamiltonian to find the ground state of.
ansatz (BaseAnsatz) – Quantum circuit ansatz to use.
max_steps (int) – Maximum number of optimization steps. Defaults to 100.
min_steps (int | None) – Minimum number of optimization steps. Defaults to 1/10 of max_steps.
tol (float) – Tolerance for the optimization. Defaults to 1e-6.
verbose (bool) – Whether to output progress during optimization. Defaults to True.
diff_method (Literal[None, 'best', 'device', 'backprop', 'adjoint', 'parameter-shift', 'hadamard', 'finite-diff', 'spsa'] | None) – Method to use for differentiation. Defaults to “adjoint”.
optimizer_settings (dict[str, Any] | None) – Settings for the optimizer.
logger (Logger) – Logger object for output. Defaults to module-level logger.
init_params_config (dict[str, Any] | None)
- qnode
Quantum node for executing the circuit.
- params_history
List of parameter values during optimization.
- cost_history
List of cost values during optimization.
- is_optimized()
Check if the optimization process has been completed.
- Returns:
- True if optimization has been performed (cost_history is not empty),
False otherwise.
- Return type:
bool
Note
This is a simple check that only verifies if any optimization steps have been taken. It does not check if the optimization has converged to a satisfactory solution.
- is_params_updated(threshold=1e-08)
Check if parameters were actually updated during optimization.
- Parameters:
threshold (float) – Minimum change threshold to consider parameters as updated.
- Returns:
True if parameters changed more than threshold, False otherwise.
- Return type:
bool
- abstractmethod optimize(init_params)
Optimize the ansatz parameters to find the ground state.
This method must be implemented by subclasses to perform the parameter optimization process.
- Parameters:
init_params (Any) – Initial parameters for the ansatz. This array must be calculate gradientable with the optimizer.
- Return type:
None
Note
The implementation should update params_history and cost_history during the optimization process.
- class qxmt.models.vqe.base.OptimizerPlatform(value)
Bases:
Enum
- PENNYLANE = 'pennylane'
- SCIPY = 'scipy'