Skip to content
Snippets Groups Projects
Commit 6a1fe455 authored by Tobias Hangleiter's avatar Tobias Hangleiter
Browse files

Merge branch 'maint/gate_layout' into 'master'

Get gate_layout back up to speed

See merge request !179
parents 26619b09 085dc22a
No related branches found
No related tags found
1 merge request!179Get gate_layout back up to speed
......@@ -4,6 +4,7 @@ Created on Mon Apr 25 11:14:02 2022
@author: Hangleiter
"""
import logging
import pathlib
import warnings
from itertools import compress
......@@ -22,12 +23,11 @@ try:
except ImportError:
ezdxf = None
DEFAULT_TEXT_KWARGS = dict(backgroundcolor='black',
horizontalalignment='center',
verticalalignment='center',
color='white', fontsize=8)
LOG = logging.getLogger(__name__)
class GateLayout:
......@@ -50,11 +50,12 @@ class GateLayout:
gate_mask = [True]*14 + [False, True, False, True, False, True, False, True]
if len(gate_names) != len(gate_mask):
warnings.warn(f"Gate name number is different from gate mask number: {len(gate_names)} != {len(gate_mask)}",
stacklevel=2)
warnings.warn("Gate name number is different from gate mask number: "
f"{len(gate_names)} != {len(gate_mask)}", stacklevel=2)
self.fig = plt.figure(fignum)
self.ax = self.fig.add_axes([0, 0, 1, 1])
self.fig.clear()
self.ax = self.fig.subplots()
self.layout_file = layout_file
self.gate_names = gate_names
self.gate_mask = gate_mask
......@@ -62,7 +63,7 @@ class GateLayout:
self.background_color = matplotlib.colors.to_hex(background_color)
self.foreground_color = matplotlib.colors.to_hex(foreground_color)
self.cmap = matplotlib.cm.get_cmap(cmap)
self.cmap = matplotlib.colormaps.get_cmap(cmap)
self.norm = matplotlib.colors.Normalize(v_min, v_max)
self.v_min = self.norm.vmin
self.v_max = self.norm.vmax
......@@ -101,7 +102,10 @@ class GateLayout:
self.get_voltages(force)
elif isinstance(voltages, dict):
for gate, voltage in voltages.items():
try:
self._latest_voltages[self.gate_names.index(gate)] = voltage
except ValueError:
LOG.warning(f'Gate not found. Skipping: {gate}')
else:
self._latest_voltages[:] = np.broadcast_to(voltages, self._latest_voltages.shape)
......@@ -118,16 +122,18 @@ class GateLayout:
return self._latest_voltages
def _setup_figure(self):
vertices = get_vertices_from_dfx(self.layout_file, self.background_color, self.foreground_color)
vertices = get_vertices_from_dfx(self.layout_file, self.background_color,
self.foreground_color)
if len(self.gate_names) != len(vertices):
warnings.warn(f"Found {len(vertices)} patches in file but got {len(self.gate_names)} gate names", stacklevel=2)
warnings.warn(f"Found {len(vertices)} patches in file but got {len(self.gate_names)} "
"gate names", stacklevel=2)
patches = []
texts = []
for idx, verts in enumerate(vertices):
verts += self._offset[None, :]
patches.append(matplotlib.patches.Polygon(verts, True, zorder=0))
texts.append(matplotlib.text.Text(*verts.mean(axis=0), f'INIT', **self.text_kwargs))
patches.append(matplotlib.patches.Polygon(verts, closed=True, zorder=0))
texts.append(matplotlib.text.Text(*verts.mean(axis=0), 'INIT', **self.text_kwargs))
all_coords = np.array([(patch.get_xy().mean(axis=0)) for patch in patches])
......
......@@ -17,6 +17,7 @@ class QcodesGateLayout(GateLayout):
class MaskedGate(qc.Parameter):
def __init__(self, name, *args, **kwargs):
super().__init__(name, *args, **kwargs)
def get_raw(self):
return 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment