Skip to content

Commit

Permalink
prepare for publication
Browse files Browse the repository at this point in the history
  • Loading branch information
joksas committed Mar 18, 2022
1 parent d341b53 commit b1c096d
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 112 deletions.
212 changes: 106 additions & 106 deletions awarememristor/plotting/figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def SiO_x():
utils.save_fig(fig, "SiO_x")


def HfO2():
def Ta_HfO2():
fig, axes = utils.fig_init(2, 0.45, fig_shape=(1, 2), sharey=True)

data = simulations.data.load_Ta_HfO2()
Expand Down Expand Up @@ -292,111 +292,7 @@ def HfO2():
handles=handles,
)

utils.save_fig(fig, "HfO2")


def pf_residuals(is_d_times_perm: bool = False):
fig, axes = utils.fig_init(2, 1.0, fig_shape=(4, 2))

axes[0, 1].sharey(axes[0, 0])
plt.setp(axes[0, 1].get_yticklabels(), visible=False)
axes[1, 1].sharey(axes[1, 0])
plt.setp(axes[1, 1].get_yticklabels(), visible=False)

axes[1, 0].sharex(axes[0, 0])
plt.setp(axes[0, 0].get_xticklabels(), visible=False)
axes[1, 1].sharex(axes[0, 1])
plt.setp(axes[0, 1].get_xticklabels(), visible=False)

axes[3, 0].sharex(axes[2, 0])
plt.setp(axes[2, 0].get_xticklabels(), visible=False)
axes[3, 0].set_xlim([-2, 2])
axes[3, 1].sharex(axes[2, 1])
plt.setp(axes[2, 1].get_xticklabels(), visible=False)
axes[3, 1].set_xlim([-2, 2])

exp_data = simulations.data.load_SiO_x_multistate()
V, I = simulations.data.all_SiO_x_curves(exp_data, clean_data=True)
resistances, c, d_times_perm, _, _ = simulations.data.pf_relationship(V, I)
R_0 = const.physical_constants["inverse of conductance quantum"][0]
# Separate data into before and after the conductance quantum.
sep_idx = np.searchsorted(resistances, R_0)

colors = utils.color_dict()

axes[0, 0].set_ylabel(utils.axis_label("ln-c-residuals"))
axes[1, 0].set_ylabel(utils.axis_label("ln-d-times-perm-residuals"))
axes[1, 0].set_xlabel(utils.axis_label("ln-R"))
axes[1, 1].set_xlabel(utils.axis_label("ln-R"))
axes[3, 0].set_xlabel(utils.axis_label("theoretical-normal-quartiles"))
axes[2, 0].set_ylabel(utils.axis_label("ordered-ln-c-residuals"))
axes[3, 1].set_xlabel(utils.axis_label("theoretical-normal-quartiles"))
axes[3, 0].set_ylabel(utils.axis_label("ordered-ln-d-times-perm-residuals"))

for is_high_resistance, ax_idx in zip([False, True], [0, 1]):
_, _, slopes, intercepts, _ = simulations.data.pf_params(
exp_data, is_high_resistance, simulations.data.SiO_x_G_on_G_off_ratio()
)

if is_high_resistance:
idxs = np.arange(sep_idx, len(resistances))
color = colors["reddish-purple"]
else:
idxs = np.arange(sep_idx)
color = colors["blue"]

x = np.log(resistances[idxs])
c_points = np.log(c[idxs])
c_residuals = c_points - slopes[0] * x - intercepts[0]

d_times_perm_points = np.log(d_times_perm[idxs])
d_times_perm_residuals = d_times_perm_points - slopes[1] * x - intercepts[1]

utils.plot_scatter(axes[0, ax_idx], x, c_residuals, color, scale=10)
zero_line = [0] * len(x)
axes[0, ax_idx].plot(
x,
zero_line,
linewidth=utils.Config.LINEWIDTH,
color=color,
linestyle="dashed",
)

utils.plot_scatter(axes[1, ax_idx], x, d_times_perm_residuals, color, scale=10)
axes[1, ax_idx].plot(
x,
zero_line,
linewidth=utils.Config.LINEWIDTH,
color=color,
linestyle="dashed",
)

(osm, osr), (m, b, _) = stats.probplot(c_residuals, dist="norm", plot=None)
utils.plot_scatter(axes[2, ax_idx], osm, osr, color, scale=10)
axes[2, ax_idx].plot(
osm,
m * osm + b,
linewidth=utils.Config.LINEWIDTH,
color=color,
linestyle="dashed",
)

(osm, osr), (m, b, _) = stats.probplot(d_times_perm_residuals, dist="norm", plot=None)
utils.plot_scatter(axes[3, ax_idx], osm, osr, color, scale=10)
axes[3, ax_idx].plot(
osm,
m * osm + b,
linewidth=utils.Config.LINEWIDTH,
color=color,
linestyle="dashed",
)

for ax in [axes[0, 0], axes[1, 0]]:
low, high = ax.get_ylim()
bound = max(abs(low), abs(high))
ax.set_ylim(-bound, bound)

utils.save_fig(fig, "pf-residuals")
utils.save_fig(fig, "Ta-HfO2")


def iv_nonlinearity_training(metric="error"):
Expand Down Expand Up @@ -685,3 +581,107 @@ def nonideality_agnosticism(metric: str = "error", norm_rows=True, include_val_l
)

utils.save_fig(fig, filename, metric=metric)


def pf_residuals(is_d_times_perm: bool = False):
fig, axes = utils.fig_init(2, 1.0, fig_shape=(4, 2))

axes[0, 1].sharey(axes[0, 0])
plt.setp(axes[0, 1].get_yticklabels(), visible=False)
axes[1, 1].sharey(axes[1, 0])
plt.setp(axes[1, 1].get_yticklabels(), visible=False)

axes[1, 0].sharex(axes[0, 0])
plt.setp(axes[0, 0].get_xticklabels(), visible=False)
axes[1, 1].sharex(axes[0, 1])
plt.setp(axes[0, 1].get_xticklabels(), visible=False)

axes[3, 0].sharex(axes[2, 0])
plt.setp(axes[2, 0].get_xticklabels(), visible=False)
axes[3, 0].set_xlim([-2, 2])
axes[3, 1].sharex(axes[2, 1])
plt.setp(axes[2, 1].get_xticklabels(), visible=False)
axes[3, 1].set_xlim([-2, 2])

exp_data = simulations.data.load_SiO_x_multistate()
V, I = simulations.data.all_SiO_x_curves(exp_data, clean_data=True)
resistances, c, d_times_perm, _, _ = simulations.data.pf_relationship(V, I)
R_0 = const.physical_constants["inverse of conductance quantum"][0]
# Separate data into before and after the conductance quantum.
sep_idx = np.searchsorted(resistances, R_0)

colors = utils.color_dict()

axes[0, 0].set_ylabel(utils.axis_label("ln-c-residuals"))
axes[1, 0].set_ylabel(utils.axis_label("ln-d-times-perm-residuals"))
axes[1, 0].set_xlabel(utils.axis_label("ln-R"))
axes[1, 1].set_xlabel(utils.axis_label("ln-R"))
axes[3, 0].set_xlabel(utils.axis_label("theoretical-normal-quartiles"))
axes[2, 0].set_ylabel(utils.axis_label("ordered-ln-c-residuals"))
axes[3, 1].set_xlabel(utils.axis_label("theoretical-normal-quartiles"))
axes[3, 0].set_ylabel(utils.axis_label("ordered-ln-d-times-perm-residuals"))

for is_high_resistance, ax_idx in zip([False, True], [0, 1]):
_, _, slopes, intercepts, _ = simulations.data.pf_params(
exp_data, is_high_resistance, simulations.data.SiO_x_G_on_G_off_ratio()
)

if is_high_resistance:
idxs = np.arange(sep_idx, len(resistances))
color = colors["reddish-purple"]
else:
idxs = np.arange(sep_idx)
color = colors["blue"]

x = np.log(resistances[idxs])
c_points = np.log(c[idxs])
c_residuals = c_points - slopes[0] * x - intercepts[0]

d_times_perm_points = np.log(d_times_perm[idxs])
d_times_perm_residuals = d_times_perm_points - slopes[1] * x - intercepts[1]

utils.plot_scatter(axes[0, ax_idx], x, c_residuals, color, scale=10)
zero_line = [0] * len(x)
axes[0, ax_idx].plot(
x,
zero_line,
linewidth=utils.Config.LINEWIDTH,
color=color,
linestyle="dashed",
)

utils.plot_scatter(axes[1, ax_idx], x, d_times_perm_residuals, color, scale=10)
axes[1, ax_idx].plot(
x,
zero_line,
linewidth=utils.Config.LINEWIDTH,
color=color,
linestyle="dashed",
)

(osm, osr), (m, b, _) = stats.probplot(c_residuals, dist="norm", plot=None)
utils.plot_scatter(axes[2, ax_idx], osm, osr, color, scale=10)
axes[2, ax_idx].plot(
osm,
m * osm + b,
linewidth=utils.Config.LINEWIDTH,
color=color,
linestyle="dashed",
)

(osm, osr), (m, b, _) = stats.probplot(d_times_perm_residuals, dist="norm", plot=None)
utils.plot_scatter(axes[3, ax_idx], osm, osr, color, scale=10)
axes[3, ax_idx].plot(
osm,
m * osm + b,
linewidth=utils.Config.LINEWIDTH,
color=color,
linestyle="dashed",
)

for ax in [axes[0, 0], axes[1, 0]]:
low, high = ax.get_ylim()
bound = max(abs(low), abs(high))
ax.set_ylim(-bound, bound)

utils.save_fig(fig, "pf-residuals")
4 changes: 2 additions & 2 deletions awarememristor/simulations/ideal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from awarememristor.simulations import (iv_nonlinearity,
from awarememristor.simulations import (high_d2d, iv_nonlinearity,
iv_nonlinearity_and_stuck_on,
iv_nonlinearity_cnn,
stuck_distribution, stuck_off,
Expand All @@ -13,7 +13,7 @@ def get_mnist_iterator():
iv_nonlinearity_and_stuck_on.get_ideal_iterator(),
stuck_distribution.get_ideal_iterator(),
weight_implementation.get_ideal_iterator(),
memristive_validation.get_ideal_iterator(),
high_d2d.get_ideal_iterator(),
]

return Iterator(
Expand Down
10 changes: 6 additions & 4 deletions reproduce_paper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,30 @@
simulations.iv_nonlinearity.main()
simulations.iv_nonlinearity_and_stuck_on.main()
simulations.iv_nonlinearity_cnn.main()
simulations.memristive_validation.main()
simulations.stuck_distribution.main()
simulations.stuck_off.main()
simulations.high_d2d.main()
simulations.weight_implementation.main()
simulations.nonideality_agnosticism.main()

# Figures in the main text
figures.experimental_data()
figures.SiO_x()
figures.Ta_HfO2()
figures.iv_nonlinearity_training()
figures.iv_nonlinearity_inference()
figures.iv_nonlinearity_cnn()
figures.weight_implementation()
figures.memristive_validation()
figures.nonideality_agnosticism()
figures.pf_residuals()

# Figures in the Supporting Information
supporting_figures.all_iv_curves_full_range()
supporting_figures.switching()
supporting_figures.iv_nonlinearity_training()
supporting_figures.weight_implementation_standard_weights_training()
supporting_figures.weight_implementation_double_weights_training()
supporting_figures.memristive_validation_training()
supporting_figures.high_d2d_training()
supporting_figures.stuck_off_training()
supporting_figures.high_iv_nonlinearity_and_stuck_on_training()
supporting_figures.stuck_distribution_training()
supporting_figures.pf_plots()

0 comments on commit b1c096d

Please sign in to comment.