diff --git a/core_tools/drivers/gates.py b/core_tools/drivers/gates.py index f2b29de866323404e81013d6c89734d9562d6da0..bb6a2965cdb01fd4125fec4c996f9860285add1d 100644 --- a/core_tools/drivers/gates.py +++ b/core_tools/drivers/gates.py @@ -15,6 +15,7 @@ class gates(qc.Instrument): gates class, generate qcodes parameters for the real gates and the virtual gates It also manages the virtual gate matrix. """ + def __init__(self, name, hardware, dac_sources, dc_gain={}): ''' gates object @@ -52,9 +53,9 @@ class gates(qc.Instrument): self._dac_params[gate_name] = dac_sources[source_index].parameters[f'dac{int(ch_num)}'] self._all_gate_names.append(gate_name) self._real_gates.append(gate_name) - self.add_parameter(gate_name, set_cmd = partial(self._set_voltage, gate_name), + self.add_parameter(gate_name, set_cmd=partial(self._set_voltage, gate_name), get_cmd=partial(self._get_voltage, gate_name), - unit = "mV") + unit="mV") # make virtual gates: for virt_gate_set in self.hardware.virtual_gates: @@ -135,7 +136,7 @@ class gates(qc.Instrument): self.parameters[real_gate].set(old_voltages[real_gate] + ratio * delta) except Exception as ex: logger.warning(f'Failed to set virtual gate voltage to {voltage:.1f} mV; Reverting all voltages. ' - f'Exception: {ex}') + f'Exception: {ex}') for real_gate, ratio in projection[gate_name].items(): self.set(real_gate, old_voltages[real_gate]) raise @@ -199,7 +200,7 @@ class gates(qc.Instrument): for virt_gate_convertor in self._virt_gate_convertors: real_voltages = [v[name] for name in virt_gate_convertor.real_gates] - virtual_voltages = np.matmul(virt_gate_convertor.r2v_matrix, real_voltages) + virtual_voltages = np.matmul(virt_gate_convertor.r2v_matrix, real_voltages) for vg_name, vg_voltage in zip(virt_gate_convertor.virtual_gates, virtual_voltages): v[vg_name] = vg_voltage self.parameters[vg_name].cache.set(vg_voltage) diff --git a/core_tools/drivers/hardware/virtual_gate_matrix.py b/core_tools/drivers/hardware/virtual_gate_matrix.py index 2246172207826c58856a346f145849f463d7796f..8769a719ac4481fd482602ce672dd0e172959a0b 100644 --- a/core_tools/drivers/hardware/virtual_gate_matrix.py +++ b/core_tools/drivers/hardware/virtual_gate_matrix.py @@ -1,5 +1,6 @@ import numpy as np + class VirtualGateMatrixView: ''' Data to convert real gate voltages to virtual gate voltages and v.v. @@ -10,6 +11,7 @@ class VirtualGateMatrixView: virtual_gates (list[str]): names of virtual gates r2v_matrix (2D array-like): matrix to convert voltages of real gates to voltages of virtual gates. ''' + def __init__(self, name, real_gates, virtual_gates, r2v_matrix, indices): self.name = name self._real_gates = real_gates @@ -34,7 +36,7 @@ class VirtualGateMatrixView: @property def r2v_matrix(self): # note: self._r2v_matrix may be changed externally. Create indexed copy here. - r2v_matrix = self._r2v_matrix[self._indices][:,self._indices] + r2v_matrix = self._r2v_matrix[self._indices][:, self._indices] return r2v_matrix @@ -112,16 +114,16 @@ class VirtualGateMatrix: def get_element(self, i, j, v2r=True): if v2r: - return self._v2r_matrix[i,j] + return self._v2r_matrix[i, j] else: - return self._r2v_matrix[i,j] + return self._r2v_matrix[i, j] def set_element(self, i, j, value, v2r=True): if v2r: - self._v2r_matrix[i,j] = value + self._v2r_matrix[i, j] = value self._r2v_matrix[:] = np.linalg.inv(self._v2r_matrix) else: - self._r2v_matrix[i,j] = value + self._r2v_matrix[i, j] = value self._v2r_matrix[:] = np.linalg.inv(self._r2v_matrix) self._calc_normalized() @@ -145,7 +147,7 @@ class VirtualGateMatrix: if self._normalization: # divide rows by diagonal value - norm = no_norm/np.diag(no_norm)[:,None] + norm = no_norm/np.diag(no_norm)[:, None] else: norm = no_norm @@ -156,7 +158,7 @@ class VirtualGateMatrix: real_gate_names = [] virtual_gate_names = [] - for i,name in enumerate(self.real_gate_names): + for i, name in enumerate(self.real_gate_names): if name in available_gates: gate_indices.append(i) real_gate_names.append(name) @@ -165,6 +167,5 @@ class VirtualGateMatrix: return VirtualGateMatrixView(self.name, real_gate_names, virtual_gate_names, - self._norm_r2v_matrix, + self._r2v_matrix, gate_indices) -