def fetchRecentDelay(self): worker = IFWorker('tcp://192.168.25.27:224') last = None while True: latest = worker.Storage.latest( 'MDIQKD_GroundTDC', after=last, filter={ 'FetchTime': 1, 'Data.MDIQKDEncoding.Configuration.Period': 1, 'Data.MDIQKDEncoding.Histogram Alice Time': 1, 'Data.MDIQKDEncoding.Histogram Bob Time': 1, }) if latest == None: continue else: last = latest['FetchTime'] period = latest['Data']['MDIQKDEncoding']['Configuration'][ 'Period'] aliceYs = latest['Data']['MDIQKDEncoding'][ 'Histogram Alice Time'] bobYs = latest['Data']['MDIQKDEncoding']['Histogram Bob Time'] xs = list(np.arange(0, period, period / len(aliceYs))) if max(aliceYs) < 50.0: aliceRise = "noSignal" else: aliceRise = self.riseTimeFit(xs, aliceYs) / 1000 if max(bobYs) < 50.0: # 无信号脉冲时 bobRise = "noSignal" # worker.Algorithm_Fitting.riseTimeFit(xs, bobYs) else: bobRise = self.riseTimeFit(xs, bobYs) / 1000 yield aliceRise, bobRise
def turnOffAllChannels(self): for awg in self.awgs: awg.beginSession() awg.turnOffAllChannels() awg.endSession() def writeWaveform(self, channel, wave): mappedChannel = self.channelMapping[channel] self.awgs[mappedChannel[0]].beginSession() self.awgs[mappedChannel[0]].writeWaveform(mappedChannel[1], [(2 * v - 1) * 32765 for v in wave]) self.awgs[mappedChannel[0]].endSession() def sendTrigger(self, awgIndex, interval1, count1, interval2, count2): dev = self.awgs[awgIndex] dev.beginSession() dev.sendTrigger(interval1, count1, interval2, count2) dev.endSession() if __name__ == '__main__': from interactionfreepy import IFWorker from interactionfreepy import IFLoop awg = USTCDACServer('192.168.25.237', sessionPermenent=True) IFWorker('tcp://192.168.25.5:224', 'USTCAWG_237', awg) IFLoop.join()
outputFile.write( msgpack.packb({ 'Summaries': summuries, 'Contents': memfile.getvalue() })) memfile.close() outputFile.close() def debug_info(level, msg): pass # print('[{}] {}'.format(level, msg)) if __name__ == '__main__': print(datetime.now(pytz.timezone('Asia/Shanghai')).isoformat()) worker = IFWorker("tcp://172.16.60.199:224", 'MDIQKD_ResultFiltering', timeout=10) reviewer = RealtimeReviewer( worker, 'MDIQKD_GroundTDC', 'MDI_ADCMonitor', 'MDIQKD_DataReviewer', datetime.now(pytz.timezone('Asia/Shanghai')).isoformat(), [[0, -0.4, 4.5], [1, -0.4, 4.5]]) #2020.8.21 # reviewer = RealtimeReviewer(worker, 'MDIQKD_GroundTDC', 'MDI_ADCMonitor', 'MDIQKD_DataReviewer', '2020-01-01T00:00:00+08:00', [[0, -0.4, 4.5], [1, -0.4, 4.5]]) #2020.8.22 reviewer.start() # worker = IFWorker("tcp://127.0.0.1:224") # reviewer = Reviewer(worker, 'MDIQKD_GroundTDC', 'MDI_ADCMonitor', 'MDIQKD_DataReviewer', '2020-08-01T01:29:30+08:00', '2020-08-01T01:36:30+08:00') # reviewer.deleteExists() # reviewer.review()
# else: # raise RuntimeError('Channel {} not exists.'.format(name)) # # async def startTrigger(self): # awg = self.awgs[0] # await awg.beginSession() # await awg.sendTrigger(1e-3, 60000, 1e-3, 60000) # await awg.endSession() # print('Trigger started.') if __name__ == '__main__': from interactionfreepy import IFWorker from interactionfreepy import IFLoop workerAlice = IFWorker('tcp://172.16.60.199:224') workerBob = IFWorker('tcp://172.16.60.199:224') devAlice = AWGEncoder(workerAlice, '_USTCAWG_Alice', { 'AMDecoy': 2, 'AMTime1': 4, 'AMTime2': 6, 'PM': 1, 'PR': 0 }) # devBob = AWGEncoder(workerBob, 'USTCAWG_Bob', {'AMDecoy': 2, 'AMTime1': 4, 'AMTime2': 6, 'PM': 1, 'PR': 0}) # workerAlice.bindService('MDIQKD_AWGEncoder_Alice_', devAlice) # workerBob.bindService('MDIQKD_AWGEncoder_Bob', devBob) import asyncio asyncio.get_event_loop().run_until_complete(devAlice.generateNewWaveform())
fig.set_size_inches(18, 10) for i in range(len(waveforms.keys())): axs[i].plot(times, waveforms[list(waveforms.keys())[i]]) axs[i].grid() plt.show() if __name__ == '__main__': from interactionfreepy import IFBroker, IFWorker, IFLoop import time import sys from tornado.ioloop import IOLoop from random import Random worker = IFWorker('tcp://192.168.25.5:224') dev = AWGEncoder(worker.asyncInvoker("USTCAWG_237"), { 'AMRef': 1, 'AMDecoy': 2, 'PM1': 3, 'PM2': 4 }) worker.bindService("AWGEncoder", dev) IFLoop.join() # rnd = Random() # dev = AWGEncoder(None, {'AMRef': 1, 'AMDecoy': 2, 'PM1': 3, 'PM2': 4}) # broker = IFBroker('tcp://*:2224') # worker = IFWorker('tcp://localhost:2224', 'AWGEncoder', dev) remoteDev = worker.AWGEncoder # remoteDev = dev
def setADCMonitorChannel(self, mode): worker = IFWorker("tcp://172.16.60.199:224") if mode[:2] == 'AB': worker.MDI_ADCMonitor.configStorage(0, 1) if mode[:2] == 'AD': worker.MDI_ADCMonitor.configStorage(0, -1) if mode[:2] == 'BD': worker.MDI_ADCMonitor.configStorage(1, -1)
def deviceConnected(self): return len(self.devices.keys()) > 0 def newDevice(self, request): self.devices[request] = request def deleteDevice(self, request): del self.devices[request] if __name__ == '__main__': import time from interactionfreepy import IFWorker dev = HMC7044Eval() worker = IFWorker('tcp://172.16.60.200:224', 'HMC7044EvalTest', dev) class EchoHandler(BaseRequestHandler): def handle(self): print('Got connection from', self.client_address) dev.newDevice(self.request) try: while True: msg = self.request.recv(8192) finally: dev.deleteDevice(self.request) serv = TCPServer(('', 25001), EchoHandler) serv.serve_forever()
import time, socket, sys, threading, math, random import numpy as np import matplotlib.pyplot as plt from math import isnan from random import Random exitHooks = [] from interactionfreepy import IFWorker worker = IFWorker("tcp://172.16.60.199:224") sys.path.append('D:\\GitHub\\Hydra\\Pydra') import Pydra class ExperimentControl: def __init__(self): self.session = Pydra.Session.newSession(('172.16.60.199', 20102), None, 'MDI-QKD-Controller-Test') self.currentTDCReportSize = -1 self.syncService = self.session.blockingInvoker( 'SyncService') # 获得对SyncService的引用 self.exchanged = False def TDCServer_ini(self, mode, FPM=False): tdcserver = worker.MDIQKD_GroundTDC tdcserver.turnOnAnalyser("Counter") if FPM: tdcserver.turnOnAnalyser( "MultiHistogram", { "Sync": 0,
# ratios = data[:, 1] # c1 = data[:, head.index(head1)] # c2 = data[:, head.index(head2)] # if mode == 'HOM': # y = c1 / (c2 + 1e-10) # elif mode == 'QBER': # y = c2 / (c1 + c2 + 1e-10) # else: # raise RuntimeError('Mode not valid.') # z = [z for z in zip(y, ratios)] # z.sort() # validZ = [zz for zz in z if zz[1] > 0.1 and zz[1] < 10][0] # return (validZ[1], validZ[0]) # # def __listValidResults(self): # files = [f for f in os.listdir(self.dir) if f.lower().endswith('.png')] # files.sort() # dirs = ['{}/{}'.format(self.dir, file[:15]) for file in files] # return dirs if __name__ == '__main__': print('HOM and QBER summary') # worker = IFWorker('tcp://172.16.60.199:224') worker = IFWorker('tcp://127.0.0.1:224') # shower = Shower(worker, 'MDI_DataReviewer_10k100M', '2020-03-12 11:04:05', '2020-06-12 22:04:05') # shower = Shower(worker, 'MDIQKD_DataReviewer_ReProcess_4', '2020-07-25T15:38:00+08:00', '2020-07-25T15:40:00+08:00') shower = Shower(worker, 'MDIQKD_DataReviewer', '2020-08-14T15:48:15+08:00', '2020-08-14T15:50:15+08:00') shower.show() worker.close()
if __name__ == '__main__': print('Net Speed Test') t = time.time() lengths = [] times = [] class NST: def __init__(self): pass def test(self, data): return time.time() - t worker1 = IFWorker('tcp://172.16.60.200:224', '__NetSpeedTest', NST(), force=True) worker2 = IFWorker('tcp://172.16.60.200:224') rnd = Random() for l in np.logspace(3, 7, 10): print(l) l = int(l) bs = ''.join(['0' for i in range(l)]) bs = bytearray(bs, 'UTF-8') t = time.time() lengths.append(l) times.append(worker2.__NetSpeedTest.test(bs)) plt.plot(lengths, times)
return results if __name__ == '__main__': stations = [ ['Ali', 'AL', 80.026, 32.325, 0], ['Delingha', 'DLH', 97.727, 37.379, 0], ['Nanshan', 'NS', 87.177, 43.475, 0], ['Beijing', 'BJ', 116.274, 40.047, 0], ['Lijiang', 'LJ', 100.029, 26.694, 0], ['Shanghai', 'SH', 121.542, 31.126, 0], ['Weihai', 'WeiH', 122.051, 37.534, 0], # ['Wuhan', 'WuH', 114.410, 30.430, 0], # ['Dalian', 'DL', 121.618, 38.932, 0], ['Russia (Beijing Time)', 'RUS', 37.596, 55.711, 4], ['Xiamen', 'XM', 118.1, 24.5, 0], ['Fuzhou', 'FZ', 119.3, 26.1, 0], ['Qingdao', 'QD', 120.3, 36.1, 0], ['Changchun', 'CC', 125.4, 43.9, 0], ['Jinan', 'JN', 117.000, 36.400, 0], ] worker = IFWorker('tcp://172.16.60.200:224') storage = worker.Storage while True: results = WeatherFetcher.fetchAll(stations) worker.Storage.append( 'Weathers', results, datetime.now(pytz.timezone('Asia/Shanghai')).isoformat()) time.sleep(3600 * 4)
dataFile.write('{}\n'.format(', '.join([str(i) for i in (data['bobMius'] + data['bobPs'])]))) dataFile.write('{}\n'.format(', '.join([str(i) for i in [ 0, int(data['ValidTime'] * repeRate) * C, int(data['XX Correct']) * C, int(data['XX Wrong']) * C, int(data['YY Count']) * C, int(data['XO Count']) * C, int(data['OX Count']) * C, int(data['YO Count']) * C, int(data['OY Count']) * C, int(data['OO Count']) * C, int(data['ZZ Correct']) * C, int(data['ZZ Wrong']) * C, ]]))) dataFile.close() p = subprocess.Popen('{}{}'.format(self.root, self.exe), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() os.remove('{}DATA_FILE.csv'.format(self.root)) result = str(stdout, 'GB2312') retults = result.split('\n') for r in retults: if r.startswith('Line 0'): print(r) return float(r.split(',')[1][3:]) * repeRate return 0 IFWorker('tcp://172.16.60.199:224', 'MDI-QKD KeyRate', KeyRate('MDI-freespace-data_process_failure_1e-7.exe')) IFWorker('tcp://172.16.60.199:224', 'MDI-QKD KeyRate 20201016', KeyRate('MDI-freespace-data_process_failure_1e-7_20201016.exe')) IFLoop.join()
from interactionfreepy import IFWorker, IFLoop class ConfigurationManager: def __init__(self, worker): self.worker = worker async def test(self): print('hahaha') self.worker.TFTDCServer. if __name__ == '__main__': worker1 = IFWorker('tcp://172.16.60.200:224') cm = ConfigurationManager(worker1) worker2 = IFWorker('tcp://172.16.60.200:224', 'TF_ConfigurationManager', cm, force=True) worker2.TF_ConfigurationManager.test() # IFLoop.join() # worker1.TF_ClockManager.delay(alice=0.1)