qc2.algorithms.qiskit
qc2 algorithms package for qiskit.
Submodules
Package Contents
Classes
Main class for the VQE algorithm with Qiskit-Nature. |
|
Main class for orbital-optimized VQE with Qiskit-Nature. |
- class qc2.algorithms.qiskit.VQE(qc2data=None, ansatz=None, active_space=None, mapper=None, estimator=None, optimizer=None, reference_state=None, init_params=None, verbose=0)[source]
Bases:
qc2.algorithms.base.vqe_base.VQEBASEMain class for the VQE algorithm with Qiskit-Nature.
This class initializes and executes the VQE algorithm using specified quantum components like ansatz, optimizer, and estimator.
- active_space
Describes the active space for quantum simulation. Defaults to
ActiveSpace((2, 2), 2).- Type:
- mapper
Strategy for fermionic-to-qubit mapping. Defaults to
qiskit.JordanWignerMapper.- Type:
QubitMapper
- estimator
Method for estimating the expectation value. Defaults to
qiskit.Estimator- Type:
BaseEstimator
- optimizer
Optimization routine for circuit variational parameters. Defaults to
qiskit_algorithms.SLSQP.- Type:
qiskit.Optmizer
- reference_state
Reference state for the VQE algorithm. Defaults to
qiskit.HartreeFock.- Type:
QuantumCircuit
- ansatz
The ansatz for the VQE algorithm. Defaults to
qiskit.UCCSD.- Type:
UCC
- params
List of initial VQE circuit parameters. Defaults to a list with entries of zero.
- Type:
List
- static _get_default_reference(active_space: qc2.algorithms.utils.active_space.ActiveSpace, mapper: qiskit_nature.second_q.mappers.QubitMapper) qiskit.circuit.QuantumCircuit[source]
Set up the default reference state circuit based on Hartree Fock.
- Parameters:
active_space (ActiveSpace) – description of the active space.
mapper (mapper) – mapper class instance.
- Returns:
Hartree-Fock circuit as the reference state.
- Return type:
QuantumCircuit
- static _get_default_ansatz(active_space: qc2.algorithms.utils.active_space.ActiveSpace, mapper: qiskit_nature.second_q.mappers.QubitMapper, reference_state: qiskit.circuit.QuantumCircuit) qiskit_nature.second_q.circuit.library.UCC[source]
Set up the default UCC ansatz from a Hartree Fock reference state.
- Parameters:
active_space (ActiveSpace) – Description of the active space.
mapper (QubitMapper) – Mapper class instance.
reference_state (QuantumCircuit) – Reference state circuit.
- Returns:
UCC ansatz quantum circuit.
- Return type:
UCC
- static _get_default_init_params(nparams: List) List[source]
Generates a list of initial circuit parameters for the ansatz.
- run(*args, **kwargs) qc2.algorithms.algorithms_results.VQEResults[source]
Executes the VQE algorithm.
- Parameters:
*args – Variable length argument list to be passed to the
qiskit_algorithm.VQEclass.**kwargs – Arbitrary keyword arguments to be passed to the
qiskit_algorithm.VQEclass.
- Returns:
An instance of
qc2.algorithms.qiskit.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.qiskit 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=SLSQP(), ... estimator=Estimator(), ... ) >>> results = qc2data.algorithm.run()
- class qc2.algorithms.qiskit.oo_VQE(qc2data=None, ansatz=None, active_space=None, mapper=None, estimator=None, optimizer=None, reference_state=None, init_circuit_params=None, init_orbital_params=None, freeze_active=False, max_iterations=50, conv_tol=1e-07, verbose=0)[source]
Bases:
qc2.algorithms.qiskit.vqe.VQEMain class for orbital-optimized VQE with Qiskit-Nature.
This class extends the VQE class to include orbital optimization. It supports customized ansatzes, active space definitions, qubit mapping strategies, estimation methods, and optimization routines. Orbital optimization is performed alongside VQE parameter optimization using analytic first and second derivatives
- orbital_params
List of orbital optimization parameters. Defaults to a list with entries of zero.
- Type:
List
- circuit_params
List of VQE circuit parameters. Defaults to a list with entries of zero.
- Type:
List
- oo_problem
An instance of
OrbitalOptimizationproblem class. Defaults to None.- Type:
- max_iterations
Maximum number of iterations for the combined circuit-orbitals parameters optimization. Defaults to 50.
- Type:
- run() qc2.algorithms.algorithms_results.OOVQEResults[source]
Optimizes both the circuit and orbital parameters.
- Returns:
An instance of
qc2.algorithms.qiskit.vqe.OOVQEResultsclass with all oo-VQE info.- Return type:
Example
>>> from ase.build import molecule >>> from qc2.ase import PySCF >>> from qc2.data import qc2Data >>> from qc2.algorithms.qiskit import oo_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 = oo_VQE( ... active_space=ActiveSpace( ... num_active_electrons=(2, 2), ... num_active_spatial_orbitals=4 ... ), ... mapper="jw", ... optimizer=SLSQP(), ... estimator=Estimator(), ... ) >>> results = qc2data.algorithm.run()
- _circuit_optimization(theta: List, kappa: List) Tuple[List, float][source]
Get total energy and best circuit parameters for a given kappa.
- Parameters:
theta (List) – List with circuit variational parameters.
kappa (List) – List with orbital rotation parameters.
- Returns:
Optimized circuit parameters and associated energy.
- Return type:
Tuple[List, float]
- _get_energy_from_parameters(theta: List, kappa: List) float[source]
Calculates total energy given circuit and orbital parameters.
- Parameters:
theta (List) – List with circuit variational parameters.
kappa (List) – List with orbital rotation parameters.
- Returns:
Total ground-state energy for a given circuit and orbital parameters.
- Return type:
- _get_rdms(theta: List, sum_spin=True) Tuple[numpy.ndarray, numpy.ndarray][source]
Calculates 1- and 2-electron reduced density matrices (RDMs).
- Parameters:
theta (List) – circuit parameters at which RDMs are calculated.
sum_spin (bool) – If True, the spin-summed 1-RDM and 2-RDM will be returned. If False, the full 1-RDM and 2-RDM will be returned. Defaults to True.
- Returns:
1- and 2-RDMs.
- Return type:
Tuple[np.ndarray, np.ndarray]