Skip to content

Instantly share code, notes, and snippets.

View rish-16's full-sized avatar
🤖
backpropagating through memories

Rishabh Anand rish-16

🤖
backpropagating through memories
View GitHub Profile
@rish-16
rish-16 / connect.py
Created May 13, 2019 06:59
Connecting to the IBM Q 4 Qubit Machine
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()
# 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)
@rish-16
rish-16 / visualize.py
Created May 11, 2019 16:48
Visualizing the Quantum Circuit
print (circuit)
@rish-16
rish-16 / gates.py
Created May 11, 2019 16:46
Adding gates into our Quantum Circuit
# 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)
@rish-16
rish-16 / circuit.py
Created May 11, 2019 16:44
Building a Quantum Circuit with our Qubits and Classical Bits.
circuit = qk.QuantumCircuit(q, c)
@rish-16
rish-16 / instantiation.py
Created May 11, 2019 16:42
Creating Qubits and Classical Bits in Qiskit
import qiskit as qk
# Creating Qubits
q = qk.QuantumRegister(2)
# Creating Classical Bits
c = qk.ClassicalRegister(2)
@rish-16
rish-16 / simulation.py
Created May 11, 2019 15:34
Quantum circuit with Qiskit
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
# 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
rewards_lookup = {
'empty': -1,
'cheese': 5,
'mousetrap': -10,
'start': 0,
'end': 0
}
discount_factor_gamma = 0.9
num_episodes = 1000
learning_rate_alpha = 0.8
epsilon_threshold = 1.0