End-to-end with NWChem
In this article, you will walk through an example of getting gate counts for quantum chemistry simulation, starting from an NWChem input deck. Before proceeding with this example, make sure that you've installed Docker, following the installation and validation guide.
For more information:
Note
This example requires Windows PowerShell Core to run. Download PowerShell Core for Windows, macOS, or Linux at https://github.com/PowerShell/PowerShell.
Importing required PowerShell modules
If you haven't already done so, clone the Microsoft/Quantum repository, which contains samples and utilities for working with the Quantum Development Kit:
git clone https://github.com/Microsoft/Quantum
Once you've cloned Microsoft/Quantum
, perform cd
into the utilities/
folder and import the PowerShell module for working with Docker and NWChem:
cd utilities
Import-Module InvokeNWChem.psm1
Note
By default, Windows prevents the running of any scripts or modules as a security measure.
To allow modules such as Invoke-NWChem.psm1
to run on Windows, you may need to change the policy.
To do so, run the Set-ExecutionPolicy
command:
Set-ExecutionPolicy RemoteSigned -Scope Process
The policy will revert when you exit PowerShell.
If you would like to save the policy, use a different value for -Scope
:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
You should now have the Convert-NWChemToBroombridge
command available:
Get-Command -Module InvokeNWChem
Next, we'll import the Get-GateCount
command provided with the GetGateCount sample.
For full details, see the instructions provided with the sample.
Next, run the following, substituting <runtime>
with either win10-x64
, osx-x64
, or linux-x64
, depending on your operating system:
cd ../Chemistry/GetGateCount
dotnet publish --self-contained -r <runtime>
Import-Module ./bin/Debug/netcoreapp2.1/<runtime>/publish/get-gatecount.dll
You should now have the Get-GateCount
command available:
Get-Command Get-GateCount
Input decks
The NWChem package takes a text file called an input deck which specifies a quantum chemistry problem to be solved, along with other parameters such as memory allocation settings. For this example, we'll use one of the pre-made input decks that comes with NWChem. First, clone the nwchemgit/nwchem repository:
Note
Since this is a very large repository, we can do a shallow clone to save some bandwidth and disk space, using the --depth 1
argument.
This is optional, however.
Cloning will work just fine without --depth 1
.
git clone https://github.com/nwchemgit/nwchem --depth 1
The nwchemgit/nwchem
repository comes with a variety of input decks intended for use with the Quantum Development Kit, listed under the QA/chem_library_tests
folder.
For this example, we'll use the H4
input deck:
cd nwchem/QA/chem_library_tests/H4
Get-Content h4_sto6g_0.000.nw
The molecule in question is a system of 4 hydrogen atoms that are arranged in a certain geometry that depends on one angle, the parameter alpha
as indicated in the name h4_sto6g_alpha.nw
of the deck. H4 is a known molecular benchmark for computational chemistry since the 1970s. The parameter sto6g
is indicative that the deck implements a representation with respect to a Slater-type orbital, specifically, a representation with respect to an STO-nG basis set with 6 Gaussian basis functions. This input deck furthermore contains several instructions to the NWChem Tensor Contraction Engine (TCE) that direct NWChem to produce the information needed for interoperating with the Quantum Development Kit:
...
set tce:print_integrals T
set tce:qorb 18
set tce:qela 9
set tce:qelb 9
Producing and consuming Broombridge output from NWChem
You now have everything you need to produce and consume Broombridge documents.
To run NWChem and produce a Broombridge document for the h4_sto6g_0.000.nw
input deck, run Convert-NWChemToBroombridge
:
Note
The first time you run this command, Docker will download the nwchemorg/nwchem-qc
image for you.
This may take a little while, depending on your connection speed, possibly providing an opportunity to get a cup of coffee.
Convert-NWChemToBroombridge h4_sto6g_0.000.nw
This will produce a Broombridge document called h4_sto6g_0.000.yaml
that you can use with Get-GateCount
:
Get-GateCount -Format YAML h4_sto6g_0.000.yaml
You should now see console output which contains resource estimation such as T-count, rotations count, CNOT count, etc. for various quantum simulation methods:
IntegralDataPath : C:\Users\martinro\REPOS\nwchem\qa\chem_library_tests\h4\h4_sto6g_0.000.yaml
HamiltonianName : hamiltonian_0
SpinOrbitals : 8
Method : Trotter
TCount : 0
RotationsCount : 92
CNOTCount : 520
ElapsedMilliseconds : 327
IntegralDataPath : C:\Users\martinro\REPOS\nwchem\qa\chem_library_tests\h4\h4_sto6g_0.000.yaml
HamiltonianName : hamiltonian_0
SpinOrbitals : 8
Method : Qubitization
TCount : 438
RotationsCount : 516
CNOTCount : 2150
ElapsedMilliseconds : 528
IntegralDataPath : C:\Users\martinro\REPOS\nwchem\qa\chem_library_tests\h4\h4_sto6g_0.000.yaml
HamiltonianName : hamiltonian_0
SpinOrbitals : 8
Method : Optimized Qubitization
TCount : 3540
RotationsCount : 18
CNOTCount : 7932
ElapsedMilliseconds : 721
There are many things to go do from here:
- Try out different predefined input decks, for example, by varying the parameter
alpha
inh4_sto6g_alpha.nw
, - Try modifying the decks by editing the NWChem decks directly, for example, exploring
STO-nG
models for various choices of n, - Try other predefined NWChem input decks that are available at
nwchem/qa/chem_library_tests
, - Try out a suite of predefined Broombridge YAML benchmarks that were generated from NWChem and are available as part of the Microsoft/Quantum repository. These benchmarks include:
- small molecules such as molecular hydrogen (H2), Beryllium (Be), Lithium hydride (LiH),
- larger molecules such as ozone (O3), beta-carotene, cytosine, and many more.
- Try out the graphical front-end EMSL Arrows that features an interface to the Microsoft Quantum Development Kit.
Producing Broombridge output from EMSL Arrows
To get started with web-based front end EMSL Arrows, navigate a browser here.
Note
Running EMSL Arrows in a web browser requires JavaScript to be enabled. Please refer to these instructions on how to enable JavaScript in your browser.
First, enter a molecule in the query box Enter an esmiles, esmiles reaction, or other Arrows input, then push the "Run Arrows" button.
You can enter many molecules by their colloquial name, such as "caffeine" instead of "1,3,7-Trimethylxanthine".
Next, click theory{qsharp_chem}. This will populate the query box further with an instruction that will tell the run to export output in the Broombridge YAML format.
Now, click Run Arrows. Depending on the size of the input, this might take a while. Or, in case the particular model has already been computed before, it can be done extremely fast as it will only amount to a lookup in a database. In either case, you will be taken to a new page that contains a plethora of information about the particular run of NWChem against the deck specified by your input.
You can download and save the Broombridge YAML file from the section that starts with the following header:
+==================================================+
|| Molecular Calculation ||
+==================================================+
Id = 48443
NWOutput = Link to NWChem Output (download)
Datafiles:
qsharp_chem.yaml-2018-10-23-14:37:42 (download)
...
Click download, which saves a local copy with a unique file name, for example qsharp_chem48443.yaml (the particular name will be different for each run). You can then further process this file as above, for example, with
Get-GateCount -Format YAML qsharp_chem48443.yaml
to get resource counts.
You might enjoy the 3D molecule builder that can be accessed from the Arrows Entry - 3D Builder tab on the EMSL Arrows start page. Clicking the JSMol 3D picture of the shown molecule will let you allow to edit it. You can move atoms around, drag atoms apart so that their inter-molecular distances change, add/remove atoms, etc. For each of these choices, once you added theory{qsharp_chem} in the query box, you can then generate an instance of the Broombridge YAML schema and further explore it using the Quantum chemistry library.
Feedback
Submit and view feedback for