# How does the pulse.Shiftphase instruction in Qiskit Pulse work? [closed]

I have some questions regarding the mechanism of Qiskit pulse.ShiftPhase instruction:

1. Does it work like a Phase Shift $$P(\theta)=\begin{bmatrix} 1 & 0 \\0 & e^{i\theta} \end{bmatrix}$$ gate, a Global Phase Shift $$Ph(\theta)=\begin{bmatrix} e^{i\theta} & 0 \\0 & e^{i\theta} \end{bmatrix}$$ gate, or a $$R_z(\theta)=\begin{bmatrix} e^{-i\theta/2} & 0 \\0 & e^{i\theta/2} \end{bmatrix}$$ gate?
2. I read that when I apply a ShiftPhase it'd affect all the pulses following, meaning everytime I apply a pulse there will be a phase shift gate right? So if I only want to apply only one RZ/PS/Global PS gate should I apply a reversal phase shift after a pulse, or would that equivalently mean I have applied a PS/GPS/RZ($$-\theta$$) gate?
3. How is the free Z rotation tracked by software in the case of a qutrit (3 energy levels) or more, and how does ShiftPhase work in this case?

Many thanks!

First note that your $$P(\theta)$$ and $$R_z(\theta)$$ gates are the same up to a global phase, so you will not be able to distinguish them.

Now, according to qiskit.pulse.ShiftPhase documentation:

The qubit phase is tracked in software, enabling instantaneous, nearly error-free Z-rotations by using a ShiftPhase to update the frame tracking the qubit state.

So the ShiftPhase pulse implements a $$R_z(\theta)$$ gate (or $$P(\theta)$$ as they are the same).

If you want to shift the phase only for one gate, you will have to apply a $$P(-\theta)$$ (via ShiftPhase) just after the gate. It is likely that the ShiftPhase will need a positive phase, as it should increase the phase according to the documentation:

The ShiftPhase instruction causes $$\phi$$ to be increased by the instruction’s phase operand.

In this case, you can use $$P(-\theta) = P(2\pi - \theta)$$ and still apply a ShiftPhase.

About your third question, the software (qiskit here?) is not aware of qutrits. It just "attach" to every pulse a given phase, pre-computed when the quantum circuit is transformed to a Schedule, and executes each pulse with its attached phase. There is no notion of $$n$$-level state here, it just impact the pulses. If your pulses explore a $$3$$-level state then so be it, but I do not think the phase-tracking part changes in any way.