# How do I apply the negative of a gate in Qiskit

I am running an algorithm where I need to apply gate1 to certain qubits and -1*gate1 to others. Any idea how I can do that in Qiskit?

The -1 in your expression can be treated as a global phase. This can be easily seen if you take a simple 2-qubit example. Consider the state $$|\psi\rangle$$:

$$|\psi_0\rangle = |q_1\rangle \otimes |q_0\rangle,$$

to which you want to apply $$-U$$ on qubit $$0$$ and $$U$$ on qubit $$1$$:

\begin{aligned} |\psi_1\rangle &= U|q_1\rangle \otimes (-U)|q_0\rangle, \\ \\ |\psi_1\rangle &= -\left(U|q_1\rangle \otimes U|q_0\rangle\right) \\ \\ |\psi_1\rangle &= e^{i\pi}\left(U|q_1\rangle \otimes U|q_0\rangle\right) \end{aligned}

So this is equivalent to applying a global phase of $$\pi$$. For more than one gate application with a $$-1$$, simply use a global phase of $$\pi$$ if the number if odd, or don't apply the global phase if the number is even.

Just remember that a global phase has no effect in the outcome of your results, so might as well ignore it.

If you insist in adding a global phase, you can do this in qiskit by using the GlobalPhaseGate gate:

from math import pi
from qiskit import QuantumCircuit
from qiskit.circuit.library import GlobalPhaseGate

qc = QuantumCircuit(2)
qc.h([0,1])
qc.append(GlobalPhaseGate(pi))


or by using the global_phase parameter in the QuantumCircuit object:

qc = QuantumCircuit(2, global_phase=pi)
qc.h([0,1])


These examples will result in the statevector:

$$|\psi\rangle = -\frac{1}{2}|00\rangle -\frac{1}{2}|01\rangle -\frac{1}{2}|10\rangle -\frac{1}{2}|11\rangle$$

• Thanks. I don't see why you say that the global phase has no effect in the outcome. That would be true if I was performing a measurement right after applying the phase, but it certainly would affect future interactions with other qubits. Commented Jun 18 at 18:04
• Not really. No matter what other unitaries you apply after acquiring a global phase, the outcome probabilities remain unchanged. It is completely undetectable. That is why is called global. Commented Jun 18 at 18:35
• True but I plan to apply a 'global' phase change to only the first few qubits in my circuit, so It's not really global in that sense Commented Jun 18 at 18:59
• @dnaik Yes it still is. If you apply $-U$ to the first qubits in your circuits for instance, it means that you are applying $-U\otimes I$ on the whole circuit, which is equal to $-(U\otimes I)$. Unless you apply a controlled version of $-U$, there is no way to change the probabilities using $-U$ instead of $U$. Commented Jun 19 at 7:52