VQE¶
The Variational Quantum Eigensolver (VQE) is a hybrid quantum-classical algorithm designed to find the ground state energy of a Hamiltonian by variationally optimizing a parameterized quantum circuit. It's widely used in quantum chemistry to compute molecular ground state energies and electronic structure properties. Nevertheless, it can also be used to find the ground state of combinatorial optimization problems, like this implementation is intends to do.
For further information see qiskit’s VQE tutorial.
Compatible Backends¶
The VQE algorithm supports the following backends:
IBM
By default,VQEuses theIBMbackend.
Initialization¶
The following section outlines the default configurations of VQE. You can also specify
other compatible backends for the algorithm. When backend=None is specified, the default backend
will be initialized automatically. In this case, if the backend requires a token, it will be taken
from the environment variables.
from luna_quantum.algorithms import VQE
from luna_quantum.solve.parameters.algorithms.base_params import ScipyOptimizerParams
algorithm = VQE(
backend=None,
ansatz='EfficientSU2',
ansatz_config={},
shots=1024,
optimizer=ScipyOptimizerParams(
method='cobyla',
tol=None,
bounds=None,
jac=None,
hess=None,
maxiter=100,
options={}
),
initial_params_seed=None,
initial_params_range=(0, 6.283185307179586)
)
Parameter Details
For a complete overview of available parameters and their usage, see the VQE API Reference.
Usage¶
from luna_quantum import LunaSolve
LunaSolve.authenticate("<YOUR_LUNA_API_KEY>")
# Define your model and algorithm
model = ...
algorithm = ...
solve_job = algorithm.run(model, name="my-solve-job")
API Reference¶
Bases: LunaAlgorithm[IBM]
Parameters for the Variational Quantum Eigensolver (VQE) algorithm.
VQE is a hybrid quantum-classical algorithm designed to find the ground state energy of a Hamiltonian by variationally optimizing a parameterized quantum circuit. It's widely used in quantum chemistry to compute molecular ground state energies and electronic structure properties.
Attributes:
| Name | Type | Description |
|---|---|---|
ansatz |
Literal['NLocal', 'EfficientSU2', 'RealAmplitudes', 'PauliTwoDesign']
|
The variational form (parameterized circuit) to use. Default is "EfficientSU2", a hardware-efficient ansatz using SU(2) rotation gates that works well on NISQ devices due to its shallow depth and flexibility. |
ansatz_config |
dict[str, Any]
|
Configuration options for the selected ansatz, such as:
Default is an empty dictionary, using the ansatz's default settings. |
shots |
int | None
|
Number of measurement samples per circuit execution. Higher values improve accuracy by reducing statistical noise at the cost of longer runtime. Default is 1024, which balances accuracy with execution time. |
optimizer |
ScipyOptimizerParams | Dict
|
Configuration for the classical optimization routine that updates the variational parameters. Default is a ScipyOptimizer instance with default settings. See ScipyOptimizer Params class or for details of contained parameters. |
initial_params_seed |
int | None
|
Seed for random number generator for intial params. |
initial_params_range |
tuple[float, float]
|
Range of initial parameter values. |
ansatz
class-attribute
instance-attribute
¶
ansatz: Literal[
"NLocal", "EfficientSU2", "RealAmplitudes", "PauliTwoDesign"
] = "EfficientSU2"
ansatz_config
class-attribute
instance-attribute
¶
backend
class-attribute
instance-attribute
¶
initial_params_range
class-attribute
instance-attribute
¶
model_config
class-attribute
instance-attribute
¶
optimizer
class-attribute
instance-attribute
¶
optimizer: ScipyOptimizerParams = Field(
default_factory=lambda: ScipyOptimizerParams()
)
get_compatible_backends
classmethod
¶
get_default_backend
classmethod
¶
get_default_backend() -> IBM
Return the default backend implementation.
This property must be implemented by subclasses to provide the default backend instance to use when no specific backend is specified.
Returns:
| Type | Description |
|---|---|
IBackend
|
An instance of a class implementing the IBackend interface that serves as the default backend. |
run ¶
run(
model: Model | str,
name: str | None = None,
backend: BACKEND_TYPE | None = None,
client: LunaSolve | str | None = None,
*args: Any,
**kwargs: Any,
) -> SolveJob
Run the configured solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model or str
|
The model to be optimized or solved. It could be an Model instance or a string identifier representing the model id. |
required |
name
|
str | None
|
If provided, the name of the job. Defaults to None. |
None
|
backend
|
BACKEND_TYPE | None
|
Backend to use for the solver. If not provided, the default backend is used. |
None
|
client
|
LunaSolve or str
|
The client interface used to interact with the backend services. If not provided, a default client will be used. |
None
|
*args
|
Any
|
Additional arguments that will be passed to the solver or client. |
()
|
**kwargs
|
Any
|
Additional keyword parameters for configuration or customization. |
{}
|
Returns:
| Type | Description |
|---|---|
SolveJob
|
The job object containing the information about the solve process. |
Bases: BaseModel
Wrapper for scipy.optimize.minimize.
See SciPy minimize documentation for more information of the available methods and parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
ScipyOptimizerMethod
|
Type of solver. See SciPy minimize documentation for supported methods. |
tol |
float | None
|
Tolerance for termination. |
bounds |
None | list[tuple[float, float]]
|
Bounds on variables for Nelder-Mead, L-BFGS-B, TNC, SLSQP, Powell,
trust-constr, COBYLA, and COBYQA methods. |
jac |
None | Literal['2-point', '3-point', 'cs']
|
Method for computing the gradient vector. Only for CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr. |
hess |
None | Literal['2-point', '3-point', 'cs']
|
Method for computing the Hessian matrix. Only for Newton-CG, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr. |
maxiter |
int
|
Maximum number of iterations to perform. Depending on the method each iteration may use several function evaluations. Will be ignored for TNC optimizer. Default: 100 |
options |
dict[str, float]
|
A dictionary of solver options. |
bounds
class-attribute
instance-attribute
¶
bounds: None | list[tuple[float, float]] = Field(
default=None,
description="Bounds on variables for Nelder-Mead, L-BFGS-B, TNC, SLSQP, Powell,trust-constr, COBYLA, and COBYQA methods. None is used to specify no bounds. A sequence of `(min, max)` can be used to specify bounds for each parameter individually.",
)
hess
class-attribute
instance-attribute
¶
hess: None | Literal["2-point", "3-point", "cs"] = Field(
default=None,
description="Method for computing the Hessian matrix. Only for Newton-CG, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr.",
)
jac
class-attribute
instance-attribute
¶
jac: None | Literal["2-point", "3-point", "cs"] = Field(
default=None,
description="Method for computing the gradient vector. Only for CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov, trust-exact and trust-constr.",
)
maxiter
class-attribute
instance-attribute
¶
maxiter: int = Field(
default=100,
ge=1,
le=10000,
description="Maximum number of iterations to perform. Depending on the method each iteration may use several function evaluations. Will be ignored for TNC optimizer.",
)
method
class-attribute
instance-attribute
¶
method: ScipyOptimizerMethod = Field(
default="cobyla",
description="Type of solver. See https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.htmlfor supported methods.",
)