1
$\begingroup$

I want to understand this Qiskit function (a function for creating the gate CNX with Python): more specifically i don't understand what's the rotations (Y and Z) over the qubits for ? I added inline questions in the code below :

def cnx(qc, *qubits):
 if len(qubits) >= 3:
  last = qubits[-1]
  #What's the goal of the next two lines ?
  qc.crz(np.pi/2, qubits[-2], qubits[-1])
  qc.cry(np.pi/2, 0, 0, qubits[-2],qubits[-1])

  #Is this a recursive call to cnx ?
  cnx(qc,*qubits[:-2],qubits[-1])

  #what's this flip yielding ?
  qc.cry(-np.pi/2, 0, 0, qubits[-2], qubits[-1])

  #what about this line ?
  cnx(qc,*qubits[:-2],qubits[-1])

  #what about this line too?
  qc.crz(-np.pi/2,qubits[-2],qubits[-1])

Thanks !

$\endgroup$
3
  • 1
    $\begingroup$ Hi! Could you tell us where you found this function? I searched for "cnx" in qiskit-terra, without any result. I also searched "cnx" in qiskit-aqua and the only results are commits showing that the cnx function has been removed the 9th of May. $\endgroup$ Jul 5 '19 at 20:33
  • $\begingroup$ Sory i don't recall from where i found it $\endgroup$ Jul 5 '19 at 20:40
  • $\begingroup$ I think this is the method from here which is based on Lemma 7.9 in the paper here. $\endgroup$
    – met927
    Jul 9 '19 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.