Your First Quantum Chemistry Calculation
In this example, we calculate the ground state energy of the Lithium Hydride (LiH) molecule
using a minimal basis set (STO-3G) and the FAST Variational Quantum Eigensolver (FAST-VQE).
Note
If the names below sound new, skim Quantum Circuits for Computational Chemists and What Is an Adaptive-VQE and FAST-VQE for the chemistry to quantum translation and why FAST-VQE is the superior method for NISQ ( Noisy Intermediate-Scale Quantum) devices.
Full Script
The script below shows the minimal setup to define the molecule, build the ground state problem, and run the calculation.
1"""Run FAST-VQE on LiH as the first script."""
2
3import qrunch as qc
4
5
6
7def main() -> float:
8 """Run FAST-VQE on LiH as the first script."""
9 # Build molecular configuration for Lithium Hydride (LiH) molecule.
10 molecular_configuration = qc.build_molecular_configuration(
11 molecule=[
12 ("H", 0.0, 0.0, 0.0),
13 ("Li", 1.5474, 0.0, 0.0),
14 ],
15 basis_set="sto3g",
16 )
17
18 # Build the ground state problem.
19 problem_builder = qc.problem_builder_creator().ground_state().standard().create()
20 ground_state_problem = problem_builder.build_restricted(molecular_configuration)
21
22 fast_vqe_calculator = qc.calculator_creator().vqe().iterative().standard().create()
23
24 result = fast_vqe_calculator.calculate(ground_state_problem)
25
26 return result.total_energy.value
27
28
29if __name__ == "__main__":
30 main()
We will now explain this script line by line.
Explanation
Import the QDK library
import qrunch as qc
import qrunch as qc loads the public and stable API.
This is the only import you need for most tasks, and the only one
that is guaranteed to be supported across versions.
Define the molecular configuration
# Build molecular configuration for Lithium Hydride (LiH) molecule.
molecular_configuration = qc.build_molecular_configuration(
molecule=[
("H", 0.0, 0.0, 0.0),
("Li", 1.5474, 0.0, 0.0),
],
basis_set="sto3g",
)
We specify a simple Lithium Hydride molecule with Cartesian coordinates (in Ångström)
and the minimal basis set STO-3G.
Build the ground state problem
# Build the ground state problem.
problem_builder = qc.problem_builder_creator().ground_state().standard().create()
ground_state_problem = problem_builder.build_restricted(molecular_configuration)
The problem_builder is an object that can construct the electronic structure problem
of a given molecular configuration. Thus this define how to obtain the molecular integrals
and the active space.
The problem_builder.build_restricted(molecular_configuration) create the
restricted ground state electronic structure problem (The molecular integrals, etc.)
for LiH.
Create the VQE calculator
fast_vqe_calculator = qc.calculator_creator().vqe().iterative().standard().create()
The calculator defines the quantum algorithm used to solve the problem. By default, the adaptive VQE pipeline selects FAST-VQE for a compact, hardware-friendly ansatz. The calculation is done using our proprietary ExcitationGateSimulator (a quantum simulator optimized for chemistry) as default.
Calculate the energy
result = fast_vqe_calculator.calculate(ground_state_problem)
Calling fast_vqe_calculator.calculate(ground_state_problem) performs the actual calculation
and returns a result object.
The result object contains the total energy and other properties of the calculated ground state.
Running the Example
After saving the script as run_lithium_hydride.py,
you can run it directly from the command line:
$ python run_lithium_hydride.py
You should see output similar to the following:
Total energy: -7.882245617108695
Tip
Values vary slightly due to numerical precision. If your value is close, the setup works.