Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix docstrings in hf module #1853

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pennylane/hf/hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def generate_electron_integrals(mol, core=None, active=None):
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> alpha = np.array([[3.42525091, 0.62391373, 0.1688554],
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True)
>>> mol = Molecule(symbols, geometry, alpha=alpha)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> args = [alpha]
>>> generate_electron_integrals(mol)(*args)
(1.0,
Expand Down Expand Up @@ -157,7 +157,7 @@ def generate_fermionic_hamiltonian(mol, cutoff=1.0e-12, core=None, active=None):
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> alpha = np.array([[3.42525091, 0.62391373, 0.1688554],
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True)
>>> mol = Molecule(symbols, geometry, alpha=alpha)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> args = [alpha]
>>> h = generate_fermionic_hamiltonian(mol)(*args)
"""
Expand Down Expand Up @@ -220,7 +220,7 @@ def generate_hamiltonian(mol, cutoff=1.0e-12, core=None, active=None):
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> alpha = np.array([[3.42525091, 0.62391373, 0.1688554],
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True)
>>> mol = Molecule(symbols, geometry, alpha=alpha)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> args = [alpha]
>>> h = generate_hamiltonian(mol)(*args)
>>> h.terms[0]
Expand Down
12 changes: 6 additions & 6 deletions pennylane/hf/hartree_fock.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def generate_scf(mol, n_steps=50, tol=1e-8):
>>> symbols = ['H', 'H']
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> alpha = np.array([[3.42525091, 0.62391373, 0.1688554],
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True),
>>> mol = Molecule(symbols, geometry, alpha=alpha)
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> args = [alpha]
>>> v_fock, coeffs, fock_matrix, h_core, repulsion_tensor = generate_hartree_fock(mol)(*args)
>>> v_fock, coeffs, fock_matrix, h_core, repulsion_tensor = generate_scf(mol)(*args)
>>> v_fock
array([-0.67578019, 0.94181155])
"""
Expand Down Expand Up @@ -192,7 +192,7 @@ def nuclear_energy(charges, r):

>>> symbols = ['H', 'F']
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 2.0]], requires_grad = True)
>>> mol = Molecule(symbols, geometry)
>>> mol = qml.hf.Molecule(symbols, geometry)
>>> args = [mol.coordinates]
>>> e = nuclear_energy(mol.nuclear_charges, mol.coordinates)(*args)
>>> print(e)
Expand Down Expand Up @@ -235,8 +235,8 @@ def hf_energy(mol):
>>> symbols = ['H', 'H']
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> alpha = np.array([[3.42525091, 0.62391373, 0.1688554],
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True),
>>> mol = Molecule(symbols, geometry, alpha=alpha)
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> args = [alpha]
>>> hf_energy(mol)(*args)
-1.065999461545263
Expand Down
15 changes: 8 additions & 7 deletions pennylane/hf/integrals.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def primitive_norm(l, alpha):

>>> l = (0, 0, 0)
>>> alpha = np.array([3.425250914])
>>> n = gaussian_norm(l, alpha)
>>> n = primitive_norm(l, alpha)
>>> print(n)
array([1.79444183])
"""
Expand Down Expand Up @@ -240,7 +240,7 @@ def gaussian_overlap(la, lb, ra, rb, alpha, beta):
**Example**

>>> la, lb = (0, 0, 0), (0, 0, 0)
>>> ra, rb = np.array(([0., 0., 0.]), np.array(([0., 0., 0.])
>>> ra, rb = np.array([0., 0., 0.]), np.array([0., 0., 0.])
>>> alpha = np.array([np.pi/2])
>>> beta = np.array([np.pi/2])
>>> o = gaussian_overlap(la, lb, ra, rb, alpha, beta)
Expand Down Expand Up @@ -268,7 +268,7 @@ def generate_overlap(basis_a, basis_b):

>>> symbols = ['H', 'H']
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> mol = Molecule(symbols, geometry)
>>> mol = qml.hf.Molecule(symbols, geometry)
>>> args = []
>>> generate_overlap(mol.basis_set[0], mol.basis_set[0])(*args)
1.0
Expand Down Expand Up @@ -372,7 +372,8 @@ def gaussian_kinetic(la, lb, ra, rb, alpha, beta):
**Example**

>>> la, lb = (0, 0, 0), (0, 0, 0)
>>> ra, rb = np.array(([0., 0., 0.]), np.array(([0., 0., 0.])
>>> ra = np.array([0., 0., 0.])
>>> rb = rb = np.array([0., 0., 0.])
>>> alpha = np.array([np.pi/2])
>>> beta = np.array([np.pi/2])
>>> t = gaussian_kinetic(la, lb, ra, rb, alpha, beta)
Expand Down Expand Up @@ -425,7 +426,7 @@ def generate_kinetic(basis_a, basis_b):
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> alpha = np.array([[3.425250914, 0.6239137298, 0.168855404],
>>> [3.425250914, 0.6239137298, 0.168855404]], requires_grad = True)
>>> mol = hf.Molecule(symbols, geometry, alpha=alpha)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> args = [mol.alpha]
>>> generate_kinetic(mol.basis_set[0], mol.basis_set[1])(*args)
0.38325367405312843
Expand Down Expand Up @@ -633,7 +634,7 @@ def generate_attraction(r, basis_a, basis_b):
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> alpha = np.array([[3.425250914, 0.6239137298, 0.168855404],
>>> [3.425250914, 0.6239137298, 0.168855404]], requires_grad = True)
>>> mol = Molecule(symbols, geometry, alpha=alpha)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> basis_a = mol.basis_set[0]
>>> basis_b = mol.basis_set[1]
>>> args = [mol.alpha]
Expand Down Expand Up @@ -783,7 +784,7 @@ def generate_repulsion(basis_a, basis_b, basis_c, basis_d):
>>> [3.425250914, 0.6239137298, 0.168855404],
>>> [3.425250914, 0.6239137298, 0.168855404],
>>> [3.425250914, 0.6239137298, 0.168855404]], requires_grad = True)
>>> mol = Molecule(symbols, geometry, alpha=alpha)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> basis_a = mol.basis_set[0]
>>> basis_b = mol.basis_set[1]
>>> args = [mol.alpha]
Expand Down
32 changes: 16 additions & 16 deletions pennylane/hf/matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def molecular_density_matrix(n_electron, c):

>>> c = np.array([[-0.54828771, 1.21848441], [-0.54828771, -1.21848441]])
>>> n_electron = 2
>>> density_matrix(n_electron, c)
>>> molecular_density_matrix(n_electron, c)
array([[0.30061941, 0.30061941], [0.30061941, 0.30061941]])
"""
p = anp.dot(c[:, : n_electron // 2], anp.conjugate(c[:, : n_electron // 2]).T)
Expand All @@ -69,10 +69,10 @@ def generate_overlap_matrix(basis_functions):
>>> symbols = ['H', 'H']
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> alpha = np.array([[3.42525091, 0.62391373, 0.1688554],
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True),
>>> mol = Molecule(symbols, geometry, alpha=alpha)
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> args = [alpha]
>>> overlap_matrix(mol.basis_set)(*args)
>>> generate_overlap_matrix(mol.basis_set)(*args)
array([[1.0, 0.7965883009074122], [0.7965883009074122, 1.0]])
"""

Expand Down Expand Up @@ -119,10 +119,10 @@ def generate_kinetic_matrix(basis_functions):
>>> symbols = ['H', 'H']
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> alpha = np.array([[3.42525091, 0.62391373, 0.1688554],
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True),
>>> mol = Molecule(symbols, geometry, alpha=alpha)
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> args = [alpha]
>>> kinetic_matrix(mol.basis_set)(*args)
>>> generate_kinetic_matrix(mol.basis_set)(*args)
array([[0.76003189, 0.38325367], [0.38325367, 0.76003189]])
"""

Expand Down Expand Up @@ -172,10 +172,10 @@ def generate_attraction_matrix(basis_functions, charges, r):
>>> symbols = ['H', 'H']
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> alpha = np.array([[3.42525091, 0.62391373, 0.1688554],
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True),
>>> mol = Molecule(symbols, geometry, alpha=alpha)
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> args = [alpha]
>>> attraction_matrix(mol.basis_set, mol.nuclear_charges, mol.coordinates)(*args)
>>> generate_attraction_matrix(mol.basis_set, mol.nuclear_charges, mol.coordinates)(*args)
array([[-2.03852057, -1.60241667], [-1.60241667, -2.03852057]])
"""

Expand Down Expand Up @@ -241,10 +241,10 @@ def generate_repulsion_tensor(basis_functions):
>>> symbols = ['H', 'H']
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> alpha = np.array([[3.42525091, 0.62391373, 0.1688554],
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True),
>>> mol = Molecule(symbols, geometry, alpha=alpha)
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> args = [alpha]
>>> repulsion_tensor(mol.basis_set)(*args)
>>> generate_repulsion_tensor(mol.basis_set)(*args)
array([[[[0.77460595, 0.56886144], [0.56886144, 0.65017747]],
[[0.56886144, 0.45590152], [0.45590152, 0.56886144]]],
[[[0.56886144, 0.45590152], [0.45590152, 0.56886144]],
Expand Down Expand Up @@ -319,10 +319,10 @@ def generate_core_matrix(basis_functions, charges, r):
>>> symbols = ['H', 'H']
>>> geometry = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], requires_grad = False)
>>> alpha = np.array([[3.42525091, 0.62391373, 0.1688554],
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True),
>>> mol = Molecule(symbols, geometry, alpha=alpha)
>>> [3.42525091, 0.62391373, 0.1688554]], requires_grad=True)
>>> mol = qml.hf.Molecule(symbols, geometry, alpha=alpha)
>>> args = [alpha]
>>> core_matrix(mol.basis_set, mol.nuclear_charges, mol.coordinates)(*args)
>>> generate_core_matrix(mol.basis_set, mol.nuclear_charges, mol.coordinates)(*args)
array([[-1.27848869, -1.21916299], [-1.21916299, -1.27848869]])
"""

Expand Down
2 changes: 1 addition & 1 deletion pennylane/hf/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Molecule:
**Example**

>>> symbols = ['H', 'H']
>>> geometry = pnp.array([[0.0, 0.0, -0.694349],
>>> geometry = np.array([[0.0, 0.0, -0.694349],
>>> [0.0, 0.0, 0.694349]], requires_grad = True)
>>> mol = Molecule(symbols, geometry)
>>> print(mol.n_electrons)
Expand Down