Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task visualization #366

Merged
merged 11 commits into from
Aug 5, 2023
Prev Previous commit
Next Next commit
finished the first version of task visualization
  • Loading branch information
Kai-Hsin Wu authored and Kai-Hsin Wu committed Aug 3, 2023
commit 81c8dcff452956c9fe314a00bb8b56f75bc72b50
41 changes: 24 additions & 17 deletions src/bloqade/ir/location/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
from bokeh.plotting import show
import numpy as np
from enum import Enum
from bokeh.models import ColumnDataSource, NumericInput, Button, Range1d, CustomJS
from bokeh.models import (
ColumnDataSource,
NumericInput,
Button,
Range1d,
CustomJS,
HoverTool,
)
from bokeh.plotting import figure
from bokeh.layouts import column, row

Expand Down Expand Up @@ -77,41 +84,40 @@ def figure(self, **assignments):
length_scale = 1

source_filled = ColumnDataSource(
data=dict(x=xs_filled, y=ys_filled, labels=labels_filled)
data=dict(_x=xs_filled, _y=ys_filled, _labels=labels_filled)
)
source_vacant = ColumnDataSource(
data=dict(x=xs_vacant, y=ys_vacant, labels=labels_vacant)
data=dict(_x=xs_vacant, _y=ys_vacant, _labels=labels_vacant)
)
source_all = ColumnDataSource(
data=dict(
x=xs_vacant + xs_filled,
y=ys_vacant + ys_filled,
labels=labels_vacant + labels_filled,
_x=xs_vacant + xs_filled,
_y=ys_vacant + ys_filled,
_labels=labels_vacant + labels_filled,
)
)

TOOLTIPS = [
("(x,y)", "(@x, @y)"),
("index: ", "@labels"),
hover = HoverTool()
hover.tooltips = [
("(x,y)", "(@_x, @_y)"),
("index: ", "@_labels"),
]

## remove box_zoom since we don't want to change the scale
p = figure(
width=400,
height=400,
tools="hover,wheel_zoom,reset, undo, redo, pan",
tooltips=TOOLTIPS,
tools="wheel_zoom,reset, undo, redo, pan",
toolbar_location="above",
)
p.x_range = Range1d(x_min - 1, x_min + length_scale + 1)
p.y_range = Range1d(y_min - 1, y_min + length_scale + 1)

p.circle(
"x", "y", source=source_filled, radius=0.015 * length_scale, fill_alpha=1
"_x", "_y", source=source_filled, radius=0.015 * length_scale, fill_alpha=1
)
p.circle(
"x",
"y",
"_x",
"_y",
source=source_vacant,
radius=0.015 * length_scale,
fill_alpha=0.25,
Expand All @@ -120,15 +126,16 @@ def figure(self, **assignments):
)

p.circle(
"x",
"y",
"_x",
"_y",
source=source_all,
radius=0, # in the same unit as the data
fill_alpha=0,
line_width=0.15 * length_scale,
visible=True, # display by default
name="Brad",
)
p.add_tools(hover)

return p

Expand Down
29 changes: 22 additions & 7 deletions src/bloqade/submission/ir/task_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from decimal import Decimal

from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource, Step
from bokeh.models import ColumnDataSource, Step, HoverTool
from bokeh.layouts import gridplot

from bloqade.submission.ir.capabilities import QuEraCapabilities
Expand Down Expand Up @@ -82,6 +82,9 @@ def _get_data_source(self):
return src

def figure(self, source, **fig_kwargs):
hover = HoverTool()
hover.tooltips = [("(x,y)", "(@times_amp, @values_amp)")]

line_plt = figure(
**fig_kwargs,
x_axis_label="Time (s)",
Expand All @@ -108,6 +111,7 @@ def figure(self, source, **fig_kwargs):
fill_alpha=0.3,
color="#6437FF",
)
line_plt.add_tools(hover)

return line_plt

Expand Down Expand Up @@ -150,8 +154,11 @@ def _get_data_source(self):
return src

def figure(self, source, **fig_kwargs):
TOOLTIPS = [("(x,y)", "(@times_phase, @values_phase)")]

line_plt = figure(
**fig_kwargs,
tooltips=TOOLTIPS,
x_axis_label="Time (s)",
y_axis_label="Value (rad)",
)
Expand Down Expand Up @@ -228,8 +235,13 @@ def _get_data_source(self):
return src

def global_figure(self, source, **fig_kwargs):
TOOLTIPS = [("(x,y)", "(@times_detune, @values_detune)")]

line_plt = figure(
**fig_kwargs, x_axis_label="Time (s)", y_axis_label="Value (rad/s)"
**fig_kwargs,
tooltips=TOOLTIPS,
x_axis_label="Time (s)",
y_axis_label="Value (rad/s)",
)

line_plt.x_range.start = 0
Expand Down Expand Up @@ -319,7 +331,11 @@ def discretize(self, task_capabilities: QuEraCapabilities):

def figure(self):
## use ir.Atom_oarrangement's plotting:
reg = ListOfLocations().add_positions(self.sites, self.filling)
## covert unit to m -> um
sites_um = list(
map(lambda cord: (float(cord[0]) * 1e6, float(cord[1]) * 1e6), self.sites)
)
reg = ListOfLocations().add_positions(sites_um, self.filling)
fig_reg = reg.figure() # ignore the B-rad widget
return fig_reg

Expand Down Expand Up @@ -388,16 +404,15 @@ def figure(self):
# lattice:
register = self.lattice.figure()

full_plt = gridplot(
col_plt = gridplot(
[[rabi_amplitude], [global_detuning], [rabi_phase]],
merge_tools=False,
sizing_mode="stretch_both",
)
# full_plt.width_policy = "max"
col_plt.width_policy = "max"

full_plt = row(full_plt, register)
full_plt = row(col_plt, register, sizing_mode="stretch_both")
full_plt.width_policy = "max"
full_plt.sizing_mode = "stretch_both"

return full_plt

Expand Down
30 changes: 15 additions & 15 deletions tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@

# import bloqade.lattice as lattice

# dict interface
seq = Sequence(
{
rydberg: {
detuning: {
Uniform: Linear(start=1.0, stop="x", duration=3.0),
ScaledLocations({1: 1.0, 2: 2.0}): Linear(
start=1.0, stop="x", duration=3.0
),
},
}
}
)


n_atoms = 11
lattice_const = 5.9

Expand All @@ -37,6 +22,21 @@
pbin.hardware_tasks[0].task_ir.show()


# dict interface
seq = Sequence(
{
rydberg: {
detuning: {
Uniform: Linear(start=1.0, stop="x", duration=3.0),
ScaledLocations({1: 1.0, 2: 2.0}): Linear(
start=1.0, stop="x", duration=3.0
),
},
}
}
)


# job = HardwareBatchResult.load_json("example-3-2d-ordered-state-job.json")

# res = job.report()
Expand Down