tangelo.algorithms.projective package

Subpackages

Submodules

tangelo.algorithms.projective.iqpe module

Implements the iterative Quantum Phase Estimation (iQPE) algorithm to solve electronic structure calculations.

Ref:

M. Dobsicek, G. Johansson, V. Shumeiko, and G. Wendin, Arbitrary Accuracy Iterative Quantum Phase Estimation Algorithm using a Single Ancillary Qubit: A two-qubit benchmark, Phys. Rev. A 76, 030306(R) (2007).

class tangelo.algorithms.projective.iqpe.BuiltInUnitary(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Enumeration of the ansatz circuits supported by iQPE.

CircuitUnitary = <class 'tangelo.toolboxes.unitary_generator.unitary_circuit.CircuitUnitary'>
TrotterSuzuki = <class 'tangelo.toolboxes.unitary_generator.trotter_suzuki.TrotterSuzukiUnitary'>
class tangelo.algorithms.projective.iqpe.IterativeQPEControl(n_bits: int, qft_qubit: int, u: Unitary)

Bases: ClassicalControl

finalize()

Called from simulator after all gates have been called.

Reinitialize all variables and store measurements and energies from the current iQPE run.

return_gates(measurement) List[Gate]

Return a list of gates based on the measurement outcome for the next step in iQPE.

Each measurement updates the current phase correction and returns a list of gates that implements the next controlled time-evolution along with the phase correction to determine the next bit value.

Parameters:

measurement (str) – “1” or “0”

Returns:

List[Gate] – The next gates to apply to the circuit

class tangelo.algorithms.projective.iqpe.IterativeQPESolver(opt_dict)

Bases: object

Solve the electronic structure problem for a molecular system by using the iterative Quantum Phase Estimation (iQPE) algorithm.

This algorithm evaluates the energy of a molecular system by performing a series of controlled time-evolutions

Users must first set the desired options of the iterative QPESolver object through the __init__ method, and call the “build” method to build the underlying objects (mean-field, hardware backend, unitary…). They are then able to call the the simulate method. In particular, simulate runs the iQPE algorithm, returning the optimal energy found by the most probable measurement as a binary fraction.

molecule

The molecular system.

Type:

SecondQuantizedMolecule

qubit_mapping

one of the supported qubit mapping identifiers.

Type:

str

unitary

one of the supported unitary evolutions.

Type:

Unitary

backend_options

parameters to build the underlying compute backend (simulator, etc).

Type:

dict

simulate_options

Options for fine-control of the simulator backend, including desired measurement results, etc.

Type:

dict

penalty_terms

parameters for penalty terms to append to target qubit Hamiltonian (see penalty_terms for more details).

Type:

dict

unitary_options

parameters for the given ansatz (see given ansatz file for details).

Type:

dict

up_then_down

change basis ordering putting all spin up orbitals first, followed by all spin down. Default, False has alternating

spin up/down ordering.

Type:

bool

qubit_hamiltonian

The Hamiltonian expressed as a sum of products of Pauli matrices.

Type:

QubitOperator

verbose

Flag for iQPE verbosity.

Type:

bool

projective_circuit

A terminal circuit that projects into the correct space, always added to the end of the unitary circuit. Could be measurement gates for example

Type:

Circuit

ref_state

The reference configuration to use. Replaces HF state

Type:

array or Circuit

size_qpe_register

The number of iterations of single qubit iQPE to use for the calculation.

Type:

int

build()

Build the underlying objects required to run the iQPE algorithm afterwards.

energy_estimation(bitstring)

Estimate energy using the calculated frequency dictionary.

Parameters:

bitstring (str) – The bitstring to evaluate the energy of in base 2.

Returns:

float – Energy of the given bitstring

get_resources()

Estimate the resources required by iQPE, with the current unitary. This assumes “build” has been run, as it requires the circuit and the qubit Hamiltonian. Return information that pertains to the user, for the purpose of running an experiment on a classical simulator or a quantum device.

simulate()

Run the iQPE circuit. Return the energy of the most probable bitstring

bitstring

The most probable bitstring.

Type:

str

histogram

The full Histogram of measurements on the iQPE ancilla qubit representing energies.

Type:

Histogram

qpe_freqs

The dictionary of measurements on the iQPE ancilla qubit.

Type:

dict

freqs

The full dictionary of measurements on all qubits.

Type:

dict

Returns:

float – The energy of the most probable bitstring measured during iQPE.

tangelo.algorithms.projective.qpe module

Implements the Quantum Phase Estimation (QPE) algorithm to solve electronic structure calculations.

class tangelo.algorithms.projective.qpe.BuiltInUnitary(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Enumeration of the ansatz circuits supported by QPE.

CircuitUnitary = <class 'tangelo.toolboxes.unitary_generator.unitary_circuit.CircuitUnitary'>
TrotterSuzuki = <class 'tangelo.toolboxes.unitary_generator.trotter_suzuki.TrotterSuzukiUnitary'>
class tangelo.algorithms.projective.qpe.QPESolver(opt_dict)

Bases: object

Solve the electronic structure problem for a molecular system by using the Quantum Phase Estimation (QPE) algorithm.

This algorithm evaluates the energy of a molecular system by performing a series of controlled time-evolutions

Users must first set the desired options of the QPESolver object through the __init__ method, and call the “build” method to build the underlying objects (mean-field, hardware backend, unitary…). They are then able to call the the simulate method. In particular, simulate runs the QPE algorithm, returning the optimal energy found by the most probable measurement as a binary fraction.

molecule

The molecular system.

Type:

SecondQuantizedMolecule

qubit_mapping

one of the supported qubit mapping identifiers.

Type:

str

unitary

one of the supported unitary evolutions.

Type:

Unitary

backend_options

parameters to build the underlying compute backend (simulator, etc).

Type:

dict

simulate_options

Options for fine-control of the simulator backend, including desired measurement results, etc.

Type:

dict

penalty_terms

parameters for penalty terms to append to target qubit Hamiltonian (see penalty_terms for more details).

Type:

dict

unitary_options

parameters for the given ansatz (see given ansatz file for details).

Type:

dict

up_then_down

change basis ordering putting all spin up orbitals first, followed by all spin down. Default, False has alternating

spin up/down ordering.

Type:

bool

qubit_hamiltonian

Self-explanatory.

Type:

QubitOperator-like

verbose

Flag for QPE verbosity.

Type:

bool

projective_circuit

A terminal circuit that projects into the correct space, always added to the end of the unitary circuit. Could be measurement gates for example

Type:

Circuit

ref_state

The reference configuration to use. Replaces HF state

Type:

array or Circuit

size_qpe_register

The number of qubits to use for the qpe register

Type:

int

build()

Build the underlying objects required to run the QPE algorithm afterwards.

energy_estimation(bitstring)

Estimate energy using the calculated frequency dictionary.

Parameters:

bitstring (str) – The bitstring to evaluate the energy of in base 10.

Returns:

float – Energy of the given bitstring

get_resources()

Estimate the resources required by QPE, with the current unitary. This assumes “build” has been run, as it requires the circuit and the qubit Hamiltonian. Return information that pertains to the user, for the purpose of running an experiment on a classical simulator or a quantum device.

simulate()

Run the QPE circuit. Return the energy of the most probable bitstring

bitstring

The most probable bitstring.

Type:

str

histogram

The full Histogram of measurements on the QPE ancilla qubits representing energies.

Type:

Histogram

qpe_freqs

The dictionary of measurements on the QPE ancilla qubits.

Type:

dict

freqs

The full dictionary of measurements on all qubits.

Type:

dict

tangelo.algorithms.projective.quantum_imaginary_time module

Module that defines the Quantum Imaginary Time Algorithm (QITE)

class tangelo.algorithms.projective.quantum_imaginary_time.QITESolver(opt_dict)

Bases: object

QITE class. This is an iterative algorithm that obtains a unitary operator that approximates the imaginary time evolution of an initial state.

molecule

The molecular system.

Type:

SecondQuantizedMolecule

dt

The imaginary time step size

Type:

float

min_de

Maximum energy change allowed before convergence.

Type:

float

max_cycles

Maximum number of iterations of QITE.

Type:

int

pool

Function that returns a list of FermionOperator. Each element represents an excitation/operator that has an effect on the total energy.

Type:

func

pool_args

The arguments for the pool function given as a tuple.

Type:

tuple

qubit_mapping

One of the supported qubit mapping identifiers.

Type:

str

qubit_hamiltonian

Self-explanatory.

Type:

QubitOperator-like

up_then_down

Spin orbitals ordering.

Type:

bool

n_spinorbitals

Self-explanatory.

Type:

int

n_electrons

Self-explanatory.

Type:

int

backend_options

Backend options for the underlying QITE propagation

Type:

dict

verbose

Flag for verbosity of QITE.

Type:

bool

build()

Builds the underlying objects required to run the QITE algorithm.

calculate_matrices(backend, new_energy)

Calculated matrix elements for imaginary time evolution. The matrices are defined in section 3.5 of https://arxiv.org/pdf/2108.04413.pdf

Parameters:
  • backend (Backend) – the backend from which the matrices are generated

  • new_energy (float) – the current energy_expectation of the Hamiltonian

Returns:
  • matrix float – The expectation values <psi| pu^+ pv |psi>

  • array float – The expectation values <psi| pu^+ H |psi>

energy_expectation(backend)

Estimate energy using the self.final_circuit, qubit hamiltonian and compute backend.

Parameters:

backend (Backend) – the backend one computes the energy expectation with

Returns:

float – energy computed by the backend

get_resources()

Returns resources currently used in underlying state preparation i.e. self.final_circuit the number of pool operators, and the size of qubit_hamiltonian

Returns:

dict – Dictionary of various quantum resources required

prepare_reference_state()

Returns circuit preparing the reference state of the ansatz (e.g prepare reference wavefunction with HF, multi-reference state, etc). These preparations must be consistent with the transform used to obtain the qubit operator.

simulate()

Performs the QITE cycles. Each iteration, a linear system is solved to obtain the next unitary. The system to be solved can be found in section 3.5 of https://arxiv.org/pdf/2108.04413.pdf

Returns:

float – final energy after obtaining running QITE

update_statevector(backend, next_circuit)

Update self.final_statevector by propagating with next_circuit using backend

Parameters:
  • backend (Backend) – the backend to use for the statevector update

  • next_circuit (Circuit) – The circuit to apply to the statevector

Module contents