diff --git a/qutil/ui/gate_layout/core.py b/qutil/ui/gate_layout/core.py index c22ab6302ccdc12a56fabe496ce9086546f6edeb..5784e08326da0f97efe2ea4098c11cad5f55e2a2 100644 --- a/qutil/ui/gate_layout/core.py +++ b/qutil/ui/gate_layout/core.py @@ -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(): - self._latest_voltages[self.gate_names.index(gate)] = voltage + 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]) diff --git a/qutil/ui/gate_layout/qcodes.py b/qutil/ui/gate_layout/qcodes.py index 1ce8fc9488dc7cfad6b8e2265cb9c8f739faac3c..44914172d17929762cf5b68c138d5417244310dc 100644 --- a/qutil/ui/gate_layout/qcodes.py +++ b/qutil/ui/gate_layout/qcodes.py @@ -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