Skip to content

Commit

Permalink
Adding plot options to gui
Browse files Browse the repository at this point in the history
  • Loading branch information
b-vanstraaten committed Jul 19, 2024
1 parent c0bded9 commit e39db1a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 33 deletions.
Binary file modified docs/source/figures/getting_started_example.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/figures/latching.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions examples/default_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
charge_carrier='h', T=0.,
)

model.run_gui()

# a helper class designed to make it easy to create gate voltage arrays for nd sweeps
voltage_composer = GateVoltageComposer(n_gate=model.n_gate)

Expand Down
2 changes: 1 addition & 1 deletion examples/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
implementation='rust', charge_carrier='h', T=0., threshold=1.,
max_charge_carriers=4,
)
model.run_gui(plot = 'changes')
model.run_gui()
4 changes: 2 additions & 2 deletions qarray/DotArrays/DotArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ def compute_threshold_estimate(self):
"""
return compute_threshold(self.cdd)

def run_gui(self, port=27182, print_compute_time: bool = False, plot = 'changes', cmap = None):
def run_gui(self, port=27182, print_compute_time: bool = False):
"""
Creates a GUI for the dot array
"""
# 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, plot = plot, cmap = cmap)
run_gui(self, port=port, print_compute_time=print_compute_time)
59 changes: 30 additions & 29 deletions qarray/gui/gui.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import re
from time import perf_counter

import dash
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from dash import dash_table
from dash import dcc, html
from dash.dependencies import Input, Output

import plotly.express as px

from qarray import DotArray, GateVoltageComposer, dot_occupation_changes, charge_state_to_unique_index
from .helper_functions import create_gate_options, n_charges_options, unique_last_axis
from .helper_functions import create_gate_options, n_charges_options, unique_last_axis, plot_options

import re


def run_gui(model, port=27182, run=True, print_compute_time=False, plot='changes', cmap=None):
def run_gui(model, port=27182, run=True, print_compute_time=False):
"""
Create the GUI for the DotArray model.
Expand All @@ -27,10 +25,6 @@ def run_gui(model, port=27182, run=True, print_compute_time=False, plot='changes
port : int
run : bool
print_compute_time : bool
plot : str : 'changes' or 'colour_map' (default 'changes')
cmap : str : the colormap to use for the plot if None the default colormap is used.
This is only used for the 'colour_map' plot argument. The allowed values are the names of the colour maps
in plotly.express.colors.named_colorscales()
"""

app = dash.Dash(__name__)
Expand Down Expand Up @@ -134,23 +128,35 @@ def run_gui(model, port=27182, run=True, print_compute_time=False, plot='changes
], style={'display': 'inline-block', 'width': '30%', 'vertical-align': 'top'}),

html.Div([
html.H4("n charges options"),
html.H4("Open/Closed options"),
dcc.Dropdown(
id='dropdown-menu-n-charges',
placeholder='Select n charges',
options=n_charges_options,
value='any'
),

html.H4("Plot options"),
dcc.Dropdown(
id='plot-options',
placeholder='Whether to plot changes or colours and if so the colour map',
options=plot_options,
value='changes'
)

], style={'display': 'inline-block', 'width': '30%', 'margin-right': '2%', 'vertical-align': 'top'}),

], style={'text-align': 'left', 'margin-bottom': '20px', 'display': 'flex',
'justify-content': 'space-between'}),

html.Div([
html.Div([
dcc.Graph(
id='heatmap',
style={'width': '100%', 'display': 'block', 'margin-left': 'auto', 'margin-right': 'auto'}
)
], style={'text-align': 'center', 'margin-top': '20px'})
])
])

@app.callback(
Expand All @@ -164,10 +170,11 @@ def run_gui(model, port=27182, run=True, print_compute_time=False, plot='changes
Input('input-scalar1', 'value'),
Input('input-scalar2', 'value'),
Input('dropdown-menu-n-charges', 'value'),
Input('plot-options', 'value'),
*[Input(f'dac_{i}', 'value') for i in range(model.n_gate)]
)
def update(Cdd, Cgd, x_gate, x_amplitude, x_resolution, y_gate, y_amplitude, y_resolution,
n_charges, *dac_values, cmap=cmap):
n_charges, plot_options, *dac_values):
"""
Update the heatmap based on the input values.
"""
Expand Down Expand Up @@ -283,23 +290,17 @@ def update(Cdd, Cgd, x_gate, x_amplitude, x_resolution, y_gate, y_amplitude, y_r
if print_compute_time:
print(f'Time taken to compute the charge state: {t1 - t0:.3f}s')

match plot:
case 'changes':
z = dot_occupation_changes(n).astype(float)
if cmap is None:
cmap = 'greys'

case 'colour_map':
z = charge_state_to_unique_index(n).astype(float)
z = np.log2(z + 1)

if cmap is None:
cmap = 'cividis'

case _:
raise ValueError(f'Plot {plot} is not recognized the options are "changes" or "colour_map"')
if plot_options in px.colors.named_colorscales():
z = charge_state_to_unique_index(n).astype(float)
z = np.log2(z + 1)
cmap = plot_options
elif plot_options == 'changes':
z = dot_occupation_changes(n).astype(float)
cmap = 'greys'
else:
raise ValueError(
f'Plot {plot_options} is not recognized the options are "changes" or a colour map in {px.colors.named_colorscales()}')

assert cmap in px.colors.named_colorscales(), f'cmap {cmap} is not a valid colormap the options are {px.colors.named_colorscales()}'
# Create the heatmap
fig = go.Figure(data=go.Heatmap(
z=z,
Expand Down Expand Up @@ -337,7 +338,7 @@ def update(Cdd, Cgd, x_gate, x_amplitude, x_resolution, y_gate, y_amplitude, y_r
showarrow=False,
font=dict(
color='black',
size=7
size=11
)
)

Expand Down
8 changes: 7 additions & 1 deletion qarray/gui/helper_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
from itertools import combinations

import numpy as np
import plotly.express as px


def unique_last_axis(arr):
"""
Expand Down Expand Up @@ -41,6 +43,10 @@ def create_gate_options(N):
return [{'label': gate, 'value': gate} for gate in true_gates + virtual_gates + e_gates + u_gates]


plot_options = [{'label': 'charge transitions', 'value': 'changes'}] + [{'label': name, 'value': name} for name in
px.colors.named_colorscales()]


n_charges_options = [
{'label': 'Any', 'value': 'any'},
# Add other options as needed, for example:
Expand Down

0 comments on commit e39db1a

Please sign in to comment.