Note
Cette page a été générée à partir de tutorials/chemistry/04_excited_states_solvers.ipynb.
Exécuter en mode interactif dans le `IBM Quantum lab <https://quantum-computing.ibm.com/jupyter/tutorial/chemistry/04_excited_states_solvers.ipynb>_.
Solveurs d’états excités (excited states
)¶
Introduction¶
Dans ce tutoriel, nous allons discuter de l’interface de calcul des états excités (excited states
) de Qiskit Chemistry. Le but est de calculer les états excités d’un Hamiltonien moléculaire. Cet Hamiltonien peut être électronique ou vibronique. Pour en savoir plus sur la préparation de l’Hamiltonien, consultez les tutoriels sur la structure électronique et les tutoriels sur la structure vibronique.
La première étape consiste à définir le système moléculaire. Dans se qui suit, nous demandons la partie électronique d’une molécule d’hydrogène.
[1]:
from qiskit.chemistry.drivers import PySCFDriver, UnitsType, Molecule
from qiskit.chemistry.transformations import FermionicTransformation, FermionicQubitMappingType
molecule = Molecule(geometry=[['H', [0., 0., 0.]],
['H', [0., 0., 0.735]]],
charge=0, multiplicity=1)
driver = PySCFDriver(molecule = molecule, unit=UnitsType.ANGSTROM, basis='sto3g')
transformation = FermionicTransformation(qubit_mapping=FermionicQubitMappingType.JORDAN_WIGNER)
Numpy 1.16 has memory leak bug https://github.com/numpy/numpy/issues/13808
It is recommended to downgrade to numpy 1.15 or older
Le Solveur (The Solver
)¶
Ensuite, nous devons définir un solveur (Solver
). Le solveur est l’algorithme par lequel l’état du sol (Ground State
) est calculé.
Let’s first start with a purely classical example: the NumPy eigensolver. This algorithm exactly diagonalizes the Hamiltonian. Although it scales badly, it can be used on small systems to check the results of the quantum algorithms. Here, we are only interested to look at eigenstates with a given number of particle. To compute only those states a filter function can be passed to the NumPy eigensolver. A default filter function is already implemented in Qiskit and can be used in this way:
[3]:
from qiskit.chemistry.algorithms import NumPyEigensolverFactory
numpy_solver = NumPyEigensolverFactory(use_default_filter_criterion=True)
Les énergies d’excitation sont également accessibles avec l’algorithme qEOM [arXiv preprint arXiv:1910.12890 (2019)]. La méthode EOM trouve les énergies d’excitation (différences d’énergie entre l’état fondamental et tous les états excités de \(n\)) en résolvant le problème de pseudo-valeur propre (pseudo-eigenvalue
) suivant.
avec
Bien que l’équation précédente puisse être résolue classiquement, chaque élément de la matrice doit être mesuré sur l’ordinateur quantique avec l’état de sol (ground state
) correspondant. Pour utiliser qEOM comme un solveur dans Qiskit, nous devons d’abord définir un calcul de l’état du sol (ground state
) expliquant aux algorithmes comment trouver l’état du sol (ground state
). Avec cela, le solveur qEOM peut être initialisé :
[4]:
from qiskit import BasicAer
from qiskit.aqua import QuantumInstance
from qiskit.chemistry.algorithms.ground_state_solvers import (GroundStateEigensolver,
VQEUCCSDFactory)
from qiskit.chemistry.algorithms.excited_states_solvers import QEOM
# This first part sets the ground state solver
# see more about this part in the ground state calculation tutorial
quantum_instance = QuantumInstance(BasicAer.get_backend('statevector_simulator'))
solver = VQEUCCSDFactory(quantum_instance)
gsc = GroundStateEigensolver(transformation, solver)
# The qEOM algorithm is simply instantiated with the chosen ground state solver
qeom_excited_states_calculation = QEOM(gsc, 'sd')
Le calcul et les résultats¶
Les résultats sont calculés et imprimés
[5]:
from qiskit.chemistry.algorithms.excited_states_solvers import ExcitedStatesEigensolver
numpy_excited_states_calculation = ExcitedStatesEigensolver(transformation, numpy_solver)
numpy_results = numpy_excited_states_calculation.solve(driver)
qeom_results = qeom_excited_states_calculation.solve(driver)
print(numpy_results)
print('\n\n')
print(qeom_results)
=== GROUND STATE ENERGY ===
* Electronic ground state energy (Hartree): -1.857275030202
- computed part: -1.857275030202
- frozen energy part: 0.0
- particle hole part: 0.0
~ Nuclear repulsion energy (Hartree): 0.719968994449
> Total ground state energy (Hartree): -1.137306035753
=== EXCITED STATE ENERGIES ===
1:
* Electronic excited state energy (Hartree): -0.882722150245
> Total excited state energy (Hartree): -0.162753155796
2:
* Electronic excited state energy (Hartree): -0.224911252831
> Total excited state energy (Hartree): 0.495057741618
=== MEASURED OBSERVABLES ===
0: # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
1: # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
2: # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
=== DIPOLE MOMENTS ===
~ Nuclear dipole moment (a.u.): [0.0 0.0 1.3889487]
0:
* Electronic dipole moment (a.u.): [0.0 0.0 1.3889487]
- computed part: [0.0 0.0 1.3889487]
- frozen energy part: [0.0 0.0 0.0]
- particle hole part: [0.0 0.0 0.0]
> Dipole moment (a.u.): [0.0 0.0 0.0] Total: 0.
(debye): [0.0 0.0 0.0] Total: 0.
1:
* Electronic dipole moment (a.u.): [0.0 0.0 1.3889487]
- computed part: [0.0 0.0 1.3889487]
- frozen energy part: [0.0 0.0 0.0]
- particle hole part: [0.0 0.0 0.0]
> Dipole moment (a.u.): [0.0 0.0 0.0] Total: 0.
(debye): [0.0 0.0 0.0] Total: 0.
2:
* Electronic dipole moment (a.u.): [0.0 0.0 1.3889487]
- computed part: [0.0 0.0 1.3889487]
- frozen energy part: [0.0 0.0 0.0]
- particle hole part: [0.0 0.0 0.0]
> Dipole moment (a.u.): [0.0 0.0 0.0] Total: 0.
(debye): [0.0 0.0 0.0] Total: 0.
=== GROUND STATE ENERGY ===
* Electronic ground state energy (Hartree): -1.857275030145
- computed part: -1.857275030145
- frozen energy part: 0.0
- particle hole part: 0.0
~ Nuclear repulsion energy (Hartree): 0.719968994449
> Total ground state energy (Hartree): -1.137306035696
=== EXCITED STATE ENERGIES ===
1:
* Electronic excited state energy (Hartree): -1.244586753196
> Total excited state energy (Hartree): -0.524617758747
2:
* Electronic excited state energy (Hartree): -0.882724353597
> Total excited state energy (Hartree): -0.162755359148
3:
* Electronic excited state energy (Hartree): -0.224913456192
> Total excited state energy (Hartree): 0.495055538257
=== MEASURED OBSERVABLES ===
0: # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
=== DIPOLE MOMENTS ===
~ Nuclear dipole moment (a.u.): [0.0 0.0 1.3889487]
0:
* Electronic dipole moment (a.u.): [0.0 0.0 1.38894909]
- computed part: [0.0 0.0 1.38894909]
- frozen energy part: [0.0 0.0 0.0]
- particle hole part: [0.0 0.0 0.0]
> Dipole moment (a.u.): [0.0 0.0 -0.00000039] Total: 0.00000039
(debye): [0.0 0.0 -0.000001] Total: 0.000001
On peut voir à partir de ces résultats qu’un état est absent des résultats de NumPy. La raison en est que la rotation (spin
) est également utilisée comme filtre et que seuls les statuts de singlet sont affichés. Dans ce qui suit, nous utilisons une fonction de filtre personnalisée (custom
) pour vérifier systématiquement nos résultats et seulement filtrer les états avec un nombre incorrect de particules (dans ce cas, le nombre de particules est 2).
[6]:
import numpy as np
def filter_criterion(eigenstate, eigenvalue, aux_values):
return np.isclose(aux_values[0][0], 2.)
new_numpy_solver = NumPyEigensolverFactory(filter_criterion=filter_criterion)
new_numpy_excited_states_calculation = ExcitedStatesEigensolver(transformation, new_numpy_solver)
new_numpy_results = new_numpy_excited_states_calculation.solve(driver)
print(new_numpy_results)
=== GROUND STATE ENERGY ===
* Electronic ground state energy (Hartree): -1.857275030202
- computed part: -1.857275030202
- frozen energy part: 0.0
- particle hole part: 0.0
~ Nuclear repulsion energy (Hartree): 0.719968994449
> Total ground state energy (Hartree): -1.137306035753
=== EXCITED STATE ENERGIES ===
1:
* Electronic excited state energy (Hartree): -1.244584549813
> Total excited state energy (Hartree): -0.524615555364
2:
* Electronic excited state energy (Hartree): -1.244584549813
> Total excited state energy (Hartree): -0.524615555364
3:
* Electronic excited state energy (Hartree): -1.244584549813
> Total excited state energy (Hartree): -0.524615555364
4:
* Electronic excited state energy (Hartree): -0.882722150245
> Total excited state energy (Hartree): -0.162753155796
5:
* Electronic excited state energy (Hartree): -0.224911252831
> Total excited state energy (Hartree): 0.495057741618
=== MEASURED OBSERVABLES ===
0: # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
1: # Particles: 2.000 S: 1.000 S^2: 2.000 M: 0.000
2: # Particles: 2.000 S: 1.000 S^2: 2.000 M: -1.000
3: # Particles: 2.000 S: 1.000 S^2: 2.000 M: 1.000
4: # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
5: # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
=== DIPOLE MOMENTS ===
~ Nuclear dipole moment (a.u.): [0.0 0.0 1.3889487]
0:
* Electronic dipole moment (a.u.): [0.0 0.0 1.3889487]
- computed part: [0.0 0.0 1.3889487]
- frozen energy part: [0.0 0.0 0.0]
- particle hole part: [0.0 0.0 0.0]
> Dipole moment (a.u.): [0.0 0.0 0.0] Total: 0.
(debye): [0.0 0.0 0.0] Total: 0.
1:
* Electronic dipole moment (a.u.): [0.0 0.0 1.3889487]
- computed part: [0.0 0.0 1.3889487]
- frozen energy part: [0.0 0.0 0.0]
- particle hole part: [0.0 0.0 0.0]
> Dipole moment (a.u.): [0.0 0.0 0.0] Total: 0.
(debye): [0.0 0.0 0.0] Total: 0.
2:
* Electronic dipole moment (a.u.): [0.0 0.0 1.3889487]
- computed part: [0.0 0.0 1.3889487]
- frozen energy part: [0.0 0.0 0.0]
- particle hole part: [0.0 0.0 0.0]
> Dipole moment (a.u.): [0.0 0.0 0.0] Total: 0.
(debye): [0.0 0.0 0.0] Total: 0.
3:
* Electronic dipole moment (a.u.): [0.0 0.0 1.3889487]
- computed part: [0.0 0.0 1.3889487]
- frozen energy part: [0.0 0.0 0.0]
- particle hole part: [0.0 0.0 0.0]
> Dipole moment (a.u.): [0.0 0.0 0.0] Total: 0.
(debye): [0.0 0.0 0.0] Total: 0.
4:
* Electronic dipole moment (a.u.): [0.0 0.0 1.3889487]
- computed part: [0.0 0.0 1.3889487]
- frozen energy part: [0.0 0.0 0.0]
- particle hole part: [0.0 0.0 0.0]
> Dipole moment (a.u.): [0.0 0.0 0.0] Total: 0.
(debye): [0.0 0.0 0.0] Total: 0.
5:
* Electronic dipole moment (a.u.): [0.0 0.0 1.3889487]
- computed part: [0.0 0.0 1.3889487]
- frozen energy part: [0.0 0.0 0.0]
- particle hole part: [0.0 0.0 0.0]
> Dipole moment (a.u.): [0.0 0.0 0.0] Total: 0.
(debye): [0.0 0.0 0.0] Total: 0.
[1]:
import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright
Version Information
Qiskit Software | Version |
---|---|
Qiskit | 0.23.0 |
Terra | 0.16.0 |
Aer | 0.7.0 |
Ignis | 0.5.0 |
Aqua | 0.8.0 |
IBM Q Provider | 0.11.0 |
System information | |
Python | 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 13:42:17) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] |
OS | Darwin |
CPUs | 2 |
Memory (Gb) | 16.0 |
Tue Oct 20 18:06:26 2020 CEST |
This code is a part of Qiskit
© Copyright IBM 2017, 2020.
This code is licensed under the Apache License, Version 2.0. You may
obtain a copy of this license in the LICENSE.txt file in the root directory
of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
Any modifications or derivative works of this code must retain this
copyright notice, and modified files need to carry a notice indicating
that they have been altered from the originals.
[ ]: