Skip to content

Commit

Permalink
updating docs and adding the possibility of plotting the gradient of …
Browse files Browse the repository at this point in the history
…the charge sensor in the GUI.

pypi
documentation
  • Loading branch information
b-vanstraaten committed Dec 7, 2024
1 parent 05860c2 commit 6f5d8b9
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 17 deletions.
Binary file modified docs/source/figures/GUI.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 35 additions & 8 deletions examples/gui_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,47 @@
from qarray import ChargeSensedDotArray
from qarray.noise_models import WhiteNoise, TelegraphNoise, NoNoise

# defining the capacitance matrices
Cdd = [[0., 0.1], [0.1, 0.]] # an (n_dot, n_dot) array of the capacitive coupling between dots
Cgd = [[1., 0.1, 0.05], [0.1, 1., 0.05]] # an (n_dot, n_gate) array of the capacitive coupling between gates and dots
Cds = [[0.05, 0.00]] # an (n_sensor, n_dot) array of the capacitive coupling between dots and sensors
Cgs = [[0.06, 0.05, 1]] # an (n_sensor, n_gate) array of the capacitive coupling between gates and sensor dots




# # # defining the capacitance matrices for a double dot
# Cdd = [[0., 0.1],
# [0.1, 0.]] # an (n_dot, n_dot) array of the capacitive coupling between dots
# Cgd = [[1., 0.1, 0.05],
# [0.1, 1., 0.05]] # an (n_dot, n_gate) array of the capacitive coupling between gates and dots
# Cds = [[0.05, 0.03]] # an (n_sensor, n_dot) array of the capacitive coupling between dots and sensors
# Cgs = [[0.06, 0.05, 1]] # an (n_sensor, n_gate) array of the capacitive coupling between gates and sensor dots
# initial_dac_values = [0, 0.0, 0.5]


# # defining the capacitance matrices for a linear array of 4 dots, uncomment this block and comment the previous block to switch
# # with the sensor on the left hand side
# Cdd = [
# [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.1, 0.05, 0.01, 0.1],
# [0.1, 1., 0.1, 0.05, 0.002],
# [0.05, 0.1, 1., 0.1, 0.001],
# [0.01, 0.05, 0.1, 1, 0.000]
# ]
#
# Cds = [[0.1, 0.05, 0.001, 0.000]] # an (n_sensor, n_dot) array of the capacitive coupling between dots and sensors
# Cgs = [[0.1, 0.04, 0.003, 0.000, 1]] # an (n_sensor, n_gate) array of the capacitive coupling between gates and sensor dots
# initial_dac_values = [0, 0, 0., 0.0, 0.5]


noise_model = WhiteNoise(amplitude=1e-2)

# creating the model
model = ChargeSensedDotArray(
Cdd=Cdd, Cgd=Cgd, Cds=Cds, Cgs=Cgs,
coulomb_peak_width=0.1, T=0,
implementation='rust', algorithm='default',
coulomb_peak_width=0.1,
T=100, # mK
noise_model=noise_model
)
initial_dac_values = [0, 0, 0.5]
model.gui(initial_dac_values = initial_dac_values)
8 changes: 5 additions & 3 deletions qarray/DotArrays/ChargeSensedDotArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from .GateVoltageComposer import GateVoltageComposer
from ._helper_functions import check_algorithm_and_implementation, \
check_and_warn_user, lorentzian, convert_to_maxwell, _convert_to_maxwell_with_sensor
check_and_warn_user, lorentzian, convert_to_maxwell, _convert_to_maxwell_with_sensor, suppress_output
from .ground_state import _ground_state_open, _ground_state_closed
from ..functions import _optimal_Vg, compute_threshold
from ..latching_models import LatchingBaseModel
Expand All @@ -20,6 +20,7 @@
PositiveValuedMatrix



@dataclass
class ChargeSensedDotArray:
"""
Expand Down Expand Up @@ -60,9 +61,9 @@ class ChargeSensedDotArray:
polish: bool = True # a bool specifying whether to polish the result of the ground state computation
max_charge_carriers: int | None = None # need if using a brute_force algorithm
batch_size: int | None = None # needed if using jax implementation
charge_carrier = 'h'
charge_carrier: str = 'h'

T: float | int = 0. # the temperature of the system
T: float | int = 0. # the temperature of the system in mK
n_peak: int = 5

coulomb_peak_width: float = 0.1 # the width of the lorentzian peaks
Expand Down Expand Up @@ -142,6 +143,7 @@ def gui(self, port=9001, run=True, print_compute_time=True, initial_dac_values=N
A function to open the GUI for the ChargeSensedDotArray class
"""
from ..gui.gui_charge_sensor import run_gui_charge_sensor

run_gui_charge_sensor(self, port = port, run = run, print_compute_time = print_compute_time, initial_dac_values = initial_dac_values)

def compute_optimal_virtual_gate_matrix(self):
Expand Down
17 changes: 17 additions & 0 deletions qarray/DotArrays/_helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
from qarray.functions import compute_threshold
from ..qarray_types import (CddInv, Cdd, VectorList, CddNonMaxwell, CgdNonMaxwell, NegativeValuedMatrix)

import sys
from contextlib import contextmanager
from io import StringIO

@contextmanager
def suppress_output():
"""Context manager to suppress all output to the terminal."""
original_stdout = sys.stdout
original_stderr = sys.stderr
try:
sys.stdout = StringIO() # Redirect stdout to a dummy buffer
sys.stderr = StringIO() # Redirect stderr to a dummy buffer
yield
finally:
sys.stdout = original_stdout
sys.stderr = original_stderr


def _convert_to_maxwell_with_sensor(cdd_non_maxwell: CddNonMaxwell, cgd_non_maxwell: CgdNonMaxwell,
cds_non_maxwell: CddNonMaxwell, cgs_non_maxwell: CgdNonMaxwell):
Expand Down
43 changes: 37 additions & 6 deletions qarray/gui/gui_charge_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ def run_gui_charge_sensor(model, port=9000, run=True, print_compute_time=True, i
{'label': 'False', 'value': 'False'}
],
value='True'
),

html.H4("Plot gradient"),
dcc.Dropdown(
id='plot gradient',
placeholder='Whether to plot the gradient of the charge sensor signal',
options=[
{'label': 'True', 'value': 'True'},
{'label': 'False', 'value': 'False'},
{'label': 'Along x axis', 'value': 'Along x'},
{'label': 'Along y axis', 'value': 'Along y'},
{'label': 'Along detuning axis', 'value': 'Along detuning axis'},
{'label': 'Magnitude', 'value': 'Magnitude'},
],
value='False'
)
], style={'width': '20%', 'margin-right': '2%'}),

Expand All @@ -245,18 +260,15 @@ def run_gui_charge_sensor(model, port=9000, run=True, print_compute_time=True, i
Input('plot-options', 'value'),
Input('automatically-update-virtual-gate-matrix', 'value'),
Input('print_charge_state', 'value'),
Input('plot gradient', 'value'),
*[Input(f'dac_{i}', 'value') for i in range(model.n_gate)]]
)
def update(Cdd, Cgd, virtual_gate_matrix, x_gate, x_amplitude, x_resolution, y_gate, y_amplitude, y_resolution,
n_charges, plot_options, automatically_update_virtual_gate_matrix, print_charge_state, *dac_values):
n_charges, plot_options, automatically_update_virtual_gate_matrix, print_charge_state, plot_gradient, *dac_values):
"""
Update the heatmap based on the input values.
"""

if model.T != 0:
print('Warning the GUI plotting currently only works for T=0. The temperature is set to 0.')
model.T = 0

dac_values = np.array(dac_values)

if x_gate == y_gate:
Expand Down Expand Up @@ -305,13 +317,32 @@ def update(Cdd, Cgd, virtual_gate_matrix, x_gate, x_amplitude, x_resolution, y_g
z, n = model.charge_sensor_open(vg)
else:
z, n = model.charge_sensor_closed(vg, n_charge=n_charges)

#if T> 0, we need to round the charge state
n = np.round(n).astype(int)

t1 = perf_counter()
if print_compute_time:
print(f'Time taken to compute the charge state: {t1 - t0:.3f}s')

if plot_options in px.colors.named_colorscales():
cmap = plot_options
z = z.squeeze()

match plot_gradient:
case 'False':
pass
case 'Along x':
z = np.gradient(z, axis=1)
case 'Along y':
z = np.gradient(z, axis=0)
case 'Magnitude':
z = np.sqrt(np.gradient(z, axis=0) ** 2 + np.gradient(z, axis=1) ** 2)
case 'Along detuning axis':
z = np.gradient(z, axis=0) - np.gradient(z, axis=1)
case _:
raise ValueError(f'Plot gradient {plot_gradient} is not recognized the options are "False", "Along x", "Along y" or "magnitude"')

elif plot_options == 'changes':
z = charge_state_changes(n).astype(float)
cmap = 'greys'
Expand All @@ -336,7 +367,7 @@ def update(Cdd, Cgd, virtual_gate_matrix, x_gate, x_amplitude, x_resolution, y_g
fig.update_xaxes(title_text=x_gate, ticktext=x_text, tickvals=x_tickvals)
fig.update_yaxes(title_text=y_gate, ticktext=y_text, tickvals=y_tickvals)

charge_states = unique_last_axis(n)
charge_states = unique_last_axis(np.round(n).astype(int))

if print_charge_state == 'False':
return fig, virtual_gate_matrix.to_dict('records')
Expand Down

0 comments on commit 6f5d8b9

Please sign in to comment.