qc2.algorithms.pennylane.pebase

Module defining QPE algorithm for PennyLane.

Classes

PEBase

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

qc2data = None[source]
format = 'pennylane'[source]
verbose = 0[source]
circuit = None[source]
num_evaluation_qubits = None[source]
active_space[source]
device = 'default.qubit'[source]
mapper[source]
qubits[source]
electrons[source]
reference_state[source]
static _get_default_reference(qubits: int, electrons: int) pennylane.numpy.ndarray[source]

Generate the default reference state for the ansatz.

Parameters:
  • qubits (int) – Number of qubits in the circuit.

  • electrons (int) – Number of electrons in the system.

Returns:

Reference state vector.

Return type:

np.ndarray

_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.

e_core

The core energy of the system.

Type:

float

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.

Parameters:

phase (float) – The phase to convert.

Returns:

The energy corresponding to the given phase.

Return type:

float

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:

float

run(*args, **kwargs) qc2.algorithms.algorithms_results.QPEResults[source]

Executes QPE algorithm.

Parameters:
  • *args

    • device_args (optional): qml.device arguments.

    • qnode_args (optional): qml.qnode arguments.

  • **kwargs

    • device_kwargs (optional): qml.device keyword arguments.

    • qnode_kwargs (optional): qml.qnode keyword arguments.

Returns:

An instance of qc2.algorithms.pennylane.vqe.VQEResults class with all VQE info.

Return type:

VQEResults

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()