Skip to content

Commit

Permalink
fix: remove redundant reshape (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbeCoull authored Dec 6, 2024
1 parent cba0608 commit f1f9355
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/braket/default_simulator/density_matrix_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ def _apply_gate(
np.ndarray: output density matrix
"""
# left product
state = multiply_matrix(state, np.reshape(matrix, [2] * len(targets) * 2), targets)
state = multiply_matrix(state, matrix, targets)
# right product
state = multiply_matrix(
state,
np.reshape(matrix.conjugate(), [2] * len(targets) * 2),
matrix.conjugate(),
tuple(i + qubit_count for i in targets),
)
return state
Expand Down
3 changes: 1 addition & 2 deletions src/braket/default_simulator/linalg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ def _multiply_matrix(

# Axes given in `operation.targets` are in the first positions.
unused_idxs = [idx for idx in range(len(state.shape)) if idx not in targets]
permutation = list(targets) + unused_idxs
# Invert the permutation to put the indices in the correct place
inverse_permutation = np.argsort(permutation)
inverse_permutation = np.argsort([*targets, *unused_idxs])
return np.transpose(product, inverse_permutation)


Expand Down

0 comments on commit f1f9355

Please sign in to comment.