7.3. Controlled- Z, S, T, P gates#
Recall that that Z, S, and T gates all change the phase of \(|1\rangle\) and that the general phase gate P(\(\theta\)) can replace them as Z = P(\(\pi\)), S = P(\(\pi/2\)), and T = P(\(\pi/4\)) (See Section 5.) In this section, controlled- Z, S, T, and P gates (CZ, CS, CT, and CP, respectively) are introduced. Since all of them work in the similar manner, only controlled-P is explained in most parts.
Operational Definition
When gate CP\(_{q_0}^{q_1}(\theta)\) acts on \(|q_1\, q_0\rangle\), P(\(\theta\)) is applied to \(q_1\) if \(q_0=1\) and nothing is done otherwise. Qubit \(q_0\) serves as source and \(q_1\) as target. AS shwon bellow, CP\(_{q_0}^{q_1}(\theta) =\) CP\(_{q_1}^{q_0}(\theta)\). Hence, it is not necessary to specify a source and a target qubit.
Mathematically, it is expressed as
Switching source and target qubits,
CP\(_{q_1}^{q_0} (\theta) |q_1\, q_0\rangle\) applies P(\(\theta\)) to \(q_0\) if \(q_1=1\) and do nothing otherwise. Mathematically, it is expressed as
Transformation
CP\(_{q_0}^{q_1}(\theta)\) and CP\(_{q_1}^{q_0}(\theta)\) transforms computational basis as follows:
Since only \(\lvert 11\rangle\) is affected, \(\text{CP}_{q_0}^{q_1}(\theta)= \text{CP}_{q_1}^{q_0}(\theta)\).
Matrix representation
7.3.1. Qiskit circuit functions#
The Qiskit circuit functions for CZ and CP are cz and cp, respectively and it appears in a circuit as follows. Unlike CX gate, the source and target are not distinguished.
q0_0: ─■──■─────
│ │P(θ)
q0_1: ─■──■─────
Qiskit does not have standard circuit functions for CS and CT but they are predefined in qiskit.circuit.library.standard_gates. You just have to create a shorthand expression from the library and use append function to add the gate to the circuit. We can always use CP(\(\pi/2\)) and CP(\(\pi/4\)) for CS and CT, respectively.
from qiskit.circuit.library.standard_gates import SGate, TGate
cs = SGate().control(1) # the parameter is the amount of control points you want
ct = TGate().control(1)
qr = QuantumRegister(2,'q')
qc = QuantumCircuit(qr)
qc.append(cs, [0, 1])
qc.append(ct, [0, 1])
qc.draw()
q_0: ──■────■──
┌─┴─┐┌─┴─┐
q_1: ┤ S ├┤ T ├
└───┘└───┘7.3.2. Acting on superposition state#
CP\(_{q_0}^{q_1}(\theta)\) multiplies phase factor \(e^{i\theta}\) only to \(|11\rangle\). Other basis vectors are not affected. Note also that the modulus of the coefficients remain the same and thus probabilities of finding the computational basis vectors are not modified by CP.
How can we change the phase of a basis vector other than \(|11\rangle\)? A possible strategy is to transform the target basis vector to \(|11\rangle\), apply CP and transform back to the original basis vector. For example, if we want to multiply \(i\) to \(|00\rangle\) without changing other basis vector, apply \((\text{X} \otimes \text{X}) \cdot \text{CS} \cdot (\text{X} \otimes \text{X})\)
Example
How can we change the phase of a basis vector other than \(|11\rangle\)? A possible strategy is to transform the target basis vector to \(|11\rangle\), apply CP and transform back to the original basis vector. For example, if we want to multiply \(i\) to \(|00\rangle\) without changing other basis vector, apply \((\text{X} \otimes \text{X}) \cdot \text{CS} \cdot (\text{X} \otimes \text{X})\). In this example, we start with a product state \(|+\rangle \otimes |+\rangle\). Then, the above gate is applied to it. Check that \(i\) is multiplied only to \(|00\rangle\). The final state is entangled. (See Section 6.1.
qr=QuantumRegister(2,'q')
qc = QuantumCircuit(qr)
# prepare a super position state
qc.h([0,1])
print("initial state")
Statevector(qc).draw('latex')
initial state
qc.barrier()
qc.x([0,1])
qc.cp(np.pi/2,0,1)
qc.x([0,1])
qc.draw()
┌───┐ ░ ┌───┐ ┌───┐
q_0: ┤ H ├─░─┤ X ├─■───────┤ X ├
├───┤ ░ ├───┤ │P(π/2) ├───┤
q_1: ┤ H ├─░─┤ X ├─■───────┤ X ├
└───┘ ░ └───┘ └───┘print("final state")
Statevector(qc).draw('latex')
final state
Exercise
Construct a circuit that transforms \(\frac{1}{2}\left(|00\rangle + |01\rangle + |10\rangle + |11\rangle\right)\) to \(\frac{1}{2}\left(|00\rangle + |01\rangle - |10\rangle + |11\rangle\right)\).