1
$\begingroup$

I need some help in multi-qubit controlled -Z rotation. Below is the qiskit code of triple controlled z rotation

def cccZ():                                      
qc = QuantumCircuit(4)
qc.cp(pi/4, 0, 3)            

qc.cx(0, 1)
qc.cp(-pi/4, 1, 3)

qc.cx(0, 1)
qc.cp(pi/4, 1, 3)

qc.cx(1, 2)
qc.cp(-pi/4, 2, 3)

qc.cx(0, 2)
qc.cp(pi/4, 2, 3)

qc.cx(1, 2)
qc.cp(-pi/4, 2, 3)

qc.cx(0, 2)
qc.cp(pi/4, 2, 3)


gate = qc.to_gate(label=' cccZ')
return gate

Please help me in modifying this code to hexa qubit z rotation? It would be really great if someone can explain its theory also. I am really struggling with random nature of quantum computing with no fixed pattern at all.

$\endgroup$

1 Answer 1

2
$\begingroup$

The mostly flexible way to create gates beyond the ones included as methods is with the circuit library:

from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

circuit = QuantumCircuit(7)
c6z = ZGate().control(6)
circuit.append(c6z, range(7))
circuit.draw()
q_0: ─■─
      │ 
q_1: ─■─
      │ 
q_2: ─■─
      │ 
q_3: ─■─
      │ 
q_4: ─■─
      │ 
q_5: ─■─
      │ 
q_6: ─■─

The decomposition of this gate is deep:

circuit.decompose().depth()
315

How to construct multi-controlled gates, in general

Any single-qubit gate can be arbitrarily-n-controlled with the method Gate.control. The parameter n sets the amount of controlled qubits. As a consequence, the resulting controlled-gate will be a n-plus-one-qubits gate.

from qiskit.circuit.library import <some>Gate
cN_gate = <some>Gate(<gate_params>).control(<n>)
print(cN_gate.num_qubits)  # n+1

You can append this custom gate to a circuit using the QuantumCircuit.append method:

circuit.append(cN_gate, [....., i])
                         \_n_/

The first $n$ parameters are the qubits in which you want to control. The last one (i) is the target qubit.

$\endgroup$
3
  • $\begingroup$ Thank you @Luciano. Please provide some methodology or trick to understand these quantum gates and circuit? $\endgroup$
    – Manu
    Aug 19, 2021 at 6:20
  • $\begingroup$ I generalized it, have a look $\endgroup$
    – luciano
    Aug 19, 2021 at 8:00
  • $\begingroup$ Thank you @Luciano $\endgroup$
    – Manu
    Aug 19, 2021 at 14:56

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.