Measurement & mixed states for quantum systems.
Notes on measurement for quantum systems.
Notes on quantum states as a generalization of classical probabilities.
Assume (1 / sqrt(2)) is factored out (not considered in the below examples).
ket_0 means 0 ket or |0>
& ket_1 means 1 ket or |1>
.
ket_0 = np.array([[1],
[0]])
ket_1 = np.array([[0],
[1]])
hadamard = np.array([[1, 1],
[1, -1]])
print("ket_0 + ket_1 =", ket_0 + ket_1)
print("hadamard @ ket_0 =", hadamard @ ket_0)
print("ket_0 - ket_1 =", ket_0 - ket_1)
print("hadamard @ ket_1 =", hadamard @ ket_1)
ket_0 + ket_1 = [[1]
[1]]
hadamard @ ket_0 = [[1]
[1]]
ket_0 - ket_1 = [[ 1]
[-1]]
hadamard @ ket_1 = [[ 1]
[-1]]
ket_00 = np.kron(ket_0, ket_0)
ket_01 = np.kron(ket_0, ket_1)
ket_10 = np.kron(ket_1, ket_0)
ket_11 = np.kron(ket_1, ket_1)
print("|00⟩ : ", ket_00)
print("|01⟩ : ", ket_01)
print("|10⟩ : ", ket_10)
print("|11⟩ : ", ket_11)
print("|00⟩ + |11⟩ =", ket_00 + ket_11)
print("|00⟩ - |11⟩ =", ket_00 - ket_11)
|00⟩ : [[1]
[0]
[0]
[0]]
|01⟩ : [[0]
[1]
[0]
[0]]
|10⟩ : [[0]
[0]
[1]
[0]]
|11⟩ : [[0]
[0]
[0]
[1]]
|00⟩ + |11⟩ = [[1]
[0]
[0]
[1]]
|00⟩ - |11⟩ = [[ 1]
[ 0]
[ 0]
[-1]]
# Hadamard gate
hadamard = np.array([[1, 1],
[1, -1]])
# CNOT gate
CNOT_mat = np.array([[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 0]])
# Initialize 2 qubits, q_0, q_1 as |0>.
q_0 = np.array([[1],
[0]])
q_1 = np.array([[1],
[0]])
# Apply hadamard to q_0.
H_q_0 = hadamard @ q_0
print("H_q_0: {}".format(H_q_0))
# Composite state of q_0 (after applying hadamard to q_0) & q_1.
composite = np.kron(H_q_0, q_1)
print("composite: {}".format(composite))
# Apply CNOT to composite state.
res = CNOT_mat @ composite
print("res: {}".format(res))
H_q_0: [[1]
[1]]
composite: [[1]
[0]
[1]
[0]]
res: [[1]
[0]
[0]
[1]]
# NOT gate
def Not_gate(v):
if v[0] == 0:
v[0] = 1
else:
v[0] = 0
if v[1] == 0:
v[1] = 1
else:
v[1] = 0
return v
# Hadamard gate
hadamard = np.array([[1, 1],
[1, -1]])
# CNOT gate
CNOT_mat = np.array([[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 0]])
# Initialize 2 qubits, q_0, q_1 as |0>.
q_0 = np.array([[1],
[0]])
q_1 = np.array([[1],
[0]])
# Apply NOT to q_1.
X_q_1 = Not_gate(q_1)
print("X_q_1: {}".format(X_q_1))
# Apply hadamard to q_1.
H_q_1 = hadamard @ X_q_1
print("H_q_1: {}".format(H_q_1))
# Composite state of q_1 (after applying hadamard to q_1) & q_0.
composite = np.kron(H_q_1, q_0) # Need to CNOT(1,0) instead of CNOT(0,1) so q_1 is 1st term in composite.
print("composite: {}".format(composite))
# Apply CNOT to composite state.
res = CNOT_mat @ composite
print("res: {}".format(res))
X_q_1: [[0]
[1]]
H_q_1: [[ 1]
[-1]]
composite: [[ 1]
[ 0]
[-1]
[ 0]]
res: [[ 1]
[ 0]
[ 0]
[-1]]
Notes on measurement for quantum systems.
Notes on quantum states as a generalization of classical probabilities.
The location of ray_results folder in colab when using RLlib &/or tune.
My attempt to implement a water down version of PBT (Population based training) for MARL (Multi-agent reinforcement learning).
Ray (0.8.2) RLlib trainer common config from:
How to calculate dimension of output from a convolution layer?
Changing Google drive directory in Colab.
Notes on the probability for linear regression (Bayesian)
Notes on the math for RNN back propagation through time(BPTT), part 2. The 1st derivative of \(h_t\) with respect to \(h_{t-1}\).
Notes on the math for RNN back propagation through time(BPTT).
Filter rows with same column values in a Pandas dataframe.
Building & testing custom Sagemaker RL container.
Demo setup for simple (reinforcement learning) custom environment in Sagemaker. This example uses Proximal Policy Optimization with Ray (RLlib).
Basic workflow of testing a Django & Postgres web app with Travis (continuous integration) & deployment to Heroku (continuous deployment).
Basic workflow of testing a dockerized Django & Postgres web app with Travis (continuous integration) & deployment to Heroku (continuous deployment).
Introducing a delay to allow proper connection between dockerized Postgres & Django web app in Travis CI.
Creating & seeding a random policy class in RLlib.
A custom MARL (multi-agent reinforcement learning) environment where multiple agents trade against one another in a CDA (continuous double auction).
This post demonstrate how setup & access Tensorflow graphs.
This post demonstrates how to create customized functions to bundle commands in a .bash_profile file on Mac.
This post documents my implementation of the Random Network Distillation (RND) with Proximal Policy Optimization (PPO) algorithm. (continuous version)
This post documents my implementation of the Distributed Proximal Policy Optimization (Distributed PPO or DPPO) algorithm. (Distributed continuous version)
This post documents my implementation of the A3C (Asynchronous Advantage Actor Critic) algorithm (Distributed discrete version).
This post documents my implementation of the A3C (Asynchronous Advantage Actor Critic) algorithm. (multi-threaded continuous version)
This post documents my implementation of the A3C (Asynchronous Advantage Actor Critic) algorithm (discrete). (multi-threaded discrete version)
This post demonstrates how to accumulate gradients with Tensorflow.
This post demonstrates a simple usage example of distributed Tensorflow with Python multiprocessing package.
This post documents my implementation of the N-step Q-values estimation algorithm.
This post demonstrates how to use the Python’s multiprocessing package to achieve parallel data generation.
This post provides a simple usage examples for common Numpy array manipulation.
This post documents my implementation of the Dueling Double Deep Q Network with Priority Experience Replay (Duel DDQN with PER) algorithm.
This post documents my implementation of the Dueling Double Deep Q Network (Dueling DDQN) algorithm.
This post documents my implementation of the Double Deep Q Network (DDQN) algorithm.
This post documents my implementation of the Deep Q Network (DQN) algorithm.