Skip to content

Commit 53fa353

Browse files
authored
[Docs] update gen_ham with UHF (#339)
In this PR: We added UHF examples in 'molecular_hamiltonians.rst', 'generate_molecular_hamiltonians.py' This part of the doc covers the new update of UHF in #309
1 parent 0e885f2 commit 53fa353

File tree

3 files changed

+122
-19
lines changed

3 files changed

+122
-19
lines changed

docs/sphinx/components/solvers/introduction.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ The :code:`molecule_options` structure provides extensive configuration for mole
7575
+---------------------+---------------+------------------+------------------------------------------+
7676
| integrals_casscf | bool | false | Use CASSCF orbitals for integrals |
7777
+---------------------+---------------+------------------+------------------------------------------+
78-
| potfile | optional | nullopt | Path to external potential file |
79-
| | <string> | | |
80-
+---------------------+---------------+------------------+------------------------------------------+
8178
| verbose | bool | false | Enable detailed output logging |
8279
+---------------------+---------------+------------------+------------------------------------------+
8380

docs/sphinx/examples/solvers/python/generate_molecular_hamiltonians.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# [Begin Documentation]
1010
import cudaq_solvers as solvers
1111

12-
# Generate active space Hamiltonian using HF molecular orbitals
12+
# Generate active space Hamiltonian using RHF molecular orbitals
1313

1414
geometry = [('N', (0.0, 0.0, 0.5600)), ('N', (0.0, 0.0, -0.5600))]
1515
molecule = solvers.create_molecule(geometry,
@@ -20,7 +20,24 @@
2020
norb_cas=3,
2121
verbose=True)
2222

23-
print('N2 HF Hamiltonian')
23+
print('N2 RHF Hamiltonian')
24+
print('Energies : ', molecule.energies)
25+
print('No. of orbitals: ', molecule.n_orbitals)
26+
print('No. of electrons: ', molecule.n_electrons)
27+
28+
# Generate active space Hamiltonian using UHF molecular orbitals
29+
30+
geometry = [('N', (0.0, 0.0, 0.5600)), ('N', (0.0, 0.0, -0.5600))]
31+
molecule = solvers.create_molecule(geometry,
32+
'sto-3g',
33+
0,
34+
0,
35+
nele_cas=2,
36+
norb_cas=3,
37+
UR=True,
38+
verbose=True)
39+
40+
print('N2 UHF Hamiltonian')
2441
print('Energies : ', molecule.energies)
2542
print('No. of orbitals: ', molecule.n_orbitals)
2643
print('No. of electrons: ', molecule.n_electrons)
@@ -83,3 +100,36 @@
83100
print('Energies: ', molecule.energies)
84101
print('No. of orbitals: ', molecule.n_orbitals)
85102
print('No. of electrons: ', molecule.n_electrons)
103+
104+
# For open-shell systems: Generate active space Hamiltonian using ROHF molecular orbitals
105+
geometry = [('N', (0.0, 0.0, 0.5600)), ('N', (0.0, 0.0, -0.5600))]
106+
molecule = solvers.create_molecule(geometry,
107+
'sto-3g',
108+
1,
109+
1,
110+
nele_cas=3,
111+
norb_cas=3,
112+
ccsd=True,
113+
verbose=True)
114+
115+
print('N2+ ROHF Hamiltonian')
116+
print('Energies : ', molecule.energies)
117+
print('No. of orbitals: ', molecule.n_orbitals)
118+
print('No. of electrons: ', molecule.n_electrons)
119+
120+
# For open-shell systems: Generate active space Hamiltonian using UHF molecular orbitals
121+
geometry = [('N', (0.0, 0.0, 0.5600)), ('N', (0.0, 0.0, -0.5600))]
122+
molecule = solvers.create_molecule(geometry,
123+
'sto-3g',
124+
1,
125+
1,
126+
nele_cas=3,
127+
norb_cas=3,
128+
ccsd=True,
129+
UR=True,
130+
verbose=True)
131+
132+
print('N2+ UHF Hamiltonian')
133+
print('Energies : ', molecule.energies)
134+
print('No. of orbitals: ', molecule.n_orbitals)
135+
print('No. of electrons: ', molecule.n_electrons)

docs/sphinx/examples_rst/solvers/molecular_hamiltonians.rst

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ Generating Molecular Hamiltonians
22
----------------------------------
33

44
The CUDA-Q Solvers library accelerates a wide range of applications in the domain of quantum chemistry.
5-
To facilitate these calculations, CUDA-Q Solvers provides the `solver.create_molecule` function to allow users to generate basis sets and Hamiltonians for many systems of interest.
6-
The molecule class contains basis set informations, and the Hamiltonian (`molecule.hamiltonian`) for the target systems.
5+
To facilitate these calculations, CUDA-Q Solvers provides the `solver.create_molecule` function to allow users to generate the electronic Hamiltonians for many systems of interest.
6+
The molecule class contains informations about the Hamiltonian (`molecule.hamiltonian`) for the target systems.
77
These Hamiltonians can then be used as input into the hybrid quantum-classical solvers that the CUDA-Q Solvers API provides.
88

99

1010
Molecular Orbitals and Hamiltonians
1111
+++++++++++++++++++++++++++++++++++
1212

13-
First we define the atomic geometry of the molecule by specifying a array of atomic symbols as strings, and coordinates in 3D space. We then get a molecule object from the `solvers.create_molecule` call.
14-
Here we create "default" Hamiltonian for the N2 system using complete active space molecular orbitals constructed from Hartree-Fock atomic orbitals.
13+
First, we define the atomic geometry of the molecule by specifying an array of atomic symbols as strings, and coordinates in 3D space. We then get a molecule object from the `solvers.create_molecule` call.
14+
Here, we create "default" Hamiltonian for the N2 system using complete active space molecular orbitals constructed from Restricted Hartree-Fock molecular orbitals.
1515

1616
.. tab:: Python
1717

@@ -27,15 +27,32 @@ Here we create "default" Hamiltonian for the N2 system using complete active spa
2727
verbose=True)
2828
2929
We specify:
30-
- The geometry previously created
31-
- The single particle basis set (here STO-3G)
32-
- The total spin
30+
- The geometry previously created. User can also provide geometry through the path to the XYZ file. For example, `geometry='path/to/xyz/file.xyz'`.
31+
- The basis set (here STO-3G)
32+
- The total spin (2 * S)
3333
- The total charge
3434
- The number of electrons in the complete active space
35-
- The number of orbitals in the complete activate space
35+
- The number of orbitals in the complete active space
3636
- A verbosity flag to help introspect on the data what was generated.
3737

38-
Along with the orbitals and Hamiltonian, we can also view various properties like the Hartree-Fock energy, and the energy of the frozen core orbitals by printing `molecule.energies`.
38+
Along with the Hamiltonian, we can also view various properties like the Hartree-Fock energy, and the energy of the frozen core orbitals by printing `molecule.energies`.
39+
40+
For using Unrestricted Hartree-Fock (UHF) orbitals, user can set the `UR` parameter to `True` in the `create_molecule` function. Here's an example:
41+
42+
.. tab:: Python
43+
44+
.. code-block:: python
45+
46+
geometry = [('N', (0.0, 0.0, 0.5600)), ('N', (0.0, 0.0, -0.5600))]
47+
molecule = solvers.create_molecule(geometry,
48+
'sto-3g',
49+
0,
50+
0,
51+
nele_cas=2,
52+
norb_cas=3,
53+
UR=True,
54+
verbose=True)
55+
3956
4057
Natural Orbitals from MP2
4158
++++++++++++++++++++++++++
@@ -56,12 +73,15 @@ Now we take our same N2 molecule, but generate natural orbitals from second orde
5673
integrals_natorb=True,
5774
verbose=True)
5875
59-
Note that we use the same API but,toggle `MP2=True` and `integrals_natorb=True`.
76+
Note that we use the same API but,toggle `MP2=True` and `integrals_natorb=True`. This will generate the molecular orbitals from MP2 natural orbitals, and compute the Hamiltonian integrals in this basis.
77+
This option is not yet available when using `UR=True`. When using `UR=True`, only UHF molecular orbitals are employed to generate the electronic Hamiltonian.
6078

6179
CASSCF Orbitals
6280
+++++++++++++++
6381

64-
Next, we can start from either Hartree-Fock or perturbation theory atomic orbitals and build complete active space self-consistent field (CASSCF) molecular orbitals.
82+
Next, we can start from either Hartree-Fock or perturbation theory natural orbitals and build complete active space self-consistent field (CASSCF) molecular orbitals.
83+
84+
In the example below, we employ the CASSCF procedure starting from RHF molecular orbitals to generate the spin molecular Hamiltonian.
6585

6686
.. tab:: Python
6787

@@ -78,7 +98,8 @@ Next, we can start from either Hartree-Fock or perturbation theory atomic orbita
7898
integrals_casscf=True,
7999
verbose=True)
80100
81-
For Hartree-Fock, or
101+
Alternatively, we can also start from RHF, then MP2 natural orbitals and then perform CASSCF to generate the spin molecular Hamiltonian.
102+
In this case, natural orbitals from MP2 are used to set the active space for the CASSCF procedure.
82103

83104
.. tab:: Python
84105

@@ -97,7 +118,42 @@ For Hartree-Fock, or
97118
integrals_casscf=True,
98119
verbose=True)
99120
100-
for MP2. In these cases, printing the `molecule.energies` also shows the `R-CASSCF` energy for the system.
121+
In these cases, printing the `molecule.energies` also shows the `R-CASSCF` energy for the system.
101122

102-
Now that we have seen how to generate basis sets and Hamiltonians for quantum chemistry systems, we can use these as inputs to hybrid quantum-classical methods like VQE or adapt VQE via the CUDA-Q Solvers API.
103123

124+
For open-shell systems
125+
++++++++++++++++++++++++++
126+
127+
For Restricted Open-shell Hartree-Fock (ROHF) orbitals, user can set the `spin` parameter to a non-zero value while keeping the `charge` parameter as needed. For example, for a molecule with one unpaired electron, you can set `spin=1` and `charge=1`. Here's an example:
128+
129+
.. tab:: Python
130+
131+
.. code-block:: python
132+
133+
geometry = [('N', (0.0, 0.0, 0.5600)), ('N', (0.0, 0.0, -0.5600))]
134+
molecule = solvers.create_molecule(geometry,
135+
'sto-3g',
136+
1,
137+
1,
138+
nele_cas=3,
139+
norb_cas=3,
140+
verbose=True)
141+
142+
143+
For Unrestricted Hartree-Fock (UHF) orbitals, user can set `UR=True` and the `spin` parameter to a non-zero value while keeping the `charge` parameter as needed. Here's an example:
144+
145+
.. tab:: Python
146+
147+
.. code-block:: python
148+
149+
geometry = [('N', (0.0, 0.0, 0.5600)), ('N', (0.0, 0.0, -0.5600))]
150+
molecule = solvers.create_molecule(geometry,
151+
'sto-3g',
152+
1,
153+
1,
154+
nele_cas=3,
155+
norb_cas=3,
156+
UR=True,
157+
verbose=True)
158+
159+
Now that we have seen how to generate the spin molecular Hamiltonians for quantum chemistry systems, we can use these as inputs to hybrid quantum-classical methods like VQE or adapt VQE via the CUDA-Q Solvers API.

0 commit comments

Comments
 (0)