def grid_indices(qubit_id, n_dimensions, grid_length, spinless):
    """This function is the inverse of orbital_id.

    Args:
        qubit_id: The tensor factor to map to grid indices.
        n_dimensions: An int giving the number of dimensions for the model.
        grid_length (int): The number of points in one dimension of the grid.
        spinless (bool): Whether to use the spinless model or not.

    Returns:
        grid_indices: The location of the qubit on the grid.
    """
    # Remove spin degree of freedom.
    orbital_id = qubit_id
    if not spinless:
        if (orbital_id % 2):
            orbital_id -= 1
        orbital_id /= 2

    # Get grid indices.
    grid_indices = []
    for dimension in range(n_dimensions):
        remainder = orbital_id % (grid_length ** (dimension + 1))
        grid_index = remainder // (grid_length ** dimension)
        grid_indices += [grid_index]
    return grid_indices