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
| # 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
| 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
| # 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
| 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
| 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
| 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
| # The main RL event loop | |
| for i in range(num_episodes): | |
| S0 = env.reset() # Current state | |
| total_reward_for_episode = 0 | |
| game_done = False | |
| for s in range(steps_per_episode): | |
| # Choosing an action to perform in the current state | |
| if np.random.rand() > epsilon: | |
| action = env.action_space.sample() # Explore with a random action |
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
| rewards_lookup = { | |
| 'empty': -1, | |
| 'cheese': 5, | |
| 'mousetrap': -10, | |
| 'start': 0, | |
| 'end': 0 | |
| } |
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
| discount_factor_gamma = 0.9 | |
| num_episodes = 1000 | |
| learning_rate_alpha = 0.8 | |
| epsilon_threshold = 1.0 |