Skip to content

Commit

Permalink
First scatter plot + python interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
FalafelGood committed Mar 22, 2021
1 parent 4842329 commit f78bbb0
Show file tree
Hide file tree
Showing 16 changed files with 9,048 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/QuNet.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions QuNet-Paper/.idea/QuNet-Paper.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions QuNet-Paper/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions QuNet-Paper/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions QuNet-Paper/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions QuNet-Paper/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions QuNet-Paper/heatmap.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using QuNet
using DataFrames
using CSV

grid_size = 10
num_trials = 100
num_trials = 1000
num_pairs = 50

net = GridNetwork(grid_size, grid_size)
Expand All @@ -10,4 +12,10 @@ net = GridNetwork(grid_size, grid_size)
# num_trials::Int64, num_pairs::Int64; max_paths=3, src_layer::Int64=-1,
# dst_layer::Int64=-1, edge_perc_rate=0.0)
coord_list = QuNet.heat_data(net, num_trials, num_pairs, max_paths=4)
println(coord_list)

# List comprehension
e = [coord_list[i][1] for i in 1:length(coord_list)]
f = [coord_list[i][2] for i in 1:length(coord_list)]
# # Convert cood_list to data_frame and write to csv
df = DataFrame(Efficiency = e, Fidelity = f)
CSV.write("data/heatmap.csv", df)
93 changes: 55 additions & 38 deletions QuNet-Paper/heatmap.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,64 @@
# https://www.python-graph-gallery.com/86-avoid-overlapping-in-scatterplot-with-2d-density

# Libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import kde

# Create data: 200 points
data = np.random.multivariate_normal([0, 0], [[1, 0.5], [0.5, 3]], 200)
x, y = data.T

# Create a figure with 6 plot areas
fig, axes = plt.subplots(ncols=6, nrows=1, figsize=(21, 5))

# Everything starts with a Scatterplot
axes[0].set_title('Scatterplot')
axes[0].plot(x, y, 'ko')
# As you can see there is a lot of overlapping here!

# Thus we can cut the plotting window in several hexbins
nbins = 20
axes[1].set_title('Hexbin')
axes[1].hexbin(x, y, gridsize=nbins, cmap=plt.cm.BuGn_r)
df = pd.read_csv("/home/hudson/.julia/dev/QuNet/data/heatmap.csv")
print(df)

# 2D Histogram
axes[2].set_title('2D Histogram')
axes[2].hist2d(x, y, bins=nbins, cmap=plt.cm.BuGn_r)
# Extract data into x, y
print(df["Efficiency"])
e = df["Efficiency"].tolist()
f = df["Fidelity"].tolist()

# Evaluate a gaussian kde on a regular grid of nbins x nbins over data extents
k = kde.gaussian_kde(data.T)
xi, yi = np.mgrid[x.min():x.max():nbins * 1j, y.min():y.max():nbins * 1j]
zi = k(np.vstack([xi.flatten(), yi.flatten()]))

# plot a density
axes[3].set_title('Calculate Gaussian KDE')
axes[3].pcolormesh(xi, yi, zi.reshape(xi.shape), shading='auto', cmap=plt.cm.BuGn_r)

# add shading
axes[4].set_title('2D Density with shading')
axes[4].pcolormesh(xi, yi, zi.reshape(xi.shape), shading='gouraud', cmap=plt.cm.BuGn_r)

# contour
axes[5].set_title('Contour')
axes[5].pcolormesh(xi, yi, zi.reshape(xi.shape), shading='gouraud', cmap=plt.cm.BuGn_r)
axes[5].contour(xi, yi, zi.reshape(xi.shape))
# Create a scatter plot
fig, axes = plt.subplots()
axes.set_title("Scatterplot")
axes.plot(e, f, 'ko')
axes.set_xlabel("Efficiency")
axes.set_ylabel("Fidelity")
plt.show()


# # Sample Code to test plot functionality:
# # https://www.python-graph-gallery.com/86-avoid-overlapping-in-scatterplot-with-2d-density
# # Create data: 200 points
# data = np.random.multivariate_normal([0, 0], [[1, 0.5], [0.5, 3]], 200)
# x, y = data.T
#
# # Create a figure with 6 plot areas
# fig, axes = plt.subplots(ncols=6, nrows=1, figsize=(21, 5))
#
# # Everything starts with a Scatterplot
# axes[0].set_title('Scatterplot')
# axes[0].plot(x, y, 'ko')
# # As you can see there is a lot of overlapping here!
#
# # Thus we can cut the plotting window in several hexbins
# nbins = 20
# axes[1].set_title('Hexbin')
# axes[1].hexbin(x, y, gridsize=nbins, cmap=plt.cm.BuGn_r)
#
# # 2D Histogram
# axes[2].set_title('2D Histogram')
# axes[2].hist2d(x, y, bins=nbins, cmap=plt.cm.BuGn_r)
#
# # Evaluate a gaussian kde on a regular grid of nbins x nbins over data extents
# k = kde.gaussian_kde(data.T)
# xi, yi = np.mgrid[x.min():x.max():nbins * 1j, y.min():y.max():nbins * 1j]
# zi = k(np.vstack([xi.flatten(), yi.flatten()]))
#
# # plot a density
# axes[3].set_title('Calculate Gaussian KDE')
# axes[3].pcolormesh(xi, yi, zi.reshape(xi.shape), shading='auto', cmap=plt.cm.BuGn_r)
#
# # add shading
# axes[4].set_title('2D Density with shading')
# axes[4].pcolormesh(xi, yi, zi.reshape(xi.shape), shading='gouraud', cmap=plt.cm.BuGn_r)
#
# # contour
# axes[5].set_title('Contour')
# axes[5].pcolormesh(xi, yi, zi.reshape(xi.shape), shading='gouraud', cmap=plt.cm.BuGn_r)
# axes[5].contour(xi, yi, zi.reshape(xi.shape))
# plt.show()
Loading

0 comments on commit f78bbb0

Please sign in to comment.