From 93fa6f0020c2241dfabfb999cb9726681f59079a Mon Sep 17 00:00:00 2001 From: amirhassank Date: Tue, 30 Jun 2020 11:56:26 -0400 Subject: [PATCH] beta-calibration added to State_Discriminator --- State_Discriminator/State_Discriminator.ini | 490 ++++++++++++++++++++ State_Discriminator/State_Discriminator.py | 44 +- 2 files changed, 528 insertions(+), 6 deletions(-) diff --git a/State_Discriminator/State_Discriminator.ini b/State_Discriminator/State_Discriminator.ini index 5bc281b..dbb81f4 100755 --- a/State_Discriminator/State_Discriminator.ini +++ b/State_Discriminator/State_Discriminator.ini @@ -59,6 +59,13 @@ combo_def_6: Six combo_def_7: Seven combo_def_8: Eight combo_def_9: Nine +combo_def_10: Ten +combo_def_11: Eleven +combo_def_12: Twelve +combo_def_13: Thirteen +combo_def_14: Fourteen +combo_def_15: Fifteen +combo_def_16: Sixteen def_value: Two group: Method section: Training @@ -344,8 +351,274 @@ section: Training state_quant: Number of states state_value_1: Three +[Pointer, QB10-S0] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB10-S1] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB10-S2] +datatype: COMPLEX +group: Pointer states +section: Training +state_quant: Number of states +state_value_1: Three + +[Pointer, QB11-S0] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB11-S1] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB11-S2] +datatype: COMPLEX +group: Pointer states +section: Training +state_quant: Number of states +state_value_1: Three + +[Pointer, QB12-S0] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB12-S1] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB12-S2] +datatype: COMPLEX +group: Pointer states +section: Training +state_quant: Number of states +state_value_1: Three + +[Pointer, QB13-S0] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB13-S1] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB13-S2] +datatype: COMPLEX +group: Pointer states +section: Training +state_quant: Number of states +state_value_1: Three + +[Pointer, QB14-S0] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB14-S1] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB14-S2] +datatype: COMPLEX +group: Pointer states +section: Training +state_quant: Number of states +state_value_1: Three + +[Pointer, QB15-S0] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB15-S1] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB15-S2] +datatype: COMPLEX +group: Pointer states +section: Training +state_quant: Number of states +state_value_1: Three + +[Pointer, QB16-S0] +datatype: COMPLEX +group: Pointer states +section: Training + +[Pointer, QB16-S1] +datatype: COMPLEX +group: Pointer states +section: Training +[Pointer, QB16-S2] +datatype: COMPLEX +group: Pointer states +section: Training +state_quant: Number of states +state_value_1: Three +[Activate beta-calibration] +datatype: BOOLEAN +def_value: False +group: Settings +section: Beta Calibration + +[Beta-calibration QB1] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB2] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB3] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB4] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB5] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB6] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB7] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB8] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB9] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB10] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB11] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB12] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB13] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB14] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB15] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration + +[Beta-calibration QB16] +tooltip: beta-calibration matrix (2D numpy array) +datatype: PATH +def_value: ... +state_quant: Activate beta-calibration +state_value_1: True +group: Settings +section: Beta Calibration [Input data, QB1] datatype: VECTOR_COMPLEX @@ -415,6 +688,62 @@ unit: V group: Input section: Data +[Input data, QB10] +datatype: VECTOR_COMPLEX +permission: WRITE +unit: V +group: Input +section: Data +show_in_measurement_dlg: True + +[Input data, QB11] +datatype: VECTOR_COMPLEX +permission: WRITE +unit: V +group: Input +section: Data +show_in_measurement_dlg: True + +[Input data, QB12] +datatype: VECTOR_COMPLEX +permission: WRITE +unit: V +group: Input +section: Data +show_in_measurement_dlg: True + +[Input data, QB13] +datatype: VECTOR_COMPLEX +permission: WRITE +unit: V +group: Input +section: Data +show_in_measurement_dlg: True + +[Input data, QB14] +datatype: VECTOR_COMPLEX +permission: WRITE +unit: V +group: Input +section: Data +show_in_measurement_dlg: True + +[Input data, QB15] +datatype: VECTOR_COMPLEX +permission: WRITE +unit: V +group: Input +section: Data +show_in_measurement_dlg: True + +[Input data, QB16] +datatype: VECTOR_COMPLEX +permission: WRITE +unit: V +group: Input +section: Data +show_in_measurement_dlg: True + [Average QB1 state] datatype: DOUBLE permission: READ @@ -474,6 +803,55 @@ permission: READ group: Output section: Data +[Average QB10 state] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + +[Average QB11 state] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + +[Average QB12 state] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + +[Average QB13 state] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + +[Average QB14 state] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + +[Average QB15 state] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + +[Average QB16 state] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + [Assignment fidelity QB1] datatype: DOUBLE permission: READ @@ -533,6 +911,55 @@ permission: READ group: Output section: Data +[Assignment fidelity QB10] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + +[Assignment fidelity QB11] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + +[Assignment fidelity QB12] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + +[Assignment fidelity QB13] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + +[Assignment fidelity QB14] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + +[Assignment fidelity QB15] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + +[Assignment fidelity QB16] +datatype: DOUBLE +permission: READ +group: Output +section: Data +show_in_measurement_dlg: True + [Average state vector] datatype: VECTOR permission: READ @@ -619,6 +1046,69 @@ x_unit: group: Output section: Data +[QB10 state] +datatype: VECTOR +permission: READ +x_name: Repetition +x_unit: +group: Output +section: Data +show_in_measurement_dlg: True + +[QB11 state] +datatype: VECTOR +permission: READ +x_name: Repetition +x_unit: +group: Output +section: Data +show_in_measurement_dlg: True + +[QB12 state] +datatype: VECTOR +permission: READ +x_name: Repetition +x_unit: +group: Output +section: Data +show_in_measurement_dlg: True + +[QB13 state] +datatype: VECTOR +permission: READ +x_name: Repetition +x_unit: +group: Output +section: Data +show_in_measurement_dlg: True + +[QB14 state] +datatype: VECTOR +permission: READ +x_name: Repetition +x_unit: +group: Output +section: Data +show_in_measurement_dlg: True + +[QB15 state] +datatype: VECTOR +permission: READ +x_name: Repetition +x_unit: +group: Output +section: Data +show_in_measurement_dlg: True + +[QB16 state] +datatype: VECTOR +permission: READ +x_name: Repetition +x_unit: +group: Output +section: Data +show_in_measurement_dlg: True + [System state] datatype: VECTOR permission: READ diff --git a/State_Discriminator/State_Discriminator.py b/State_Discriminator/State_Discriminator.py index 4e325b2..0c3158e 100755 --- a/State_Discriminator/State_Discriminator.py +++ b/State_Discriminator/State_Discriminator.py @@ -13,13 +13,15 @@ class Error(Exception): class Driver(LabberDriver): """ This class implements a Labber driver""" - MAX_QUBITS = 9 + MAX_QUBITS = 16 def performOpen(self, options={}): """Perform the operation of opening the instrument connection""" # define variables for training data sets self.training_cfg = {} self.init_training_data() + self.beta_calibration_matrices = {} + self.use_beta_calibration = False def performClose(self, bError=False, options={}): """Perform the close instrument connection operation""" @@ -46,7 +48,8 @@ def performSetValue(self, quant, value, sweepRate=0.0, options={}): quant.setValue(value) training_vector = quant.getValueArray() # get qubit/state for which data is valid - qubit = int(quant.name[-1]) + #qubit = int(quant.name[-1]) + qubit = extract_qubit_number(quant.name) state = int(self.getValue('Training, input state')) all_states = self.getValue('Train all states at once') @@ -76,6 +79,23 @@ def performSetValue(self, quant, value, sweepRate=0.0, options={}): quant.name.startswith('Pointer,'))): self.training_valid = False + elif quant.name == 'Activate beta-calibration': + self.use_beta_calibration=value + + elif quant.name.startswith('beta-calibration'): + #qubit = int(quant.name[-1]) - 1 + qubit = extract_qubit_number(quant.name) - 1 + try: + matrix = np.load(value) + if matrix.shape != (2,2): + self.log('Beta-calibration matrix has the incorrect shape') + raise Exception('Incorrect matrix shape') + else: + self.beta_calibration_matrices[qubit]=matrix + except: + self.beta_calibration_matrices[qubit]=None + self.log('Error loading beta-calibration matrix from npy file.') + return value def performGetValue(self, quant, options={}): @@ -86,15 +106,22 @@ def performGetValue(self, quant, options={}): # check input if quant.name.startswith('QB'): # qubit = int(quant.name[2]) - 1 - qubit = int(quant.name.split("QB")[1].split(' ')[0]) - 1 + # qubit = int(quant.name.split("QB")[1].split(' ')[0]) - 1 + qubit = extract_qubit_number(quant.name) - 1 value = self.qubit_states[qubit] elif quant.name.startswith('Average QB'): # qubit = int(quant.name[10]) - 1 - qubit = int(quant.name.split('QB')[1].split(' ')[0]) - 1 + # qubit = int(quant.name.split('QB')[1].split(' ')[0]) - 1 + qubit = extract_qubit_number(quant.name) - 1 value = np.mean(self.qubit_states[qubit]) + if self.use_beta_calibration and self.beta_calibration_matrices[qubit] is not None: + beta = self.beta_calibration_matrices[qubit] + m_vector = np.array( [1-value,value] ) + value=np.linalg.inv(beta).dot(m_vector)[1] elif quant.name.startswith('Assignment fidelity QB'): - #qubit = int(quant.name[22]) - 1 - qubit = int(quant.name.split('QB')[1].split(' ')[0]) - 1 + # qubit = int(quant.name[22]) - 1 + # qubit = int(quant.name.split('QB')[1].split(' ')[0]) - 1 + qubit = extract_qubit_number(quant.name) - 1 value = self.assignment_fidelity[qubit] elif quant.name.startswith('Average state vector'): # states are encoded in array of ints @@ -267,6 +294,11 @@ def calculate_states(self): self.state_vector = np.zeros(len(output), dtype=int) self.state_vector += (output * (self.n_state ** n)) +def extract_qubit_number(string): + for word in string.split(): + if 'QB' in word: + num=word.split('QB')[1].split('-')[0].split(' ')[0] + return int(num) if __name__ == '__main__': pass