Skip to content

Commit

Permalink
givens decomposition: apply zrot without copying matrix (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung authored May 8, 2024
1 parent e139f89 commit 13c962f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions python/ffsim/linalg/givens.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,15 @@ def givens_decomposition(
right_rotations.append(
GivensRotation(c, s, target_index + 1, target_index)
)
current_matrix = current_matrix.T.copy()
(
current_matrix[target_index + 1],
current_matrix[target_index],
current_matrix[:, target_index + 1],
current_matrix[:, target_index],
) = zrot(
current_matrix[target_index + 1],
current_matrix[target_index],
current_matrix[:, target_index + 1],
current_matrix[:, target_index],
c,
s,
)
current_matrix = current_matrix.T
else:
# rotate rows by left multiplication
for j in range(i + 1):
Expand Down
10 changes: 4 additions & 6 deletions python/ffsim/qiskit/gates/slater_determinant.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,14 @@ def _givens_decomposition_slater(orbital_coeffs: np.ndarray) -> list[GivensRotat
# zero out element j of row i
c, s = zrotg(current_matrix[i, j - 1], current_matrix[i, j])
rotations.append(GivensRotation(c, s, j, j - 1))
current_matrix = current_matrix.T.copy()
(
current_matrix[j - 1],
current_matrix[j],
current_matrix[:, j - 1],
current_matrix[:, j],
) = zrot(
current_matrix[j - 1],
current_matrix[j],
current_matrix[:, j - 1],
current_matrix[:, j],
c,
s,
)
current_matrix = current_matrix.T

return rotations[::-1]

0 comments on commit 13c962f

Please sign in to comment.