Skip to content

Commit c958f1b

Browse files
Strilancbabbush
authored andcommitted
Polish pydoc in _jellium.py (#58)
1 parent 7d20e39 commit c958f1b

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

src/fermilib/utils/_jellium.py

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def orbital_id(grid, grid_coordinates, spin=None):
3636
If None, assume spinless model.
3737
3838
Returns:
39-
tensor_factor: tensor factor associated with provided orbital label.
39+
tensor_factor (int):
40+
tensor factor associated with provided orbital label.
4041
"""
4142
# Initialize.
4243
if isinstance(grid_coordinates, int):
@@ -68,12 +69,13 @@ def grid_indices(qubit_id, grid, spinless):
6869
"""This function is the inverse of orbital_id.
6970
7071
Args:
71-
qubit_id: The tensor factor to map to grid indices.
72+
qubit_id (int): The tensor factor to map to grid indices.
7273
grid (Grid): The discretization to use.
7374
spinless (bool): Whether to use the spinless model or not.
7475
7576
Returns:
76-
grid_indices: The location of the qubit on the grid.
77+
grid_indices (numpy.ndarray[int]):
78+
The location of the qubit on the grid.
7779
"""
7880
# Remove spin degree of freedom.
7981
orbital_id = qubit_id
@@ -95,8 +97,9 @@ def position_vector(position_indices, grid):
9597
"""Given grid point coordinate, return position vector with dimensions.
9698
9799
Args:
98-
position_indices: List or tuple of integers giving grid point
99-
coordinate. Allowed values are ints in [0, grid_length).
100+
position_indices (int|iterable[int]):
101+
List or tuple of integers giving grid point coordinate.
102+
Allowed values are ints in [0, grid_length).
100103
grid (Grid): The discretization to use.
101104
102105
Returns:
@@ -111,8 +114,7 @@ def position_vector(position_indices, grid):
111114

112115
# Compute position vector.
113116
adjusted_vector = numpy.array(position_indices, float) - grid.length // 2
114-
position_vector = grid.scale * adjusted_vector / float(grid.length)
115-
return position_vector
117+
return grid.scale * adjusted_vector / float(grid.length)
116118

117119

118120
def momentum_vector(momentum_indices, grid):
@@ -136,8 +138,7 @@ def momentum_vector(momentum_indices, grid):
136138

137139
# Compute momentum vector.
138140
adjusted_vector = numpy.array(momentum_indices, float) - grid.length // 2
139-
momentum_vector = 2. * numpy.pi * adjusted_vector / grid.scale
140-
return momentum_vector
141+
return 2. * numpy.pi * adjusted_vector / grid.scale
141142

142143

143144
def momentum_kinetic_operator(grid, spinless=False):
@@ -178,19 +179,16 @@ def momentum_potential_operator(grid, spinless=False):
178179
179180
Args:
180181
grid (Grid): The discretization to use.
181-
spinless: Boole, whether to use the spinless model or not.
182+
spinless (bool): Whether to use the spinless model or not.
182183
183184
Returns:
184-
operator: An instance of the FermionOperator class.
185+
operator (FermionOperator)
185186
"""
186187
# Initialize.
187188
volume = grid.volume_scale()
188189
prefactor = 2. * numpy.pi / volume
189190
operator = FermionOperator((), 0.0)
190-
if spinless:
191-
spins = [None]
192-
else:
193-
spins = [0, 1]
191+
spins = [None] if spinless else [0, 1]
194192

195193
# Loop once through all plane waves.
196194
for omega_indices in grid.all_points_indices():
@@ -205,8 +203,7 @@ def momentum_potential_operator(grid, spinless=False):
205203
continue
206204

207205
# Compute coefficient.
208-
coefficient = prefactor / \
209-
omega_momenta.dot(omega_momenta)
206+
coefficient = prefactor / omega_momenta.dot(omega_momenta)
210207

211208
for grid_indices_a in grid.all_points_indices():
212209
shifted_indices_d = [
@@ -242,18 +239,15 @@ def position_kinetic_operator(grid, spinless=False):
242239
243240
Args:
244241
grid (Grid): The discretization to use.
245-
spinless: Bool, whether to use the spinless model or not.
242+
spinless (bool): Whether to use the spinless model or not.
246243
247244
Returns:
248-
operator: An instance of the FermionOperator class.
245+
operator (FermionOperator)
249246
"""
250247
# Initialize.
251248
n_points = grid.num_points()
252249
operator = FermionOperator()
253-
if spinless:
254-
spins = [None]
255-
else:
256-
spins = [0, 1]
250+
spins = [None] if spinless else [0, 1]
257251

258252
# Loop once through all lattice sites.
259253
for grid_indices_a in grid.all_points_indices():
@@ -289,19 +283,16 @@ def position_potential_operator(grid, spinless=False):
289283
290284
Args:
291285
grid (Grid): The discretization to use.
292-
spinless: Boole, whether to use the spinless model or not.
286+
spinless (bool): Whether to use the spinless model or not.
293287
294288
Returns:
295-
operator: An instance of the FermionOperator class.
289+
operator (FermionOperator)
296290
"""
297291
# Initialize.
298292
volume = grid.volume_scale()
299293
prefactor = 2. * numpy.pi / volume
300294
operator = FermionOperator()
301-
if spinless:
302-
spins = [None]
303-
else:
304-
spins = [0, 1]
295+
spins = [None] if spinless else [0, 1]
305296

306297
# Loop once through all lattice sites.
307298
for grid_indices_a in grid.all_points_indices():
@@ -364,10 +355,10 @@ def jordan_wigner_position_jellium(grid, spinless=False):
364355
365356
Args:
366357
grid (Grid): The discretization to use.
367-
spinless: Bool, whether to use the spinless model or not.
358+
spinless (bool): Whether to use the spinless model or not.
368359
369360
Returns:
370-
hamiltonian: An instance of the QubitOperator class.
361+
hamiltonian (QubitOperator)
371362
"""
372363
# Initialize.
373364
n_orbitals = grid.num_points()

0 commit comments

Comments
 (0)