@@ -64,13 +64,12 @@ def orbital_id(grid_length, grid_coordinates, spin=None):
6464 return tensor_factor
6565
6666
67- def grid_indices (qubit_id , n_dimensions , grid_length , spinless ):
67+ def grid_indices (qubit_id , grid , spinless ):
6868 """This function is the inverse of orbital_id.
6969
7070 Args:
7171 qubit_id: The tensor factor to map to grid indices.
72- n_dimensions: An int giving the number of dimensions for the model.
73- grid_length (int): The number of points in one dimension of the grid.
72+ grid (Grid): The discretization to use.
7473 spinless (bool): Whether to use the spinless model or not.
7574
7675 Returns:
@@ -85,9 +84,9 @@ def grid_indices(qubit_id, n_dimensions, grid_length, spinless):
8584
8685 # Get grid indices.
8786 grid_indices = []
88- for dimension in range (n_dimensions ):
89- remainder = orbital_id % (grid_length ** (dimension + 1 ))
90- grid_index = remainder // (grid_length ** dimension )
87+ for dimension in range (grid . dimensions ):
88+ remainder = orbital_id % (grid . length ** (dimension + 1 ))
89+ grid_index = remainder // (grid . length ** dimension )
9190 grid_indices += [grid_index ]
9291 return grid_indices
9392
@@ -414,10 +413,10 @@ def jordan_wigner_position_jellium(grid, spinless=False):
414413 # Add ZZ terms.
415414 prefactor = numpy .pi / volume
416415 for p in range (n_qubits ):
417- index_p = grid_indices (p , grid . dimensions , grid . length , spinless )
416+ index_p = grid_indices (p , grid , spinless )
418417 position_p = position_vector (index_p , grid )
419418 for q in range (p + 1 , n_qubits ):
420- index_q = grid_indices (q , grid . dimensions , grid . length , spinless )
419+ index_q = grid_indices (q , grid , spinless )
421420 position_q = position_vector (index_q , grid )
422421
423422 differences = position_p - position_q
@@ -437,13 +436,13 @@ def jordan_wigner_position_jellium(grid, spinless=False):
437436 # Add XZX + YZY terms.
438437 prefactor = .25 / float (n_orbitals )
439438 for p in range (n_qubits ):
440- index_p = grid_indices (p , grid . dimensions , grid . length , spinless )
439+ index_p = grid_indices (p , grid , spinless )
441440 position_p = position_vector (index_p , grid )
442441 for q in range (p + 1 , n_qubits ):
443442 if not spinless and (p + q ) % 2 :
444443 continue
445444
446- index_q = grid_indices (q , grid . dimensions , grid . length , spinless )
445+ index_q = grid_indices (q , grid , spinless )
447446 position_q = position_vector (index_q , grid )
448447
449448 differences = position_p - position_q
0 commit comments