Avoid mutating optimal Givens input matrices#1344
Conversation
Cover repeated optimal_givens_decomposition calls with the same unitary matrix so the implementation must leave caller-owned arrays unchanged.
Use a private workspace copy for the in-place Givens rotations and phase rewrites so repeated decomposition calls with the same unitary remain deterministic.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request ensures that the optimal_givens_decomposition function does not mutate its input unitary matrix by creating a copy of it. A corresponding unit test has been added to verify that the input matrix remains unmodified and that consecutive function calls produce identical circuits. There are no review comments, so I have no feedback to provide.
Fixes #761.
What changed
Verification
.venv\Scripts\python.exe -m pytest -p no:cacheprovider src\openfermion\circuits\primitives\optimal_givens_decomposition_test.py -q.venv\Scripts\python.exe -m black --check --workers 1 src\openfermion\circuits\primitives\optimal_givens_decomposition.py src\openfermion\circuits\primitives\optimal_givens_decomposition_test.py.venv\Scripts\python.exe -B -c "import ast, pathlib; [ast.parse(pathlib.Path(p).read_text(encoding='utf-8'), filename=p) for p in ['src/openfermion/circuits/primitives/optimal_givens_decomposition.py','src/openfermion/circuits/primitives/optimal_givens_decomposition_test.py']]"git diff --check