-
Notifications
You must be signed in to change notification settings - Fork 1k
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
ZPowGate to QASM false conversion #6726
Comments
For the time being, I'd appreciate guidance on how I can implement |
So, I got some decompositions for XPow, YPow, and ZPow, but having some trouble with their controlled versions. I am for instance trying the decomposition for a controlled XPow gate, and not quite sure what the decomposition would be. For XPow itself I did self.RX(exponent * np.pi, qubit_indices)
self.GlobalPhase(exponent * np.pi/2)
if global_shift != 0:
self.GlobalPhase(global_shift * np.pi/2) The tricky part is that the controlled version wouldn't be self.CRX(exponent * np.pi, control_index, target_index)
self.GlobalPhase(exponent * np.pi/2)
if global_shift != 0:
self.GlobalPhase(global_shift * np.pi/2) It would need a controlled global phase gate too, which I don't think exists, as global phase is not really a gate, but more of a global correction. I don't really know how a conditional global phase gate could be implemented. IIRC qiskit just calculates the unitary when it creates the conditional version of it, so I'd really try to stay away from gates that use conditional global phase. |
The only solution I can immediately think of is implementing its underlying unitary matrix instead, and decomposing it to a qubit qubit sequence of gates just like any other two qubit gates. This is not ideal, as the explicit decomposition could be more efficient. |
I'll try to clean up and make a PR on the |
I'm playing around with the idea of applying the unitary of the global phase to an actual qubit. So, it sounds very stupid as global phase is a property that's applied to the entire system, but from some testing, if we apply the global phase as a single qubit gate (its unitary representation) to any of the qubits, it behaves the same way as applying a global phase gate. This way, we can account for global phase I think a tad easier. I did question myself ALOT about this idea, and still am, but I made sure the code was correct and the equality was properly checked. I also did the check for gradual accumulation of the global phases and it basically behaves the same way, you'd apply another and another gate. from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
qc_1 = QuantumCircuit(3)
qc_2 = QuantumCircuit(3)
qc_3 = QuantumCircuit(3)
qc_4 = QuantumCircuit(3)
# Define GHZ state
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
# Apply global phase
global_phase_angle = 1/3
global_phase = np.exp(1j * global_phase_angle) * np.identity(2)
qc_1.global_phase = global_phase_angle
qc_2.unitary(global_phase, [0])
qc_3.unitary(global_phase, [1])
qc_4.unitary(global_phase, [2])
# Define the unitary operators for each circuit
u1 = Operator(qc_1).data
u2 = Operator(qc_2).data
u3 = Operator(qc_3).data
u4 = Operator(qc_4).data
# Ensure all are equal
assert np.all([np.all(u1 == u2), np.all(u1 == u3), np.all(u1 == u4)]) P.S : If I have done some really stupid mistake, I apologize in advance. P.S : I think I can account for the controlled global phase by fixing the relative phase of the controlled indices using a MCPhase. |
Description of the issue
Greetings there,
Hope all are well. I am trying to implement the
quantum_shannon_decomposition.py
in qiskit, and to do that I need to representZPowGate
using gates such as Ry, Rz, global phase, and such. To see what the conversion is I used thecirq.qasm()
function, however, the conversion is wrong as can be seen below.How to reproduce the issue
Cirq version
The text was updated successfully, but these errors were encountered: