研究型实验 ============== 量子计算的开放实验 物理层实验 ~~~~~~~~~~~~~ .. code-block:: python from spinqlablink import SpinQLabLink, ExperimentType, Pulse, Gradient from spinqlablink import print_graph # Constants for Pauli component measurement steps # These represent different measurement configurations for Pauli operators XI_XZ_YI_YZ = 1 # X⊗I, X⊗Z, Y⊗I, Y⊗Z measurements XI_XX_YI_YX = 2 # X⊗I, X⊗X, Y⊗I, Y⊗X measurements XI_XY_YI_YX = 3 # X⊗I, X⊗Y, Y⊗I, Y⊗X measurements ZI_ZZ_YI_YZ = 4 # Z⊗I, Z⊗Z, Y⊗I, Y⊗Z measurements IX_ZX_IY_ZY = 5 # I⊗X, Z⊗X, I⊗Y, Z⊗Y measurements IZ_ZZ_IY_ZY = 6 # I⊗Z, Z⊗Z, I⊗Y, Z⊗Y measurements # Experiment type constants CUSTOMIZED_MEASUREMENT = 0 # User-defined custom measurement PAULI_COMPONENT_MEASUREMENT = 1 # Measurement of Pauli components QUANTUM_STATE_TOMOGRAPHY = 2 # Full quantum state tomography def main(): # Create connection spinqlablink = SpinQLabLink("192.168.15.4", 8181, "anyword", "anyword") spinqlablink.connect() if not spinqlablink.wait_for_login(): print("Login failed") return exp_physical_layer, exp_physical_layer_para = spinqlablink.register_experiment(ExperimentType.PHYSICAL_LAYER_EXPERIMENT) # Set other parameters exp_type = CUSTOMIZED_MEASUREMENT # CUSTOMIZED_MEASUREMENT = 0, PAULI_COMPONENT_MEASUREMENT = 1, QUANTUM_STATE_TOMOGRAPHY = 2 exp_physical_layer_para.type_setting = exp_type # which type of experiment to run exp_physical_layer_para.pulses = [Pulse(path=0, amplitude=100, phase=90, width=40)] # pulse sequence exp_physical_layer_para.gradients = [] # gradient sequence exp_physical_layer_para.relaxation_delay = 15 # relaxation delay(S) exp_physical_layer_para.h_freShift = 0 # hydrogen frequency shift(Hz) exp_physical_layer_para.p_freShift = 0 # phosphorus frequency shift(Hz) exp_physical_layer_para.h_freDemo = 0 # hydrogen frequency demo(Hz) exp_physical_layer_para.p_freDemo = 0 # phosphorus frequency demo(Hz) if exp_type == CUSTOMIZED_MEASUREMENT: exp_physical_layer_para.state_initialization = True # whether to initialize the state exp_physical_layer_para.sampleFre = 10000 # sample frequency(Hz) exp_physical_layer_para.sampleCount = 16000 # sample count exp_physical_layer_para.sampleDelay = 0 # sample delay(us) exp_physical_layer_para.samplePath = 0 # sample path 0:hydrogen, 1:phosphorus elif exp_type == PAULI_COMPONENT_MEASUREMENT: exp_physical_layer_para.stepList = [XI_XZ_YI_YZ, XI_XX_YI_YX, XI_XY_YI_YX, ZI_ZZ_YI_YZ, IX_ZX_IY_ZY, IZ_ZZ_IY_ZY] # step list elif exp_type == QUANTUM_STATE_TOMOGRAPHY: exp_physical_layer_para.samplePath = -1 # sample path 0:hydrogen, 1:phosphorus, -1:both spinqlablink.run_experiment() print("Waiting for experiment completion") spinqlablink.wait_for_experiment_completion() exp_info = spinqlablink.get_experiment_result() spinqlablink.deregister_experiment() spinqlablink.disconnect() if "result" in exp_info: exp_result = exp_info["result"] for key, value in exp_result.items(): if key != "graph": print(f"{key}: {value}") print_graph(exp_info["result"]) else: print("Experiment failed") if __name__ == "__main__": main() 实验参数解析 ^^^^^^^^^^^^ - **ExperimentType**: 实验类型,选择PHYSICAL_LAYER_EXPERIMENT,设置实验类型(详情参阅 :class:`spinqlablink.ExperimentType` 类) - **type_setting**: 实验类型,选择PAULI_COMPONENT_MEASUREMENT - **CUSTOMIZED_MEASUREMENT = 0**: 用户自定义测量 - **PAULI_COMPONENT_MEASUREMENT = 1**: 泡利分量测量 - **QUANTUM_STATE_TOMOGRAPHY = 2**: 量子态层析重构 - **stepList**: 步骤列表,用于泡利分量测量 - **XI_XZ_YI_YZ**: X⊗I, X⊗Z, Y⊗I, Y⊗Z测量 - **XI_XX_YI_YX**: X⊗I, X⊗X, Y⊗I, Y⊗X测量 - **XI_XY_YI_YX**: X⊗I, X⊗Y, Y⊗I, Y⊗X测量 - **ZI_ZZ_YI_YZ**: Z⊗I, Z⊗Z, Y⊗I, Y⊗Z测量 - **IX_ZX_IY_ZY**: I⊗X, Z⊗X, I⊗Y, Z⊗Y测量 - **IZ_ZZ_IY_ZY**: I⊗Z, Z⊗Z, I⊗Y, Z⊗Y测量 - **Pulse**: 定义脉冲序列,设置脉冲的路径、宽度、振幅、相位和频率偏移(详情参阅 :class:`spinqlablink.Pulse` 类) - **samplePath**: 采样路径,-1=双通道, 0=氢通道,1=磷通道 [-1,0,1] - **sampleCount**: 采样点数 [4000-16000] - **sampleFre**: 采样频率 [10000-100000] - **sampleDelay**: 采样延迟(us) [0-20000000] - **relaxation_delay**: 弛豫延迟(s) [0-20000000] - **h_freShift**: 氢频率偏移(hz) [0-10000] - **h_freDemo**: 氢频率解调(hz) [0-10000] - **p_freShift**: 磷频率偏移(hz) [0-10000] - **p_freDemo**: 磷频率解调(hz) [0-10000] 实验结果解析 ^^^^^^^^^^^^ .. code-block:: { "result":{ "graph":[ { # step 0 "fidRe": [[x,y],...], "fidIm":[[x,y],...], "fftRe":[[x,y],...], "fftIm":[[x,y],...], "lorenz":[[x,y],...], "fftRe":[[x,y],...], "fftIm":[[x,y],...], "fftMod":[[x,y],...], "fidMod":[[x,y],...], "fftFit":[[x,y],...] }, { # step 1}, ... ], "pauli_matrix":{ "II":0.2, "IX":0.3, "IY":0.4, ... "XX":0.5 }, "matrix":{ "real":[0.1,0.2,...], "imag":[0.1,0.2,...], }, "probability":[0.1,0.2,0.3,0.4] } } - **graph**: 图表数据,包含实部和虚部,graph中包含1-6个step - **pauli_matrix**: 泡利矩阵 - **I/X/Y/Z**: 16个泡利矩阵系数 - **matrix**: 矩阵数据 - **real**: 实部数据 - **imag**: 虚部数据 - **probability**: 概率数据 线路层实验 ~~~~~~~~~~~~~ .. code-block:: python from spinqlablink import SpinQLabLink, ExperimentType, Pulse, Gradient, Gate, CustomGate, Circuit from spinqlablink import print_graph def main(): # Create connection spinqlablink = SpinQLabLink("192.168.15.4", 8181, "anyword", "anyword") spinqlablink.connect() if not spinqlablink.wait_for_login(): print("Login failed") return exp_circuit_layer, exp_circuit_layer_para = spinqlablink.register_experiment(ExperimentType.CIRCUIT_LAYER_EXPERIMENT) using_pulse = True if using_pulse: exp_circuit_layer_para.pulses = [Pulse(path=0, phase=90, amplitude=100, width=40)] else: circuit = Circuit(2) circuit << Gate(type='H', qubitIndex=0) circuit << CustomGate(type='H',customType='H1_custom_gate',qubitIndex=1,pulses=[Pulse(path=1,phase=90,amplitude=100,width=40)]) circuit.print_circuit() exp_circuit_layer_para.set_circuit(circuit) # Set other parameters exp_circuit_layer_para.using_pulse = using_pulse # True: using pulse to testing gate, False: using circuit to get result exp_circuit_layer_para.gradients = [Gradient(delay=0,value=0)] # gradient sequence exp_circuit_layer_para.relaxation_delay = 15 #S exp_circuit_layer_para.h_freShift = 0 # hydrogen frequency shift(Hz) exp_circuit_layer_para.p_freShift = 0 # phosphorus frequency shift(Hz) exp_circuit_layer_para.h_freDemo = 0 # hydrogen frequency demo(Hz) exp_circuit_layer_para.p_freDemo = 0 # phosphorus frequency demo(Hz) exp_circuit_layer_para.sampleFre = 10000 # sample frequency(Hz) exp_circuit_layer_para.sampleCount = 16000 # sample count exp_circuit_layer_para.sampleDelay = 0 # sample delay(us) exp_circuit_layer_para.samplePath = -1 # Sampling path: 0=Hydrogen channel, 1=Phosphorus channel, -1=both channels spinqlablink.run_experiment() print("Waiting for experiment completion") spinqlablink.wait_for_experiment_completion() exp_info = spinqlablink.get_experiment_result() spinqlablink.deregister_experiment() spinqlablink.disconnect() if "result" in exp_info: exp_result = exp_info["result"] for key, value in exp_result.items(): if key != "graph": print(f"{key}: {value}") print_graph(exp_info["result"]) else: print("Experiment failed") if __name__ == "__main__": main() 实验参数解析 ^^^^^^^^^^^^ - **ExperimentType**: 实验类型,选择CIRCUIT_LAYER_EXPERIMENT,设置实验类型(详情参阅 :class:`spinqlablink.ExperimentType` 类) - **using_pulse**: 使用脉冲序列,True: 使用脉冲序列, False: 使用量子线路 [True,False] - **gradients**: 梯度序列,用于梯度测量(详情参阅 :class:`spinqlablink.Gradient` 类) - **Pulse**: 定义脉冲序列,设置脉冲的路径、宽度、振幅、相位和频率偏移(详情参阅 :class:`spinqlablink.Pulse` 类) - **Circuit**: 定义量子线路,设置量子线路的门和量子比特(详情参阅 :class:`spinqlablink.Circuit` 类) - **samplePath**: 采样路径,-1=双通道, 0=氢通道,1=磷通道 [-1,0,1] - **sampleCount**: 采样点数 [4000-16000] - **sampleFre**: 采样频率 [10000-100000] - **sampleDelay**: 采样延迟(us) [0-20000000] - **relaxation_delay**: 弛豫延迟(s) [0-20000000] - **h_freShift**: 氢频率偏移(hz) [0-10000] - **h_freDemo**: 氢频率解调(hz) [0-10000] - **p_freShift**: 磷频率偏移(hz) [0-10000] - **p_freDemo**: 磷频率解调(hz) [0-10000] 实验结果解析 ^^^^^^^^^^^^ .. code-block:: { "result":{ "graph":[ { # step 0 "fidRe": [[x,y],...], "fidIm":[[x,y],...], "fftRe":[[x,y],...], "fftIm":[[x,y],...], "lorenz":[[x,y],...], "fftRe":[[x,y],...], "fftIm":[[x,y],...], "fftMod":[[x,y],...], "fidMod":[[x,y],...], "fftFit":[[x,y],...] }, { # step 1}, ... ], "fidelity": 0.99, "gateNums": 2, "hFre_offset": 0, "pFre_offset": 0, "pulseControlTime": 1000, "pureTime": 1000, "purity": 0.99, "relaxtion": 15, "sampleTime": 1000, "smt": 6, "matrix": { "real":[0.1,0.2,...], "imag":[0.1,0.2,...], }, "probability":[0.1,0.2,0.3,0.4] } } - **graph**: 图表数据,包含实部和虚部,graph中包含2/6个step - **matrix**: 矩阵数据 - **real**: 实部数据 - **imag**: 虚部数据 - **probability**: 概率数据 - **fidelity**: 保真度 - **gateNums**: 门总数 - **hFre_offset**: 氢频率偏移(hz) - **pFre_offset**: 磷频率偏移(hz) - **pulseControlTime**: 脉冲控制时间(us) - **pureTime**: 赝纯态时间(us) - **purity**: 纯度(%) - **relaxtion**: 弛豫时间(us) - **sampleTime**: 采样时间(us) - **smt**: 系统综合测量次数