Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding DMM notebook and Modifying SLM Mask (#569)
Browse files Browse the repository at this point in the history
* adding dmm, draw to DetuningMap

* Testing avoiding circular import

* Refactoring to avoid circular imports

* Fix broken UTs

* Import sorting

* Fixing plot DetuningMap

* Serialization/Deserialization of DMM in device

* Fixing typos

* Testing DMM and DetuningMap

* Fixing typo

* adding xfails, fixing type

* Remove DMM from devices and finish UTs

* Take into account review comments

* Add annotations

* Error in Global and Local

* Defining _DMMSchedule

* Fixing nits

* Fixing typo

* Creating DMM notebook, modif SLM notebook

* Taking into account review comments

* Fixing type

* Fix labels in reg_drawer, draw det_maps in seq

* Fixing doc build, add draw_detuning_maps to docs

* Separating register/det_maps drawing from channels

* introducing get_qubit_data

* Add drawing of quantities per qubit

* Fixing for local pulses

* Adding bounds to label

* Drawing legend for local targetting

* FIX sampling rate, QutipEmulator

* Updating figures

* Updating SLM Mask & local addressability notebook

* Adding explanation text

* Fixing type

* Replace modulate_det_map by add_dmm_detuning

* Replace modulate_det_map for add_dmm_detuning

* Fixing tests

* Revert changes to Bayesian optimization notebook

* Fixing docs

* clearing outputs

* Deleting scaling in favor extending to draw reg

* Placing legend in lower part of drawing

* Updating figures

* Relaunching bayesian optimisation

* Taking into account review comments

* Printing sequence with DMM

* Adding subscript and indent

* Defining __str__ for DMM

---------

Co-authored-by: HGSilveri <henrique.silverio@tecnico.ulisboa.pt>
a-corni and HGSilveri authored Sep 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent fa0698f commit 082aa81
Showing 14 changed files with 1,506 additions and 331 deletions.
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -87,6 +87,7 @@ computers and simulators, check the pages in :doc:`review`.
tutorials/reg_layouts
tutorials/interpolated_wfs
tutorials/serialization
tutorials/dmm
tutorials/slm_mask
tutorials/output_mod_eom
tutorials/virtual_devices
3 changes: 3 additions & 0 deletions docs/source/tutorials/dmm.nblink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "../../../tutorials/advanced_features/Local addressability with DMM.ipynb"
}
49 changes: 37 additions & 12 deletions pulser-core/pulser/register/_reg_drawer.py
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ def _draw_2D(
masked_qubits: set[QubitId] = set(),
are_traps: bool = False,
dmm_qubits: Mapping[QubitId, float] = {},
label_name: str = "atoms",
) -> None:
ordered_qubit_colors = RegDrawer._compute_ordered_qubit_colors(
ids, qubit_colors
@@ -68,9 +69,14 @@ def _draw_2D(
ix, iy = plane

if are_traps:
params = dict(s=50, edgecolors="black", facecolors="none")
params = dict(
s=50,
edgecolors="black",
facecolors="none",
label="traps",
)
else:
params = dict(s=30, c=ordered_qubit_colors)
params = dict(s=30, c=ordered_qubit_colors, label=label_name)

ax.scatter(pos[:, ix], pos[:, iy], alpha=0.7, **params)

@@ -93,15 +99,19 @@ def _draw_2D(
if i in dmm_qubits.keys():
dmm_pos.append(c)
dmm_arr = np.array(dmm_pos)
max_weight = max(dmm_qubits.values())
alpha = (
0.2 * np.array(list(dmm_qubits.values())) / max_weight
if max_weight > 0
else 0
)
ax.scatter(
dmm_arr[:, ix],
dmm_arr[:, iy],
marker="s",
s=1200,
alpha=0.2
* np.array(list(dmm_qubits.values()))
/ max(dmm_qubits.values()),
c="black",
alpha=alpha,
c="black" if not qubit_colors else ordered_qubit_colors,
)
axes = "xyz"

@@ -115,6 +125,7 @@ def _draw_2D(
# Determine which labels would overlap and merge those
plot_pos = list(pos[:, (ix, iy)])
plot_ids: list[list[str]] = [[f"{i}"] for i in ids]
dmm_qubits = {str(q): w for q, w in dmm_qubits.items()}
# Threshold distance between points
epsilon = 1.0e-2 * np.diff(ax.get_xlim())[0]

@@ -152,9 +163,7 @@ def _draw_2D(
qubit_det = []
for q in plot_ids[i][j:]:
extra_label = (
f": {dmm_qubits[int(q)]:.2f}"
if not is_mask
else ""
f":{dmm_qubits[q]:.2f}" if not is_mask else ""
)
qubit_det.append(q + extra_label)
plot_ids[i][j:] = [", ".join(qubit_det)]
@@ -215,6 +224,15 @@ def _draw_2D(
# Only draw central axis lines when not drawing the graph
ax.axvline(0, c="grey", alpha=0.5, linestyle=":")
ax.axhline(0, c="grey", alpha=0.5, linestyle=":")
ax.legend(
loc="best",
bbox_to_anchor=(0.0, 0.0, 1.0, 0.3),
prop=dict(stretch="condensed", size=8),
handlelength=1.5,
handleheight=0.6,
handletextpad=0.1,
markerscale=0.8,
)

@staticmethod
def _draw_3D(
@@ -351,6 +369,7 @@ def _initialize_fig_axes(
pos: np.ndarray,
blockade_radius: Optional[float] = None,
draw_half_radius: bool = False,
nregisters: int = 1,
) -> tuple[plt.figure.Figure, plt.axes.Axes]:
"""Creates the Figure and Axes for drawing the register."""
diffs = RegDrawer._register_dims(
@@ -364,15 +383,20 @@ def _initialize_fig_axes(
Ls = proportions * max(
min(big_side / 4, 10), 4
) # Figsize is, at most, (10,10), and, at least (4,*) or (*,4)
Ls[1] = max(Ls[1], 1.0) # Figsize height is at least 1
fig, axes = plt.subplots(figsize=Ls, layout="constrained")
Ls[1] = max(Ls[1], 2.0 * nregisters) # Figsize height is at least 2
fig, axes = plt.subplots(
nrows=nregisters,
figsize=Ls * nregisters,
layout="constrained",
)
return (fig, axes)

@staticmethod
def _initialize_fig_axes_projection(
pos: np.ndarray,
blockade_radius: Optional[float] = None,
draw_half_radius: bool = False,
nregisters: int = 1,
) -> tuple[plt.figure.Figure, plt.axes.Axes]:
"""Creates the Figure and Axes for drawing the register projections."""
diffs = RegDrawer._register_dims(
@@ -401,9 +425,10 @@ def _initialize_fig_axes_projection(
fig_width = min(np.sum(widths), fig_height * 4)

rescaling = 20 / max(max(fig_width, fig_height), 20)
figsize = (rescaling * fig_width, rescaling * fig_height)
figsize = (rescaling * fig_width, rescaling * fig_height * nregisters)

fig, axes = plt.subplots(
nrows=nregisters,
ncols=3,
figsize=figsize,
gridspec_kw=dict(width_ratios=widths),
1 change: 1 addition & 0 deletions pulser-core/pulser/register/weight_maps.py
Original file line number Diff line number Diff line change
@@ -126,6 +126,7 @@ def draw(
pos,
labels_,
with_labels=labels is not None,
are_traps=True,
dmm_qubits=dict(zip(labels_, self.weights)),
)

Loading

0 comments on commit 082aa81

Please sign in to comment.