Commit fbfa9af3 authored by Tobias Jörg Theodor Kempe's avatar Tobias Jörg Theodor Kempe
Browse files

adds comments to optimized version

parent e969d6e7
Pipeline #466581 passed with stage
in 51 seconds
......@@ -28,23 +28,28 @@ def simulate(phi1, phi2):
# zip measurement outcome together
x1x2 = np.concatenate((x1, x2), axis=1)
# creates array to store counts in
# 1st index ~ without time constraints (0) or with coincidence constraint (1)
# 2nd index ~ the respective outcome [0, 0] (0), [0, 1] (1), [1, 0] (2), or [1, 1] (3)
counts = np.empty((2, 4), dtype=np.int32)
# calculates counts without time constraints
counts[0, 0] = np.sum(np.all(x1x2 == np.array([0, 0]), axis=1), axis=0)
counts[0, 1] = np.sum(np.all(x1x2 == np.array([0, 1]), axis=1), axis=0)
counts[0, 2] = np.sum(np.all(x1x2 == np.array([1, 0]), axis=1), axis=0)
counts[0, 3] = np.sum(np.all(x1x2 == np.array([1, 1]), axis=1), axis=0)
# calculates counts with coincidence constraint
counts[1, 0] = np.sum(np.logical_and(np.all(x1x2 == np.array([0, 0]), axis=1), coincidences), axis=0)
counts[1, 1] = np.sum(np.logical_and(np.all(x1x2 == np.array([0, 1]), axis=1), coincidences), axis=0)
counts[1, 2] = np.sum(np.logical_and(np.all(x1x2 == np.array([1, 0]), axis=1), coincidences), axis=0)
counts[1, 3] = np.sum(np.logical_and(np.all(x1x2 == np.array([1, 1]), axis=1), coincidences), axis=0)
# computes expectancy values for x1*x2, x1 and x2
E_all = np.sum(counts, axis=1).astype(float)
E_12 = (counts[:, 0] - counts[:, 1] - counts[:, 2] + counts[:, 3]).astype(float)
E_1 = (counts[:, 0] + counts[:, 1] - counts[:, 2] - counts[:, 3]).astype(float)
E_2 = (counts[:, 0] - counts[:, 1] + counts[:, 2] - counts[:, 3]).astype(float)
if (np.all(E_all > 0)):
E_12 /= E_all
E_1 /= E_all
......@@ -55,10 +60,12 @@ def simulate(phi1, phi2):
def try_all_configs(n_configs):
# allocates storage for each required expectancy value
E_12 = np.empty((n_configs, 2), dtype=np.float32)
E_1 = np.empty((n_configs, 2), dtype=np.float32)
E_2 = np.empty((n_configs, 2), dtype=np.float32)
# simulates all configurations
for i in range(n_configs):
phi1 = 0
phi2 = i * 2 * np.pi / n_configs
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment