This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import qiskit as qk | |
| # defining our Qubits and Bits | |
| q = qk.QuantumRegister(2) | |
| c = qk.ClassicalRegister(2) | |
| # Creating a circuit with our Qubits and Bits | |
| circuit = qk.QuantumCircuit(q, c) | |
| # Adding Gates |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import qiskit as qk | |
| # Creating Qubits | |
| q = qk.QuantumRegister(2) | |
| # Creating Classical Bits | |
| c = qk.ClassicalRegister(2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| circuit = qk.QuantumCircuit(q, c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Hadamard Gate on the first Qubit | |
| circuit.h(q[0]) | |
| # CNOT Gate on the first and second Qubits | |
| circuit.cx(q[0], q[1]) | |
| # Measuring the Qubits | |
| circuit.measure(q, c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print (circuit) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Using Qiskit Aer's Qasm Simulator | |
| simulator = qk.BasicAer.get_backend('qasm_simulator') | |
| # Simulating the circuit using the simulator to get the result | |
| job = qk.execute(circuit, simulator) | |
| result = job.result() | |
| # Getting the aggregated binary outcomes of the circuit. | |
| counts = result.get_counts(circuit) | |
| print (counts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import qiskit import qk | |
| ''' | |
| When you run the script once, you do not need to add | |
| your API key again as your account has already been | |
| saved in memory | |
| ''' | |
| qk.IBMQ.save_account('YOUR_API_KEY') | |
| qk.IBMQ.load_accounts() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Applying a Hadamard Gate on the n Qubits | |
| to get a final bitstring of size n | |
| The bitstring will be converted to a | |
| decimal number (integer) between 0 and 2^3 - 1 (7) | |
| ''' | |
| for i in range(n): | |
| circ.h(q[i]) | |
| circ.measure(q,c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| `n` is the number of Qubits needed to | |
| generate a a random number between | |
| 0 and 2^n - 1 | |
| ''' | |
| n = 3 | |
| ''' | |
| Creating a Quantum Register with `n` Qubits and | |
| `n` Classical Bits where n=3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The backend simulator available to me | |
| backend = qk.IBMQ.get_backend('ibmqx4') |