Skip to content

dlasecki/qiskit-nature

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Qiskit Nature

LicenseBuild StatusCoverage Status

⚠️ This branch of Qiskit Nature is under heavy development! In particular, if you are encountering errors referring to modules under qiskit_nature.second_q, you are very likely looking for the stable branch instead of this one. That branch also matches the published documentation.

Qiskit Nature is an open-source framework which supports solving quantum mechanical natural science problems using quantum computing algorithms. This includes finding ground and excited states of electronic and vibrational structure problems, measuring the dipole moments of molecular systems, solving the Ising and Fermi-Hubbard models on lattices, and much more.

The code comprises chemistry drivers, which when provided with a molecular configuration will return one- and two-body integrals as well as other data that is efficiently computed classically. This output data from a driver can then be used as input in Qiskit Nature that contains logic which is able to translate this into a form that is suitable for quantum algorithms.

For the solution of electronic structure problems, the problem Hamiltonian is first expressed in the second quantization formalism, comprising fermionic excitation and annihilation operators. These can then be mapped to the qubit formalism using a variety of mappings such as Jordan-Wigner, Parity, and more, in readiness for the quantum computation.

Installation

We encourage installing Qiskit Nature via the pip tool (a python package manager).

pip install qiskit-nature

pip will handle all dependencies automatically and you will always install the latest (and well-tested) version.

If you want to work on the very latest work-in-progress versions, either to try features ahead of their official release or if you want to contribute to Qiskit Nature, then you can install from source. To do this follow the instructions in the documentation.

Optional Installs

To run chemistry experiments using Qiskit Nature, it is recommended that you install a classical computation chemistry software program/library interfaced by Qiskit. Several, as listed below, are supported, and while logic to interface these programs is supplied by Qiskit Nature via the above pip installation, the dependent programs/libraries themselves need to be installed separately.

  1. Gaussian 16™, a commercial chemistry program
  2. PSI4, a chemistry program that exposes a Python interface allowing for accessing internal objects
  3. PyQuante, a pure cross-platform open-source Python chemistry program
  4. PySCF, an open-source Python chemistry program

HDF5 Driver

A useful functionality integrated into Qiskit Nature is its ability to serialize a file in hierarchical Data Format 5 (HDF5) format representing all the output data from a chemistry driver.

The HDF5 driver accepts such HDF5 files as input so molecular experiments can be run, albeit on the fixed data as stored in the file. As such, if you have some pre-created HDF5 files created from Qiskit Nature, you can use these with the HDF5 driver even if you do not install one of the classical computation packages listed above.

Creating Your First Chemistry Programming Experiment in Qiskit

Now that Qiskit Nature is installed, let's try a chemistry application experiment using the VQE (Variational Quantum Eigensolver) algorithm to compute the ground-state (minimum) energy of a molecule.

Note: The following example belongs to the version >= 0.5 . The working example for version <0.5 can be found at the old README file.

from qiskit_nature.settings import settings
from qiskit_nature.units import DistanceUnit
from qiskit_nature.second_q.drivers import PySCFDriver
from qiskit_nature.second_q.problems import ElectronicStructureProblem

settings.dict_aux_operators = True

# Use PySCF, a classical computational chemistry software
# package, to compute the one-body and two-body integrals in
# electronic-orbital basis, necessary to form the Fermionic operator
driver = PySCFDriver(atom='H .0 .0 .0; H .0 .0 0.735',
                     unit=DistanceUnit.ANGSTROM,
                     basis='sto3g')
problem = driver.run()

# generate the second-quantized operators
main_op, _ = problem.second_q_ops()

num_particles = problem.num_particles
num_spatial_orbitals = problem.num_spatial_orbitals

# setup the classical optimizer for VQE
from qiskit.algorithms.optimizers import L_BFGS_B

optimizer = L_BFGS_B()

# setup the mapper and qubit converter
from qiskit_nature.second_q.mappers import ParityMapper
from qiskit_nature.second_q.mappers import QubitConverter

mapper = ParityMapper()
converter = QubitConverter(mapper=mapper, two_qubit_reduction=True)

# map to qubit operators
qubit_op = converter.convert(main_op, num_particles=num_particles)

# setup the initial state for the ansatz
from qiskit_nature.second_q.circuit.library import HartreeFock

init_state = HartreeFock(num_spatial_orbitals, num_particles, converter)

# setup the ansatz for VQE
from qiskit.circuit.library import TwoLocal

num_qubits = 2 * num_spatial_orbitals
ansatz = TwoLocal(num_qubits, ['ry', 'rz'], 'cz')

# add the initial state
ansatz.compose(init_state, front=True, inplace=True)

# setup and run VQE
from qiskit.algorithms.minimum_eigensolvers import VQE
from qiskit.primitives import Estimator

algorithm = VQE(Estimator(), ansatz, optimizer)

result = algorithm.compute_minimum_eigenvalue(qubit_op)
print(result.eigenvalue.real)

electronic_structure_result = problem.interpret(result)
print(electronic_structure_result)

The program above uses a quantum computer to calculate the ground state energy of molecular Hydrogen, H2, where the two atoms are configured to be at a distance of 0.735 angstroms. The molecular input specification is processed by the PySCF driver. This driver is wrapped by the ElectronicStructureProblem. This problem instance generates a list of second-quantized operators which we can map to qubit operators with a QubitConverter. Here, we chose the parity mapping in combination with a 2-qubit reduction, which is a precision-preserving optimization removing two qubits; a reduction in complexity that is particularly advantageous for NISQ computers.

The qubit operator is then passed as an input to the Variational Quantum Eigensolver (VQE) algorithm, instantiated with a classical optimizer and a RyRz ansatz (TwoLocal). A Hartree-Fock initial state is used as a starting point for the ansatz.

The VQE algorithm is then run, in this case using the noiseless Estimator primitive implemented in Qiskit Terra. For more information on the primitives refer to their documentation.

In the end, you are given a result object by the VQE which you can analyze further by interpreting it with your problem instance.

Further examples

Learning path notebooks may be found in the Nature Tutorials section of the documentation and are a great place to start

Jupyter notebooks containing further Nature examples may be found in the following Qiskit GitHub repositories at qiskit-nature/docs/tutorials.


Contribution Guidelines

If you'd like to contribute to Qiskit, please take a look at our contribution guidelines. This project adheres to Qiskit's code of conduct. By participating, you are expected to uphold this code.

We use GitHub issues for tracking requests and bugs. Please join the Qiskit Slack community for discussion and simple questions. For questions that are more suited for a forum, we use the Qiskit tag in Stack Overflow.

Authors and Citation

Qiskit Nature was inspired, authored and brought about by the collective work of a team of researchers. Qiskit Nature continues to grow with the help and work of many people, who contribute to the project at different levels. If you use Qiskit, please cite as per the provided BibTeX file.

Please note that if you do not like the way your name is cited in the BibTex file then consult the information found in the .mailmap file.

License

This project uses the Apache License 2.0.

However there is some code that is included under other licensing as follows:

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.0%
  • Fortran 1.7%
  • Other 0.3%