Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- operation BellTest () : ()
- {
- body
- {
- // Use two qubits
- using (qubits = Qubit[2])
- {
- Set (One, qubits[0]);
- Set (Zero, qubits[1]);
- // Apply Hadamard gate to the first qubit
- H(qubits[0]);
- // Apply CNOT gate
- CNOT(qubits[0],qubits[1]);
- }
- }
- }
- # import and initialize the method used to store quantum programs
- from qiskit import QuantumProgram
- qp = QuantumProgram()
- # initialize a quantum register of two qubits
- qr = qp.create_quantum_register('qr',2)
- # and a classical register of two bits
- cr = qp.create_classical_register('cr',2)
- # create a circuit with them which we call 'Bell'
- qc = qp.create_circuit('Bell',[qr],[cr])
- # apply a Hadamard to the first qubit
- qc.h(qr[0])
- # apply a controlled not with the first qubit as control
- qc.cx(qr[0], qr[1])
- # measure the first qubit and store its result on the first bit
- qc.measure(qr[0], cr[0])
- # the same for the second qubit and bit
- qc.measure(qr[1], cr[1])
- # run the circuit
- result = qp.execute('Bell')
- # extract the results
- print(result.get_counts('Bell'))
- results = qp.execute(['Bell'], backend='ibmqx4', shots=1024)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement