1
$\begingroup$

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?

$\endgroup$

1 Answer 1

2
$\begingroup$

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 $$

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$
    – dnaik
    Commented Jun 18 at 18:04
  • $\begingroup$ 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. $\endgroup$
    – diemilio
    Commented Jun 18 at 18:35
  • $\begingroup$ 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 $\endgroup$
    – dnaik
    Commented Jun 18 at 18:59
  • $\begingroup$ @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$. $\endgroup$
    – Tristan Nemoz
    Commented Jun 19 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.