diff --git a/sodetlib/det_config.py b/sodetlib/det_config.py index 441eb45f..240be04a 100644 --- a/sodetlib/det_config.py +++ b/sodetlib/det_config.py @@ -5,7 +5,7 @@ import sys import time import shutil - +from sodetlib.operations import uxm_setup class YamlReps: class FlowSeq(list): @@ -308,10 +308,7 @@ def apply_to_pysmurf_instance(self, S, load_tune=True): that this does not set any of the tracking-related params since this shouldn't replace tracking_setup. """ - S.set_amplifier_bias( - bias_hemt=self.exp['amp_hemt_Vg'], - bias_50k=self.exp['amp_50k_Vg'] - ) + uxm_setup.setup_amps(S, cfg, optimize=False, update_cfg=False) if load_tune: tunefile = self.exp['tunefile'] diff --git a/sodetlib/operations/uxm_setup.py b/sodetlib/operations/uxm_setup.py index 3ce8697c..f10d6f8f 100644 --- a/sodetlib/operations/uxm_setup.py +++ b/sodetlib/operations/uxm_setup.py @@ -78,12 +78,14 @@ def find_gate_voltage(S, target_Id, amp_name, vg_min=-2.0, vg_max=0, return False @sdl.set_action() -def setup_amps(S, cfg, update_cfg=True, enable_300K_LNA=True): +def setup_amps(S, cfg, update_cfg=True, enable_300K_LNA=True, optimize=True): """ Initial setup for 50k and hemt amplifiers. For C04/C05 cryocards, will first - check if the drain voltages are set. Then checks if drain - currents are in range, and if not will scan gate voltage to find one that - hits the target current. Will update the device cfg if successful. + check if the drain voltages are set. If `optmize`=False, will then apply + the gate voltage values from the config file. If `optmize`=True, + then checks if drain currents are in range, and if not will scan gate + voltage to find one that hits the target current. + Will update the device cfg if successful. The following parameters can be modified in the device cfg, where {amp} is one of ['hemt', 'hemt1', 'hemt2', '50k', '50k1', '50k2']: @@ -105,6 +107,9 @@ def setup_amps(S, cfg, update_cfg=True, enable_300K_LNA=True): If true, will update the device cfg and save the file. enable_300K_LNA: If true, will turn on the 300K LNAs. + optimize : bool + If true, will search for optimal gate voltage values instead of simply + applying the values from the configuration file. """ sdl.pub_ocs_log(S, "Starting setup_amps") @@ -153,26 +158,28 @@ def setup_amps(S, cfg, update_cfg=True, enable_300K_LNA=True): if Vd != exp[f"amp_{amp}_drain_volt"]: S.set_amp_drain_voltage(amp, exp[f"amp_{amp}_drain_volt"]) - # Check drain currents / scan gate voltages - delta_drain_currents = dict() - for amp in amp_list: - delta_Id = np.abs(amp_biases[f"{amp}_drain_current"] - exp[f"amp_{amp}_drain_current"]) - if delta_Id > exp[f'amp_{amp}_drain_current_tolerance']: - S.log(f"{amp} current not within tolerance, scanning for correct gate voltage") + if optimize: + # Check drain currents / scan gate voltages + delta_drain_currents = dict() + for amp in amp_list: + delta_Id = np.abs(amp_biases[f"{amp}_drain_current"] - exp[f"amp_{amp}_drain_current"]) + if delta_Id > exp[f'amp_{amp}_drain_current_tolerance']: + S.log(f"{amp} current not within tolerance, scanning for correct gate voltage") + S.set_amp_gate_voltage(amp, exp[f'amp_{amp}_init_gate_volt'],override=True) + success = find_gate_voltage( + S, exp[f"amp_{amp}_drain_current"], amp, wait_time=exp['amp_step_wait_time'], + id_tolerance=exp[f'amp_{amp}_drain_current_tolerance'] + ) + if not success: + sdl.pub_ocs_log(S, f"Failed determining {amp} gate voltage") + sdl.set_session_data(S, 'setup_amps_summary', summary) + S.C.write_ps_en(0) + return False, summary + + else: + for amp in amp_list: S.set_amp_gate_voltage(amp, exp[f'amp_{amp}_init_gate_volt'],override=True) - success = find_gate_voltage( - S, exp[f"amp_{amp}_drain_current"], amp, wait_time=exp['amp_step_wait_time'], - id_tolerance=exp[f'amp_{amp}_drain_current_tolerance'] - ) - if not success: - sdl.pub_ocs_log(S, f"Failed determining {amp} gate voltage") - sdl.set_session_data(S, 'setup_amps_summary', summary) - S.C.write_ps_en(0) - return False, summary - # Turn on 300K LNAs - if enable_300K_LNA: - S.C.write_optical(0b11) - + # Update device cfg biases = S.get_amplifier_biases() if update_cfg: @@ -180,6 +187,10 @@ def setup_amps(S, cfg, update_cfg=True, enable_300K_LNA=True): cfg.dev.update_experiment({f'amp_{amp}_gate_volt': biases[f'{amp}_gate_volt']}, update_file=True) + # Turn on 300K LNAs + if enable_300K_LNA: + S.C.write_optical(0b11) + summary = {'success': True, **biases} sdl.set_session_data(S, 'setup_amps_summary', summary) return True, summary