Skip to content

Commit

Permalink
improving gui
Browse files Browse the repository at this point in the history
  • Loading branch information
b-vanstraaten committed Jul 24, 2024
1 parent 8d4d2c1 commit 0b2f94b
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 25 deletions.
3 changes: 1 addition & 2 deletions examples/figure_4b.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
implementation='rust',
charge_carrier='electron',
T=150,
threshold=0.1
threshold=0.05
)
model.max_charge_carriers = 2

voltage_composer = GateVoltageComposer(n_gate=model.n_gate, n_dot=model.n_dot)

Expand Down
32 changes: 13 additions & 19 deletions examples/gui.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
from qarray import DotArray
#
# Cdd = [
# [0, 0.1],
# [0.1, 0]
# ]
#
# Cgd = [
# [1., 0.1],
# [0.1, 1]
# ]

Cdd = [
[0., 0.2, 0.2, 0.5],
[0.2, 0., 0.05, 0.2],
[0.2, 0.05, 0.2, 0.],
[0.5, 0.2, 0., 0]
[0., 0.2, 0.05, 0.01],
[0.2, 0., 0.2, 0.05],
[0.05, 0.2, 0.0, 0.2],
[0.01, 0.05, 0.2, 0]
]

Cgd = [
[1., 0, 0, 0, 0],
[0, 1., 0, 0.0, 0],
[0, 0, 1., 0, 0],
[0, 0, 0, 1, 1]
[1., 0, 0, 0],
[0, 1., 0, 0.0],
[0, 0, 1., 0],
[0, 0, 0, 1]
]


Expand All @@ -34,4 +24,8 @@
implementation='rust', charge_carrier='h', T=0., threshold=1.,
max_charge_carriers=4,
)
model.run_gui()

# with the optimal gate voltage formula we can center the scans on any charge state we wish.
# try the argument [0.0, 0.5, 0.5, 0.0] to center the scan on the (0, 1, 0, 0) -> (0, 0, 1, 0) charge transition
initial_dac_values = model.optimal_Vg([0.0, 0.0, 0.0, 0.0])
model.run_gui(initial_dac_values=initial_dac_values)
95 changes: 95 additions & 0 deletions examples/threshold_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from time import perf_counter_ns

import matplotlib.pyplot as plt
import numpy as np

from qarray import DotArray, GateVoltageComposer, dot_occupation_changes

cdd = [
[1., -0., -0.004, -0.0],
[-0., 1, -0.04, -0.01],
[-0.004, -0.04, 1, -0.],
[-0.0, -0.01, -0., 1.]
]
cgd = np.array([
[0.5, 0.2, 0.02, 0.03],
[0.4, 1., 0.4, 0.1],
[0.05, 0.4, 1., 0.4],
[0.04, 0.1, 0.4, 1.1]
])

model = DotArray(
cdd=cdd,
cgd=cgd,
algorithm='thresholded',
implementation='rust',
charge_carrier='electron',
T=0,
threshold=1.
)

voltage_composer = GateVoltageComposer(n_gate=model.n_gate, n_dot=model.n_dot)

vx_min, vx_max = -1.4, 0.6
vy_min, vy_max = -1, 1
# using the dot voltage composer to create the dot voltage array for the 2d sweep
vg = voltage_composer.do2d(1, vy_min, vx_max, 200, 4, vy_min, vy_max, 200)
vg += model.optimal_Vg(np.array([0.7, 0.57, 0.52, 1]))

ground_truth = model.ground_state_open(vg)

csd = []
times = []

n_average = 2

thresholds = np.linspace(0, 0.2, 100)

for threshold in thresholds:
model.threshold = threshold

for _ in range(n_average):
t0 = perf_counter_ns()
result = model.ground_state_open(vg)
t1 = perf_counter_ns()
times.append(t1 - t0)

csd.append(result)

csd = np.array(csd)
times = np.array(times).reshape(-1, n_average)
diff = csd != ground_truth

diff = np.any(diff, axis=-1)
average_diff = np.mean(diff, axis=(1, 2))

plt.figure()

plt.scatter(thresholds, 100 * average_diff)
plt.xlabel('Threshold')
plt.ylabel('Error (%)')
plt.axvline(model.compute_threshold_estimate(), color='red', linestyle='--')
# adding second y-axis
plt.twinx()

# plot this error as a shaded region
plt.errorbar(thresholds, times.mean(axis=-1) / 1e6, 2 * times.std(axis=-1) / 1e6, color='red')

plt.ylabel('Time (ms)')

# making a gif out of the csds
import imageio
import os

os.makedirs('csd', exist_ok=True)

for i, csd in enumerate(csd):
plt.figure()
plt.title(f'Threshold: {thresholds[i]:.3f}')
plt.imshow(dot_occupation_changes(csd).T, origin='lower', aspect='equal', extent=[vx_min, vx_max, vy_min, vy_max],
cmap='Greys', interpolation='none')
plt.savefig(f'csd/{i}.png')
plt.close()

images = [imageio.imread(f'csd/{i}.png') for i in range(len(thresholds))]
imageio.mimsave('csd.gif', images)
9 changes: 7 additions & 2 deletions qarray/DotArrays/DotArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,15 @@ def compute_optimal_virtual_gate_matrix(self):
self.gate_voltage_composer.virtual_gate_matrix = virtual_gate_matrix
return virtual_gate_matrix

def run_gui(self, port=27182, print_compute_time: bool = False):
def run_gui(self, port=27182, print_compute_time: bool = False, initial_dac_values=None):
"""
Creates a GUI for the dot array
:param port: the port to run the GUI on
:param print_compute_time: a bool specifying whether to print the compute time
:param initial_dac_values: the initial dac values to set the GUI to as a numpy array of length n_gate
"""
# importing the run_gui function here to avoid circular imports
from ..gui import run_gui
run_gui(self, port=port, print_compute_time=print_compute_time)
run_gui(self, port=port, print_compute_time=print_compute_time, initial_dac_values=initial_dac_values)
9 changes: 7 additions & 2 deletions qarray/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .helper_functions import create_gate_options, n_charges_options, unique_last_axis, plot_options


def run_gui(model, port=27182, run=True, print_compute_time=False):
def run_gui(model, port=27182, run=True, print_compute_time=False, initial_dac_values=None):
"""
Create the GUI for the DotArray model.
Expand Down Expand Up @@ -49,6 +49,11 @@ def run_gui(model, port=27182, run=True, print_compute_time=False):
virtual_gate_matrix = np.round(virtual_gate_matrix, 3)
virtual_gate_matrix = pd.DataFrame(virtual_gate_matrix, dtype=float, columns=[f'vP{i + 1}' for i in range(n_gate)])

if initial_dac_values is None:
initial_dac_values = np.zeros(n_gate)
else:
initial_dac_values = np.round(initial_dac_values, 3)

app.layout = html.Div([
# First Row: Tables
html.Div([
Expand Down Expand Up @@ -152,7 +157,7 @@ def run_gui(model, port=27182, run=True, print_compute_time=False):
dcc.Input(
id=f'dac_{i}',
type='number',
value=0,
value=float(initial_dac_values[i]),
placeholder=f'P{i}',
step=0.1,
style={'margin-bottom': '10px', 'display': 'block'}
Expand Down

0 comments on commit 0b2f94b

Please sign in to comment.