/ dilution_controller_src / cycle_routines.py
cycle_routines.py
  1  from threading import Thread
  2  import itertools
  3  import time
  4  import datetime
  5  from utilities.Utils import heater_off, heater_on, isfinished, heater_PID_config, switch_off, switch_on
  6  
  7  
  8  
  9  
 10  class Cooldown_routine(Thread):
 11      def __init__(self, data, lock):
 12          self.data_buffer = data
 13          self.lock = lock
 14  
 15          super().__init__()
 16  
 17      def PID_config(self):
 18          with self.lock:
 19              for device in [ctc100A, ctc100B]:
 20                  for channel in device.output_channels:
 21                      # status = device.write(f'{channel}.value ?')
 22                      status = device.get_variable(channel)
 23                      if status > 0:
 24                          heater_off(device, channel)
 25                  for channel in device.aio_channels[:2]:
 26                      # status = device.write(f'{channel}.value ?')
 27                      status = device.get_variable(channel)
 28                      if status > 1:
 29                          switch_off(device, channel)
 30  
 31          with self.lock:
 32              for system in [He7_A_channels, He7_B_channels]:
 33                  heater_PID_config(system['device'],
 34                                  system['He4_heater'], system['He4_pump'])
 35                  heater_PID_config(system['device'],
 36                                  system['He3_heater'], system['He3_pump'])
 37                  heater_off(system['device'], system['He4_heater'])
 38                  heater_off(system['device'], system['He3_heater'])
 39          time.sleep(1)
 40  
 41          with self.lock:
 42              for system in [He7_A_channels, He7_B_channels]:
 43                  heater_on(system['device'], system['He4_heater'])
 44                  heater_on(system['device'], system['He3_heater'])
 45          
 46          time.sleep(100)
 47      
 48      def first_run_precooling(self):
 49  
 50          data_copy = self.data_buffer.copy()
 51          for system in [He7_B_channels, He7_A_channels]:
 52              print(f"checking {system['device'].name}")
 53              while data_copy[f"LakeshoreModel372/{system['He4_head']}"][-1] > 3.5 and isfinished(data_copy['time'], data_copy[f"LakeshoreModel372/{system['He4_head']}"]):
 54                  time.sleep(1)
 55                  data_copy = self.data_buffer.copy()
 56              print(f"4He Heat switch on {system['device'].name}")
 57              with self.lock:
 58  
 59                  heater_off(system['device'], system['He4_heater'])
 60                  switch_on(system['device'], system['He4_aio'])
 61  
 62          print(f'Waiting for 10 minutes, starting at {datetime.datetime.now()}')
 63          time.sleep(600)
 64  
 65          data_copy = self.data_buffer.copy()
 66  
 67          for system in [He7_A_channels, He7_B_channels]:
 68              print(f"checking {system['device'].name} {system['He3_head']}")
 69  
 70              while data_copy[f"LakeshoreModel372/{system['He3_head']}"][-1] > 1.5 and isfinished(data_copy['time'], data_copy[f"LakeshoreModel372/{system['He3_head']}"]):
 71                  time.sleep(1)
 72                  data_copy = self.data_buffer.copy()
 73              print(f"Heater on {system['device'].name} {system['He3_head']}")
 74  
 75              with self.lock:
 76  
 77                  heater_off(system['device'], system['He3_heater'])
 78                  switch_on(system['device'], system['He3_aio'])
 79  
 80              data_copy = self.data_buffer.copy()
 81          print(f'sleeping 5 min starting at {datetime.datetime.now()}')
 82          time.sleep(600)
 83  
 84          for system in [He7_A_channels, He7_B_channels]:
 85              print('Aspettando l\'inverno')
 86              while (condition_temperature := data_copy[f"LakeshoreModel372/{system['He3_head']}"][-1] > 0.45) and (condition_stability := isfinished(data_copy['time'], data_copy[f"LakeshoreModel372/{system['He3_head']}"] )):
 87                  time.sleep(2)
 88                  data_copy = self.data_buffer.copy()
 89              if not condition_temperature:
 90                  print('walrus activated, sleeping 10 minutes')
 91                  time.sleep(600)
 92  
 93          print(f'End of precooling, allowing it to stabilise, waiting 7 minute starting at {datetime.datetime.now()}')
 94          time.sleep(300)
 95  
 96  
 97      def run(self):
 98          
 99          print('Starting flipflop cooling')
100          
101  
102         
103  
104          list_of_systems = {'System A': [
105              He7_A_channels, True], 'System_B': [He7_B_channels, False]}
106          Still_voltages = [50, 55, 60, 65, 30]
107          MC_setpoints = [0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.2]
108  
109          for V, setpoint, (system, status) in itertools.product(Still_voltages, MC_setpoints, list_of_systems.items()):
110              if status:
111                  model372.set_still_voltage(V)
112                  model372.set_MC_setpoint(setpoint)
113                  print(
114                      f'Still output: {V}, Mixing Chamber setpoint: {setpoint}')
115                  status_update = self.cryo_cool(list_of_systems[system][0])
116                  list_of_systems[system][1] = status_update
117              else:
118                  list_of_systems[system][1] = True
119  
120          while True:
121              for key, values in list_of_systems.items():
122                  system, status = values
123                  if status:
124                      status_update = self.cryo_cool(system)
125                      list_of_systems[key][1] = status_update
126                  else:
127                      list_of_systems[key][1] = True
128  
129      def update_list_of_temperature(self, data_list):
130          for key in self.data_buffer:
131              data_list[key].extend(self.data_buffer[key])
132  
133      def cryo_cool(self, system):
134          print(f"Switching off Heat switches on {system['device'].name}")
135          with self.lock:
136  
137              switch_off(system['device'], system['He4_aio'])
138              switch_off(system['device'], system['He3_aio'])
139  
140          data_copy = self.data_buffer.copy()
141          print(
142              f"checking {system['device'].name} waiting for switches to cool down below 10K")
143          time.sleep(10)
144  
145          while data_copy[f"{system['device'].name}/{system['He4_switch']}"][-1] > 10 or data_copy[f"{system['device'].name}/{system['He3_switch']}"][-1] > 10:
146              time.sleep(2)
147              self.update_list_of_temperature(data_copy)
148          print(
149              f"Heater on {system['device'].name}, waiting for 4He head to reach 3 K")
150  
151          with self.lock:
152  
153              heater_on(system['device'], system['He4_heater'])
154              heater_on(system['device'], system['He3_heater'])
155  
156          print(f'sleeping 10 minutes, startint at {datetime.datetime.now()}')
157  
158          time.sleep(600)
159          print('waking up, startint to check')
160  
161          self.update_list_of_temperature(data_copy)
162  
163          while data_copy[f"LakeshoreModel372/{system['He4_head']}"][-1] > 3.0 and isfinished(data_copy['time'], data_copy[f"LakeshoreModel372/{system['He4_head']}"]):
164              time.sleep(2)
165              self.update_list_of_temperature(data_copy)
166  
167          print(
168              f"Heat switch on {system['device'].name}, wairing for 3He to reach 1.2 K")
169  
170          with self.lock:
171  
172              heater_off(system['device'], system['He4_heater'])
173              switch_on(system['device'], system['He4_aio'])
174  
175          print(f'sleeping 10 minutes, startint at {datetime.datetime.now()}')
176          time.sleep(600)
177          print('waking up, startint to check')
178          self.update_list_of_temperature(data_copy)
179  
180          while data_copy[f"LakeshoreModel372/{system['He3_head']}"][-1] > 1.2 and isfinished(data_copy['time'], data_copy[f"LakeshoreModel372/{system['He3_head']}"]):
181              time.sleep(2)
182              self.update_list_of_temperature(data_copy)
183  
184          print(
185              f"Heat switch on on {system['device'].name}, waiting for 3He to reaching <450mK")
186          with self.lock:
187  
188              heater_off(system['device'], system['He3_heater'])
189              switch_on(system['device'], system['He3_aio'])
190  
191          print(f'sleeping 5 min starting at {datetime.datetime.now()}')
192          time.sleep(300)
193  
194          print('waking again, startint to check')
195          while (condition_temperature := data_copy[f"LakeshoreModel372/{system['He3_head']}"][-1] > 0.450) and (condition_stability := isfinished(data_copy['time'], data_copy[f"LakeshoreModel372/{system['He3_head']}"])):
196              time.sleep(2)
197              self.update_list_of_temperature(data_copy)
198  
199          if not condition_temperature:
200              print(
201                  f'walrus activated, sleeping 10 minutes starting at {datetime.datetime.now()}')
202              time.sleep(600)
203          print('Ready to switch system')
204  
205          return False