Skip to content

Commit

Permalink
Fix unintended mutation of original matrix in swap_rows_columns_list
Browse files Browse the repository at this point in the history
Bug:
- When swapping rows and columns of a numpy array within the  function, the original matrix in memory was inadvertently modified due to mutable behavior of numpy arrays.

Fix:
- Created a copy of the input matrix inside the function before making any modifications. This ensures that only the copied matrix is altered, while the original matrix remains unchanged.
  • Loading branch information
evmckinney9 committed Oct 5, 2023
1 parent 476d0fb commit fad0d1d
Show file tree
Hide file tree
Showing 6 changed files with 1,884 additions and 237 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Variables
PYTHON_VERSION = python3.11
PYTHON_VERSION = python3.10
PIP = .venv/bin/pip
PYTEST = .venv/bin/pytest
PRE_COMMIT = .venv/bin/pre-commit
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ requires-python = ">=3.9"
dependencies = [
"scipy",
"qutip",
"numpy",
"numpy==1.23.5",
"qiskit",
"qiskit-aer",
"weylchamber",
Expand Down
6 changes: 6 additions & 0 deletions src/mirror_gates/fast_unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ def _compute_unitary(self, block, qubit_map) -> UnitaryGate:
# The qubit order is reversed
def swap_rows_columns_list(unitary):
"""Handle swapping qarg ordering."""
# make a copy to avoid mutable object errors
unitary = unitary.copy()

# # XXX no idea why this error occurs, but temp fix
# unitary.setflags(write=True)

unitary[:, [1, 2]] = unitary[:, [2, 1]]
unitary[[1, 2], :] = unitary[[2, 1], :]
return unitary
Expand Down
159 changes: 97 additions & 62 deletions src/notebooks/debug_bench.ipynb

Large diffs are not rendered by default.

210 changes: 37 additions & 173 deletions src/notebooks/results/bench.ipynb

Large diffs are not rendered by default.

1,742 changes: 1,742 additions & 0 deletions src/notebooks/results/debug_consolidate.ipynb

Large diffs are not rendered by default.

0 comments on commit fad0d1d

Please sign in to comment.