Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. operation BellTest () : ()
  2. {
  3. body
  4. {
  5. // Use two qubits
  6. using (qubits = Qubit[2])
  7. {
  8. Set (One, qubits[0]);
  9. Set (Zero, qubits[1]);
  10.  
  11. // Apply Hadamard gate to the first qubit
  12. H(qubits[0]);
  13.  
  14. // Apply CNOT gate
  15. CNOT(qubits[0],qubits[1]);
  16. }
  17. }
  18. }
  19.  
  20. # import and initialize the method used to store quantum programs
  21. from qiskit import QuantumProgram
  22. qp = QuantumProgram()
  23. # initialize a quantum register of two qubits
  24. qr = qp.create_quantum_register('qr',2)
  25. # and a classical register of two bits
  26. cr = qp.create_classical_register('cr',2)
  27. # create a circuit with them which we call 'Bell'
  28. qc = qp.create_circuit('Bell',[qr],[cr])
  29. # apply a Hadamard to the first qubit
  30. qc.h(qr[0])
  31. # apply a controlled not with the first qubit as control
  32. qc.cx(qr[0], qr[1])
  33. # measure the first qubit and store its result on the first bit
  34. qc.measure(qr[0], cr[0])
  35. # the same for the second qubit and bit
  36. qc.measure(qr[1], cr[1])
  37. # run the circuit
  38. result = qp.execute('Bell')
  39. # extract the results
  40. print(result.get_counts('Bell'))
  41.  
  42. results = qp.execute(['Bell'], backend='ibmqx4', shots=1024)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement