qc2.algorithms.pennylane.vqe
Module defining VQE algorithm for PennyLane.
Classes
Main class for the VQE algorithm with PennyLane. |
Module Contents
- class qc2.algorithms.pennylane.vqe.VQE(qc2data=None, ansatz=None, active_space=None, mapper=None, device=None, optimizer=None, reference_state=None, init_params=None, max_iterations=50, conv_tol=1e-07, verbose=0)[source]
Bases:
qc2.algorithms.base.vqe_base.VQEBASEMain class for the VQE algorithm with PennyLane.
This class initializes and executes the VQE algorithm using specified quantum components like ansatz, optimizer, and estimator.
- mapper[source]
Strategy for fermionic-to-qubit mapping. Defaults to
JordanWignerMapper.- Type:
QubitMapper
- device[source]
Device for estimating the expectation value. Defaults to
default.qubit.- Type:
qml.device
- optimizer[source]
Optimization routine for circuit variational parameters. Defaults to
qml.GradientDescentOptimizer.- Type:
qml.optimizer
- reference_state[source]
Reference state for the VQE algorithm. Defaults to
qml.qchem.hf_state.- Type:
qml.ref_state
- params[source]
List of initial VQE circuit parameters. Defaults to a list with entries of zero.
- Type:
List
- max_iterations[source]
Maximum number of iterations for the combined circuit-orbitals parameters optimization. Defaults to 50.
- Type:
- static _get_default_reference(qubits: int, electrons: int) pennylane.numpy.ndarray[source]
Generate the default reference state for the ansatz.
- static _get_default_ansatz(qubits: int, electrons: int, reference_state: pennylane.numpy.ndarray) Callable[source]
Create the default ansatz function for the VQE circuit.
- static _get_default_init_params(qubits: int, electrons: int) pennylane.numpy.ndarray[source]
Generate default initial parameters for the ansatz.
- static _build_circuit(dev: str, qubits: int, ansatz: Callable, qubit_op: pennylane.operation.Operator, device_args=None, device_kwargs=None, qnode_args=None, qnode_kwargs=None) pennylane.QNode[source]
Builds and return PennyLane QNode.
- Parameters:
dev (str) – PennyLane quantum device.
qubits (int) – Number of qubits in the circuit.
ansatz (Callable) – Ansatz function for the circuit.
qubit_op (Operator) – Qubit operator for the Hamiltonian.
device_args (list, optional) – Additional arguments for the quantum device. Defaults to None.
device_kwargs (dict, optional) – Additional keyword arguments for the quantum device. Defaults to None.
qnode_args (list, optional) – Additional arguments for the QNode. Defaults to None.
qnode_kwargs (dict, optional) – Additional keyword arguments for the QNode. Defaults to None.
- Returns:
PennyLane qnode with built-in ansatz.
- Return type:
QNode
- run(*args, **kwargs) qc2.algorithms.algorithms_results.VQEResults[source]
Executes VQE algorithm.
- Parameters:
*args –
device_args (optional):
qml.devicearguments.qnode_args (optional):
qml.qnodearguments.
**kwargs –
device_kwargs (optional):
qml.devicekeyword arguments.qnode_kwargs (optional):
qml.qnodekeyword arguments.
- Returns:
An instance of
qc2.algorithms.pennylane.vqe.VQEResultsclass with all VQE info.- Return type:
Example
>>> from ase.build import molecule >>> from qc2.ase import PySCF >>> from qc2.data import qc2Data >>> from qc2.algorithms.pennylane import VQE >>> from qc2.algorithms.utils import ActiveSpace >>> >>> mol = molecule('H2O') >>> >>> hdf5_file = 'h2o.hdf5' >>> qc2data = qc2Data(hdf5_file, mol, schema='qcschema') >>> qc2data.molecule.calc = PySCF() >>> qc2data.run() >>> qc2data.algorithm = VQE( ... active_space=ActiveSpace( ... num_active_electrons=(2, 2), ... num_active_spatial_orbitals=4 ... ), ... optimizer=qml.GradientDescentOptimizer(stepsize=0.5), ... device="default.qubit" ... ) >>> results = qc2data.algorithm.run()