-
Notifications
You must be signed in to change notification settings - Fork 989
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
optimize_for_target_gateset
does not return equivalent circuit
#6517
Comments
doesn't looklike an issue in the specifically decomposing the third operation doesn't yield a correct result >> op = XXPowGate(exponent=2.3059912502413593, global_shift=5.787646153894631).on(qr[3], qr[4]).controlled_by(qr[1])
>> c = cirq.Circuit(cirq.decompose(op))
>> print(cirq.equal_up_to_global_phase(cirq.unitary(c), cirq.unitary(op)))
False |
diving deeper the decomposition reaches a controlled >> op = cirq.CZPowGate(exponent=-4.611982500482719, global_shift=-2.8938230769473154).on(cirq.LineQubit(3), cirq.LineQubit(4)).controlled_by(cirq.LineQubit(1))
>> c = cirq.Circuit(op._decompose_())
>> print(cirq.equal_up_to_global_phase(cirq.unitary(c), cirq.unitary(op)))
False |
the root cause is the hardcoded decomposition for controlled gate when the subgate is CZPowGate, which turns a CZPowGate into a Controlled - ZPowGate. this transformation misses at least a phase which becomes problematic for the controlled version Cirq/cirq-core/cirq/ops/controlled_gate.py Lines 178 to 202 in decf16d
Suggested fix: Add a correction operation on line Cirq/cirq-core/cirq/ops/controlled_gate.py Lines 200 to 202 in decf16d
|
We should change the In hindsight, we probably shouldn't have added so many special cases to the decomposition of |
Description of the issue
The document says
optimize_for_target_gateset
returns "An equivalent circuit containing gates accepted by gateset." However, applyingoptimize_for_target_gateset
to the below circuit generates a new circuit with a different final state vector.Note that the final state vectors have a large difference (atol >= 1e-3).
How to reproduce the issue
Cirq version
You can get the cirq version by printing
cirq.__version__
. From the command line:The text was updated successfully, but these errors were encountered: