qc2.algorithms.pennylane.pebase
Module defining QPE algorithm for PennyLane.
Classes
Module Contents
- class qc2.algorithms.pennylane.pebase.PEBase(qc2data=None, active_space=None, mapper=None, device=None, reference_state=None, verbose=0)[source]
Bases:
qc2.algorithms.base.base_algorithm.BaseAlgorithm- static _get_default_reference(qubits: int, electrons: int) pennylane.numpy.ndarray[source]
Generate the default reference state for the ansatz.
- _init_qubit_hamiltonian()[source]
Initializes the qubit Hamiltonian for the quantum phase estimation algorithm.
This method retrieves the qubit Hamiltonian representation of the target molecule from the qc2data object. It requires prior initialization of qc2data with the molecular data.
- Raises:
ValueError – If qc2data is not set correctly.
- qubit_op
The qubit operator representing the Hamiltonian.
- Type:
Operator
- static _phase_to_energy(phase: float) float[source]
Convert a phase from 0 to 1 to an energy from -pi to pi.
- static _build_circuit(dev: str, qubits: int, num_estimation_wires: int, reference_state: pennylane.numpy.ndarray, unitary_op: pennylane.operation.Operator, device_args=None, device_kwargs=None, qnode_args=None, qnode_kwargs=None) pennylane.QNode[source]
- Abstractmethod:
Constructs and returns a PennyLane QNode for quantum phase estimation.
This method sets up a quantum circuit on a specified quantum device using the provided parameters. It initializes the qubits, applies necessary quantum operations including the unitary operator, and prepares the reference state.
- Parameters:
dev (str) – Identifier for the PennyLane quantum device to be used.
qubits (int) – Total number of qubits in the circuit.
num_estimation_wires (int) – Number of qubits designated for phase estimation.
reference_state (np.ndarray) – Initial state of the qubits, typically representing the Hartree-Fock state.
unitary_op (Operator) – Operator that defines the unitary evolution in the circuit.
device_args (list, optional) – Additional positional 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 positional arguments for the QNode. Defaults to None.
qnode_kwargs (dict, optional) – Additional keyword arguments for the QNode. Defaults to None.
- Returns:
The constructed QNode with the specified ansatz for phase estimation.
- Return type:
QNode
- abstract get_phase()[source]
Retrieves the estimated phase after the QPE algorithm has been run.
- Returns:
The estimated phase.
- Return type:
- run(*args, **kwargs) qc2.algorithms.algorithms_results.QPEResults[source]
Executes QPE 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 QPE >>> 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 = QPE( ... active_space=ActiveSpace( ... num_active_electrons=(2, 2), ... num_active_spatial_orbitals=4 ... ), ... num_evaluation_qubits=3, ... device="default.qubit" ... ) >>> results = qc2data.algorithm.run()