Source code for qibolab._core.instruments.erasynth
importjsonimportrequestsfromqcodes_contrib_drivers.drivers.ERAInstrumentsimportERASynthPlusPlusfromqibo.configimportlogfrom.oscillatorimportLocalOscillator,LocalOscillatorSettings__all__=["ERASynth"]RECONNECTION_ATTEMPTS=10"""Number of times to attempt sending requests to the web server in case offailure."""TIMEOUT=10"""Timeout time for HTTP requests in seconds."""classERASynthEthernet:"""ERA ethernet driver that follows the QCoDeS interface. Controls the instrument via HTTP requests to the instrument's web server. """def__init__(self,name,address):self.name=nameself.address=addressself.post("readAll",1)self.post("readDiagnostic",0)self.post("rfoutput",0)@propertydefurl(self):returnf"http://{self.address}/"defpost(self,name,value):"""Post a value to the instrument's web server. Try to post multiple times, waiting for 0.1 seconds between each attempt. Args: name: str = The name of the value to post. value: str = The value to post. """value=str(value)for_inrange(RECONNECTION_ATTEMPTS):try:response=requests.post(self.url,data={name:value},timeout=TIMEOUT)ifresponse.status_code==200:returnTruebreakexcept(ConnectionError,TimeoutError,requests.exceptions.ReadTimeout):log.info("ERAsynth connection timed out, retrying...")raiseConnectionError(f"Unable to post {name}={value} to {self.name}")defget(self,name):"""Get a value from the instrument's web server. Try to get multiple times, waiting for 0.1 seconds between each attempt. Args: name: str = The name of the value to get. """ifname=="ref_osc_source":value=self.get("reference_int_ext")ifvalue==1:return"EXT"else:return"INT"for_inrange(RECONNECTION_ATTEMPTS):try:response=requests.post(self.url,params={"readAll":1},timeout=TIMEOUT)ifresponse.status_code==200:# reponse.text is a dictonary in string format, convert it to a dictonaryreturnjson.loads(response.text)[name]breakexcept(ConnectionError,TimeoutError,requests.exceptions.ReadTimeout):log.info("ERAsynth connection timed out, retrying...")raiseConnectionError(f"Unable to get {name} from {self.name}")defset(self,name,value):"""Set a value to the instrument's web server. Args: name (str): Name of the paramater that we are updating. In qibolab this can be ``frequency``, ``power`` or ``ref_osc_source``, however the instrument's web server may support more values. value: New value to set to the given parameter. The type of value depends on the parameter being updated. """ifname=="ref_osc_source":ifvalue.lower()in("int","internal"):self.post("reference_int_ext",0)elifvalue.lower()in("ext","external"):self.post("reference_int_ext",1)else:raiseValueError(f"Invalid reference clock source {value}")elifname=="frequency":self.post(name,int(value))elifname=="power":self.post(name,float(value))else:self.post(name,value)defon(self):self.post("rfoutput",1)defoff(self):self.post("rfoutput",0)defclose(self):self.off()
[docs]classERASynth(LocalOscillator):"""Driver to control the ERAsynth++ local oscillator. This driver is using: https://qcodes.github.io/Qcodes_contrib_drivers/api/generated/qcodes_contrib_drivers.drivers.ERAInstruments.html#qcodes_contrib_drivers.drivers.ERAInstruments.erasynth.ERASynthPlusPlus or the custom :class:`qibolab.instruments.erasynth.ERASynthEthernet` object if we are connected via ethernet. """def__init__(self,address,ethernet=True,ref_osc_source=None):super().__init__(address=address,settings=LocalOscillatorSettings(ref_osc_source=ref_osc_source),)self.ethernet=ethernet