Skip to content
Snippets Groups Projects
Commit 28e73bbd authored by Sander Snoo's avatar Sander Snoo
Browse files

"gates" should use virtual matrix as shown in GUI and not the normalized matrix

parent 7b3816ec
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment