Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimal_givens_decomposition has bad side effects #761

Open
kevinsung opened this issue Dec 10, 2021 · 2 comments
Open

optimal_givens_decomposition has bad side effects #761

kevinsung opened this issue Dec 10, 2021 · 2 comments
Labels

Comments

@kevinsung
Copy link
Collaborator

If you call optimal_givens_decomposition and then construct another circuit using the same qubits, the latter circuit can be incorrect. For example, below I create two circuits that should be identical, but the second one is different and incorrect:

import cirq
from openfermion import optimal_givens_decomposition

n_qubits = 3
qubits = cirq.LineQubit.range(n_qubits)
mat = cirq.testing.random_unitary(n_qubits)

circuit1 = cirq.Circuit(optimal_givens_decomposition(qubits, mat))
circuit2 = cirq.Circuit(optimal_givens_decomposition(qubits, mat))
circuit1

0: ──────────────PhISwap(0.25)──────────────────────────────────────────────PhISwap(0.25)──────────Z^-0.577───
                 │                                                          │
1: ───Z^(-1/3)───PhISwap(0.25)^(-5/16)───PhISwap(0.25)───────────Z^0.351────PhISwap(0.25)^-0.435───Z^(1/7)────
                                         │
2: ───Z^0.255────────────────────────────PhISwap(0.25)^(-8/15)───Z^-0.284─────────────────────────────────────
circuit2

0: ───PhISwap(0.25)───────────────────────PhISwap(0.25)─────Z^-0.577───
      │                                   │
1: ───PhISwap(0.25)^0───PhISwap(0.25)─────PhISwap(0.25)^0───Z^(1/7)────
                        │
2: ─────────────────────PhISwap(0.25)^0───Z^-0.284─────────────────────
@ncrubin
Copy link
Collaborator

ncrubin commented Dec 11, 2021

This is because optimal_givens_decomposition is mutating the variable mat I think. Can you confirm this?

@kevinsung
Copy link
Collaborator Author

You're right, the issue is that mat is being mutated.

@kevinsung kevinsung added the bug label Dec 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants