qubitclient 0.0.0.1__py3-none-any.whl → 0.0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of qubitclient might be problematic. Click here for more details.

Files changed (53) hide show
  1. qubitclient/__init__.py +6 -1
  2. qubitclient/nnscope/nnscope.py +51 -0
  3. qubitclient/{QubitSeg.py → nnscope/nnscope_api/QubitSeg.py} +7 -7
  4. qubitclient/nnscope/nnscope_api/curve/__init__.py +0 -0
  5. qubitclient/nnscope/nnscope_api/curve/curve_type.py +15 -0
  6. qubitclient/nnscope/task.py +130 -0
  7. qubitclient/nnscope/utils/data_convert.py +114 -0
  8. qubitclient/nnscope/utils/data_parser.py +41 -0
  9. qubitclient/nnscope/utils/request_tool.py +41 -0
  10. qubitclient/nnscope/utils/result_parser.py +55 -0
  11. qubitclient/scope/scope.py +51 -0
  12. qubitclient/scope/scope_api/__init__.py +8 -0
  13. qubitclient/scope/scope_api/api/__init__.py +1 -0
  14. qubitclient/scope/scope_api/api/defined_tasks/__init__.py +1 -0
  15. qubitclient/scope/scope_api/api/defined_tasks/get_task_result_api_v1_tasks_demo_pk_get.py +155 -0
  16. qubitclient/scope/scope_api/api/defined_tasks/get_task_result_api_v1_tasks_scope_pk_get.py +155 -0
  17. qubitclient/scope/scope_api/api/defined_tasks/optpipulse_api_v1_tasks_scope_optpipulse_post.py +218 -0
  18. qubitclient/scope/scope_api/api/defined_tasks/rabi_api_v1_tasks_scope_rabi_post.py +218 -0
  19. qubitclient/scope/scope_api/api/defined_tasks/rabicos_api_v1_tasks_scope_rabicospeak_post.py +218 -0
  20. qubitclient/scope/scope_api/api/defined_tasks/s21peak_api_v1_tasks_scope_s21peak_post.py +218 -0
  21. qubitclient/scope/scope_api/api/defined_tasks/s21vflux_api_v1_tasks_scope_s21vflux_post.py +218 -0
  22. qubitclient/scope/scope_api/api/defined_tasks/singleshot_api_v1_tasks_scope_singleshot_post.py +218 -0
  23. qubitclient/scope/scope_api/api/defined_tasks/spectrum2d_api_v1_tasks_scope_spectrum2d_post.py +218 -0
  24. qubitclient/scope/scope_api/api/defined_tasks/spectrum_api_v1_tasks_scope_spectrum_post.py +218 -0
  25. qubitclient/scope/scope_api/api/defined_tasks/t1fit_api_v1_tasks_scope_t1fit_post.py +218 -0
  26. qubitclient/scope/scope_api/api/defined_tasks/t1fit_api_v1_tasks_scope_t2fit_post.py +218 -0
  27. qubitclient/scope/scope_api/client.py +268 -0
  28. qubitclient/scope/scope_api/errors.py +16 -0
  29. qubitclient/scope/scope_api/models/__init__.py +29 -0
  30. qubitclient/scope/scope_api/models/body_optpipulse_api_v1_tasks_scope_optpipulse_post.py +83 -0
  31. qubitclient/scope/scope_api/models/body_rabi_api_v1_tasks_scope_rabi_post.py +83 -0
  32. qubitclient/scope/scope_api/models/body_rabicos_api_v1_tasks_scope_rabicospeak_post.py +83 -0
  33. qubitclient/scope/scope_api/models/body_s21_peak_api_v1_tasks_scope_s21_peak_post.py +83 -0
  34. qubitclient/scope/scope_api/models/body_s21_vflux_api_v1_tasks_scope_s21_vflux_post.py +83 -0
  35. qubitclient/scope/scope_api/models/body_singleshot_api_v1_tasks_scope_singleshot_post.py +83 -0
  36. qubitclient/scope/scope_api/models/body_spectrum_2d_api_v1_tasks_scope_spectrum_2d_post.py +83 -0
  37. qubitclient/scope/scope_api/models/body_spectrum_api_v1_tasks_scope_spectrum_post.py +83 -0
  38. qubitclient/scope/scope_api/models/body_t1_fit_api_v1_tasks_scope_t1_fit_post.py +83 -0
  39. qubitclient/scope/scope_api/models/body_t1_fit_api_v1_tasks_scope_t2_fit_post.py +83 -0
  40. qubitclient/scope/scope_api/models/http_validation_error.py +75 -0
  41. qubitclient/scope/scope_api/models/validation_error.py +88 -0
  42. qubitclient/scope/scope_api/types.py +54 -0
  43. qubitclient/scope/task.py +147 -0
  44. qubitclient/scope/utils/__init__.py +0 -0
  45. qubitclient/scope/utils/data_parser.py +20 -0
  46. qubitclient-0.0.3.0.dist-info/METADATA +112 -0
  47. qubitclient-0.0.3.0.dist-info/RECORD +51 -0
  48. qubitclient-0.0.0.1.dist-info/METADATA +0 -35
  49. qubitclient-0.0.0.1.dist-info/RECORD +0 -8
  50. {qubitclient-0.0.0.1.dist-info → qubitclient-0.0.3.0.dist-info}/WHEEL +0 -0
  51. {qubitclient-0.0.0.1.dist-info → qubitclient-0.0.3.0.dist-info}/licenses/LICENSE +0 -0
  52. {qubitclient-0.0.0.1.dist-info → qubitclient-0.0.3.0.dist-info}/top_level.txt +0 -0
  53. {qubitclient-0.0.0.1.dist-info → qubitclient-0.0.3.0.dist-info}/zip-safe +0 -0
qubitclient/__init__.py CHANGED
@@ -1 +1,6 @@
1
- from .curve.curve_type import CurveType # noqa: F401
1
+ from .nnscope.nnscope_api.curve.curve_type import CurveType # noqa: F401
2
+ from .scope.scope import QubitScopeClient
3
+ from .nnscope.nnscope import QubitNNScopeClient
4
+ from .scope.task import TaskName
5
+ from .nnscope.task import NNTaskName
6
+ from .nnscope.nnscope_api.QubitSeg import QubitSegClient
@@ -0,0 +1,51 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (c) 2025 yaqiang.sun.
3
+ # This source code is licensed under the license found in the LICENSE file
4
+ # in the root directory of this source tree.
5
+ #########################################################################
6
+ # Author: yaqiangsun
7
+ # Created Time: 2025/10/20 18:13:37
8
+ ########################################################################
9
+
10
+
11
+ import os
12
+ # import cv2
13
+ import numpy as np
14
+ import sys
15
+ # 获取当前文件的绝对路径,向上两层就是项目根目录
16
+ project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
17
+ if project_root not in sys.path:
18
+ sys.path.insert(0, project_root)
19
+ #
20
+ # `scope_api_client`: this package is generated by `openapi-python-client`
21
+
22
+ from .task import run_task
23
+ import logging
24
+ import numpy as np
25
+
26
+
27
+
28
+ logging.basicConfig(level=logging.INFO)
29
+
30
+
31
+ class QubitNNScopeClient(object):
32
+ def __init__(self, url, api_key):
33
+ self.url = url
34
+ self.api_key = api_key
35
+
36
+ def request(self, file_list:list[str|dict[str,np.ndarray]|np.ndarray],task_type:str="s21peak",*args,**kwargs):
37
+ if len(file_list)>0:
38
+ response = run_task(file_list=file_list,url=self.url,api_key=self.api_key,task_type=task_type,*args,**kwargs)
39
+ else:
40
+ raise ValueError("file_list must not be empty")
41
+ return response
42
+ def get_result(self,response):
43
+ if response.status_code == 200:
44
+ logging.info("Result: %s", response.json())
45
+ result = response.json()
46
+ result = result["result"]
47
+ return result
48
+ else:
49
+ logging.error("Error: %s %s", response.status_code, response.text)
50
+ return []
51
+
@@ -10,10 +10,10 @@
10
10
  import logging
11
11
  import numpy as np
12
12
 
13
- from qubitclient.utils.request_tool import file_request,file_request_with_dict
14
- from qubitclient.utils.result_parser import parser_result
15
- from qubitclient.utils.result_parser import convet_axis
16
- from qubitclient.curve.curve_type import CurveType
13
+ from qubitclient.nnscope.utils.request_tool import file_request,file_request_with_dict
14
+ from qubitclient.nnscope.utils.result_parser import parser_result
15
+ from qubitclient.nnscope.utils.result_parser import convet_axis
16
+ from .curve.curve_type import CurveType
17
17
 
18
18
 
19
19
  logging.basicConfig(level=logging.INFO)
@@ -23,13 +23,13 @@ class QubitSegClient(object):
23
23
  def __init__(self, url, api_key,curve_type:CurveType=None):
24
24
  self.url = url
25
25
  self.api_key = api_key
26
- self.confidence_type = curve_type
26
+ self.curve_type = curve_type
27
27
  def request(self, file_list:list[str|dict[str,np.ndarray]]):
28
28
  if len(file_list)>0:
29
29
  if type(file_list[0]) == str:
30
- response = file_request(file_path_list=file_list,url=self.url,api_key=self.api_key,curve_type=self.confidence_type)
30
+ response = file_request(file_path_list=file_list,url=self.url,api_key=self.api_key,curve_type=self.curve_type)
31
31
  elif type(file_list[0]) == dict:# 多个content字典
32
- response = file_request_with_dict(dict_list=file_list,url=self.url,api_key=self.api_key,curve_type=self.confidence_type)
32
+ response = file_request_with_dict(dict_list=file_list,url=self.url,api_key=self.api_key,curve_type=self.curve_type)
33
33
  else:
34
34
  raise ValueError("file_list must be a list of str or dict")
35
35
  else:
File without changes
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (c) 2025 yaqiang.sun.
3
+ # This source code is licensed under the license found in the LICENSE file
4
+ # in the root directory of this source tree.
5
+ #########################################################################
6
+ # Author: yaqiangsun
7
+ # Created Time: 2025/06/06 16:52:53
8
+ ########################################################################
9
+
10
+
11
+ from enum import Enum
12
+
13
+ class CurveType(str, Enum):
14
+ COSINE = "cosin"
15
+ POLY = "poly"
@@ -0,0 +1,130 @@
1
+
2
+ import os
3
+ import requests
4
+
5
+ import io
6
+ import numpy as np
7
+
8
+
9
+ from qubitclient.nnscope.utils.data_convert import convert_spectrum_npy2npz,convert_spectrum_dict2npz
10
+
11
+ # load from npz file path
12
+ def load_from_npz_path(file_path_list:list[str]):
13
+ files = []
14
+ npydata = {}
15
+ npydata['id'] = 0
16
+ image_qs = {}
17
+ index = 0
18
+ for file_path in file_path_list:
19
+ if file_path.endswith('.npz'):
20
+ index+=1
21
+ with np.load(file_path, allow_pickle=True) as data: # 修改:添加 allow_pickle=True 参数
22
+ # file_contents[file_name] = dict(data) # 将 .npz 文件内容转换为字典
23
+ content = dict(data) # 将 .npz 文件内容转换为字典
24
+ image_qs[str(index)] = (content['iq_avg'],content['bias'],content['frequency'])
25
+ npydata['image'] = image_qs
26
+ with io.BytesIO() as buffer:
27
+ np.savez(buffer, **npydata)
28
+ bytes_obj = buffer.getvalue()
29
+ files.append(("request", ("None.npz", bytes_obj, "application/octet-stream")))
30
+ return files
31
+ def load_from_npy_path(file_path_list:list[str]):
32
+ files = []
33
+ for file_path in file_path_list:
34
+ if file_path.endswith('.npy'):
35
+ data = np.load(file_path, allow_pickle=True)
36
+ data = data.item() if isinstance(data, np.ndarray) else data
37
+ with io.BytesIO() as buffer:
38
+ np.savez(buffer, **data)
39
+ bytes_obj = buffer.getvalue()
40
+ files.append(("request", ("None.npz", bytes_obj, "application/octet-stream")))
41
+ return files
42
+ def load_from_npz_dict(dict_list:list[dict]):
43
+ files = []
44
+ npydata = {}
45
+ npydata['id'] = 0
46
+ image_qs = {}
47
+ for index,dict_obj in enumerate(dict_list):
48
+ image_qs[str(index)] = (dict_obj['iq_avg'], dict_obj['bias'], dict_obj['frequency'])
49
+ npydata['image'] = image_qs
50
+ with io.BytesIO() as buffer:
51
+ np.savez(buffer, **npydata)
52
+ bytes_obj = buffer.getvalue()
53
+ files.append(("request", ("None.npz", bytes_obj, "application/octet-stream")))
54
+ return files
55
+ def load_from_npy_dict(dict_list:list[dict]):
56
+ files = []
57
+ for dict_obj in dict_list:
58
+ with io.BytesIO() as buffer:
59
+ np.savez(buffer, **dict_obj)
60
+ bytes_obj = buffer.getvalue()
61
+ files.append(("request", ("None.npz",bytes_obj, "application/octet-stream")))
62
+ return files
63
+ def request_task(files,url,api_key,curve_type:str=None):
64
+ headers = {'Authorization': f'Bearer {api_key}'} # 添加API密钥到请求头
65
+ data = {
66
+ "curve_type":curve_type.value if curve_type else None
67
+ }
68
+ response = requests.post(url, files=files, headers=headers,data=data)
69
+ return response
70
+ def load_files(filepath_list: list[str|dict[str,np.ndarray]|np.ndarray]):
71
+ if len(filepath_list)<=0:
72
+ return []
73
+ else:
74
+ if isinstance(filepath_list[0], dict):
75
+ if "image" in filepath_list[0]:
76
+ return load_from_npy_dict(filepath_list)
77
+ else:
78
+ return load_from_npz_dict(filepath_list)
79
+ elif isinstance(filepath_list[0], np.ndarray):
80
+ filepath_list = [filepath_list[i].item() for i in range(len(filepath_list))]
81
+ return load_files(filepath_list)
82
+ elif isinstance(filepath_list[0], str):
83
+ if filepath_list[0].endswith('.npz'):
84
+ return load_from_npz_path(filepath_list)
85
+ elif filepath_list[0].endswith('.npy'):
86
+ return load_from_npy_path(filepath_list)
87
+ else:
88
+ return []
89
+
90
+
91
+
92
+ DEFINED_TASKS = {}
93
+ def task_register(func):
94
+ DEFINED_TASKS[func.__name__.lower()] = func
95
+ return func
96
+
97
+ def run_task(file_list: list[str|dict[str,np.ndarray]|np.ndarray],url,api_key,task_type:str,*args,**kwargs):
98
+ files = load_files(file_list)
99
+ response = DEFINED_TASKS[task_type.value](files,url,api_key,*args,**kwargs)
100
+ return response
101
+
102
+
103
+ @task_register
104
+ def test(files):
105
+
106
+ return "hello"
107
+
108
+ @task_register
109
+ def spectrum2d(files,url,api_key,curve_type):
110
+ spectrum2d_url = url + "/seglines"
111
+ response = request_task(files,spectrum2d_url,api_key,curve_type)
112
+ return response
113
+
114
+ from enum import Enum, unique
115
+ @unique
116
+ class NNTaskName(Enum):
117
+ # S21PEAK = "s21peak"
118
+ # OPTPIPULSE = "optpipulse"
119
+ # RABI = "rabi"
120
+ # RABICOS = "rabicos"
121
+ # S21VFLUX = "s21vflux"
122
+ # SINGLESHOT = "singleshot"
123
+ # SPECTRUM = "spectrum"
124
+ # T1FIT = "t1fit"
125
+ # T2FIT = "t2fit"
126
+ SPECTRUM2D = "spectrum2d"
127
+
128
+
129
+
130
+
@@ -0,0 +1,114 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (c) 2025 yaqiang.sun.
3
+ # This source code is licensed under the license found in the LICENSE file
4
+ # in the root directory of this source tree.
5
+ #########################################################################
6
+ # Author: yaqiangsun
7
+ # Created Time: 2025/10/24 15:54:07
8
+ ########################################################################
9
+
10
+
11
+ import numpy as np
12
+ import io
13
+ import os
14
+ import numpy as np
15
+ import cv2
16
+
17
+
18
+ def load_npz_file(file_path):
19
+ with np.load(file_path, allow_pickle=True) as data: # 修改:添加 allow_pickle=True 参数
20
+ # file_contents[file_name] = dict(data) # 将 .npz 文件内容转换为字典
21
+ content = dict(data) # 将 .npz 文件内容转换为字典
22
+ return content
23
+ def convert_data_to_image(npz_content):
24
+ content = npz_content
25
+ iq_avg = content["iq_avg"] # 二维数据
26
+ iq_avg_normalized = convert_complex_map__to_image(iq_avg=iq_avg)
27
+ return iq_avg_normalized
28
+ def convert_complex_map__to_image(iq_avg):
29
+ # 检查并转置
30
+ rows, cols = iq_avg.shape
31
+ if rows < cols:
32
+ iq_avg = iq_avg.T # 转置矩阵
33
+
34
+
35
+ # 取相位
36
+ phase = np.angle(iq_avg)
37
+ phase_normalized = ((phase + np.pi) / (2 * np.pi)) * 255
38
+ # 纵向归一化
39
+ phase_mean = phase_normalized.mean(axis=0, keepdims=True) # 形状(1,30)
40
+ ppase_std = phase_normalized.std(axis=0, keepdims=True) # 形状(1,30)
41
+ phase_normalized = (phase_normalized - phase_mean) / (ppase_std+1e-8)
42
+ # phase_normalized = phase_normalized.astype(np.uint8)
43
+ # 全局归一化
44
+ phase_normalized = cv2.normalize(phase_normalized, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U)
45
+
46
+ # 取幅度
47
+ iq_avg = np.abs(iq_avg)
48
+
49
+ # iq_avg = phase_normalized
50
+ # 纵向归一化
51
+ # mean = iq_avg.mean(axis=0, keepdims=True) # 形状(1,30)
52
+ # std = iq_avg.std(axis=0, keepdims=True) # 形状(1,30)
53
+ # iq_avg = (iq_avg - mean) / (std+1e-8)
54
+ # 幅度全局归一化
55
+ iq_avg_normalized = cv2.normalize(iq_avg, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U)
56
+ # return iq_avg_normalized
57
+
58
+ #取幅度的梯度
59
+ gradient_y, gradient_x = np.gradient(iq_avg)
60
+ gradient_y = np.abs(gradient_y)
61
+ gradient_y_normalized = cv2.normalize(gradient_y, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U)
62
+
63
+ # iq_avg_normalized = cv2.merge([iq_avg_normalized, phase_normalized, gradient_y_normalized])
64
+ iq_avg_normalized = cv2.merge([iq_avg_normalized, iq_avg_normalized, iq_avg_normalized])
65
+ return iq_avg_normalized
66
+
67
+
68
+ def load_npz_to_image(file_path):
69
+ npz_content = load_npz_file(file_path)
70
+ image = convert_data_to_image(npz_content)
71
+ return image
72
+
73
+ def convert_spectrum_npy2npz(npy_file_path:str):
74
+ data = np.load(npy_file_path, allow_pickle=True)
75
+ data = data.item() if isinstance(data, np.ndarray) else data
76
+ dict_list, name_list = convert_spectrum_dict2npz(data,npy_file_path)
77
+ return dict_list, name_list
78
+ def convert_spectrum_dict2npz(data:dict,npy_file_path:str="None.npy"):
79
+ if not isinstance(data, dict) or 'image' not in data:
80
+ raise ValueError("数据格式无效,缺少 'image' 键")
81
+ image = data["image"]
82
+ q_list = image.keys()
83
+
84
+ dict_list = []
85
+ name_list = []
86
+
87
+ for idx, q_name in enumerate(q_list):
88
+ image_q = image[q_name]
89
+
90
+ data = image_q[0]
91
+ if data.ndim != 2:
92
+ raise ValueError("数据格式无效,data不是二维数组")
93
+ data = np.array(data)
94
+ data = np.abs(data)
95
+ height_axis = image_q[1]
96
+ width_axis = image_q[2]
97
+ new_dict = {}
98
+ new_dict["iq_avg"] = data
99
+ new_dict["frequency"] = image_q[2]
100
+ new_dict["bias"] = image_q[1]
101
+
102
+ npz_file_path = npy_file_path.replace(".npy", f"{q_name}.npz")
103
+ dict_list.append(new_dict)
104
+ name_list.append(npz_file_path)
105
+ # npz_file_path = npz_file_path.replace("npyfile","npyconverted")
106
+ # np.savez(npz_file_path,**new_dict)
107
+ # np.savez(npz_file_path,iq_avg=image_q[0],frequency=image_q[2],bias=image_q[1])
108
+ return dict_list, name_list
109
+
110
+ if __name__ == '__main__':
111
+ npy_file_path = "tmp/npyfile/tmp0ffc025b.py_4905.npy"
112
+ convert_spectrum_npy2npz(npy_file_path)
113
+
114
+ image = load_npz_to_image("tmp/npyconverted/tmp0ffc025b.py_4905Q6.npz")
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (c) 2025 yaqiang.sun.
3
+ # This source code is licensed under the license found in the LICENSE file
4
+ # in the root directory of this source tree.
5
+ #########################################################################
6
+ # Author: yaqiangsun
7
+ # Created Time: 2025/04/11 17:58:29
8
+ ########################################################################
9
+
10
+ import os
11
+ import numpy as np
12
+ import cv2
13
+
14
+
15
+ def load_npz_file(file_path):
16
+ with np.load(file_path, allow_pickle=True) as data:
17
+ content = dict(data)
18
+ return content
19
+ def convert_data_to_image(npz_content):
20
+ content = npz_content
21
+ iq_avg = content["iq_avg"]
22
+ rows, cols = iq_avg.shape
23
+ if rows < cols:
24
+ iq_avg = iq_avg.T
25
+ iq_avg = np.abs(iq_avg)
26
+ iq_avg_normalized = cv2.normalize(iq_avg, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U)
27
+ return iq_avg_normalized
28
+
29
+ def load_npz_to_image(file_path):
30
+ npz_content = load_npz_file(file_path)
31
+ image = convert_data_to_image(npz_content)
32
+ return image
33
+
34
+ def load_npz_to_images(file_path_list):
35
+ images = []
36
+ for file_path in file_path_list:
37
+ print(file_path)
38
+ image = load_npz_to_image(file_path)
39
+ images.append(image)
40
+ # cv2.imwrite("tmp/client/test.jpg",image)
41
+ return images
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (c) 2025 yaqiang.sun.
3
+ # This source code is licensed under the license found in the LICENSE file
4
+ # in the root directory of this source tree.
5
+ #########################################################################
6
+ # Author: yaqiangsun
7
+ # Created Time: 2025/04/15 10:31:23
8
+ ########################################################################
9
+ import os
10
+ import requests
11
+ import io
12
+ import numpy as np
13
+ from qubitclient.nnscope.nnscope_api.curve.curve_type import CurveType
14
+
15
+
16
+ def file_request(file_path_list,url,api_key,curve_type:CurveType=None):
17
+ files = []
18
+ for file_path in file_path_list:
19
+ if file_path.endswith('.npz'):
20
+ file_name = os.path.basename(file_path)
21
+ files.append(("request", (file_name, open(file_path, "rb"), "image/jpeg")))
22
+ headers = {'Authorization': f'Bearer {api_key}'} # 添加API密钥到请求头
23
+ data = {
24
+ "curve_type":curve_type.value if curve_type else None
25
+ }
26
+ response = requests.post(url, files=files, headers=headers,data=data)
27
+ return response
28
+
29
+ def file_request_with_dict(dict_list,url,api_key,curve_type:str=None):
30
+ files = []
31
+ for index,dict_obj in enumerate(dict_list):
32
+ with io.BytesIO() as buffer:
33
+ np.savez(buffer, **dict_obj)
34
+ bytes_obj = buffer.getvalue()
35
+ files.append(("request", ("None"+str(index)+".npz", bytes_obj, "application/octet-stream")))
36
+ headers = {'Authorization': f'Bearer {api_key}'} # 添加API密钥到请求头
37
+ data = {
38
+ "curve_type":curve_type.value if curve_type else None
39
+ }
40
+ response = requests.post(url, files=files, headers=headers,data=data)
41
+ return response
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (c) 2025 yaqiang.sun.
3
+ # This source code is licensed under the license found in the LICENSE file
4
+ # in the root directory of this source tree.
5
+ #########################################################################
6
+ # Author: yaqiangsun
7
+ # Created Time: 2025/04/15 10:23:27
8
+ ########################################################################
9
+
10
+ import math
11
+ import cv2
12
+
13
+ def parser_result(result, images):
14
+ result_images = []
15
+ for i in range(len(result)):
16
+ image = images[i]
17
+ if len(image.shape) == 2:
18
+ image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
19
+ # input_image_reshape = (512, 512)
20
+ input_image_reshape = (image.shape[1]*10,image.shape[0])
21
+ image = cv2.resize(image, input_image_reshape, interpolation=cv2.INTER_NEAREST)
22
+
23
+
24
+ image_result = result[i]
25
+ linepoints_list = image_result["linepoints_list"]
26
+ for linepoints in linepoints_list:
27
+ for j in range(len(linepoints) - 1):
28
+ cv2.line(image, tuple([int(linepoints[j][0]*10),int(linepoints[j][1])]), tuple([int(linepoints[j + 1][0]*10),int(linepoints[j + 1][1])]), (0, 255, 0), 2)
29
+
30
+ # cv2.imwrite(f"tmp/client/result_{i}.jpg", image)
31
+ result_images.append(image)
32
+ return result_images
33
+
34
+ def convet_axis(points,x_dim,y_dim):
35
+ reflection_points = []
36
+ for point in points:
37
+ x = point[0]
38
+ y = point[1]
39
+
40
+ x_grid_start = x_dim[int(x)]
41
+ x_grid_end = x_dim[min(int(x)+1,len(x_dim)-1)]
42
+ x_refletion = (x_grid_end-x_grid_start)* math.modf(x)[0] + x_grid_start
43
+
44
+
45
+ # y_index = min(max(0,int(y)),len(y_dim)-2)
46
+ y_index = int(y)
47
+ if y_index<0 or y_index>len(y_dim)-2:
48
+ continue
49
+ y_grid_start = y_dim[y_index]
50
+ y_grid_end = y_dim[y_index+1]
51
+ y_refletion = (y_grid_end-y_grid_start)* math.modf(y)[0] + y_grid_start
52
+ reflection_points.append([x_refletion,y_refletion])
53
+ pass
54
+
55
+ return reflection_points
@@ -0,0 +1,51 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (c) 2025 yaqiang.sun.
3
+ # This source code is licensed under the license found in the LICENSE file
4
+ # in the root directory of this source tree.
5
+ #########################################################################
6
+ # Author: yaqiangsun
7
+ # Created Time: 2025/10/20 18:13:37
8
+ ########################################################################
9
+
10
+
11
+ import os
12
+ # import cv2
13
+ import numpy as np
14
+ import sys
15
+ # 获取当前文件的绝对路径,向上两层就是项目根目录
16
+ project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
17
+ if project_root not in sys.path:
18
+ sys.path.insert(0, project_root)
19
+ #
20
+ # `scope_api_client`: this package is generated by `openapi-python-client`
21
+ from .scope_api import Client
22
+ from .task import run_task
23
+ import logging
24
+ import numpy as np
25
+
26
+
27
+
28
+ logging.basicConfig(level=logging.INFO)
29
+
30
+
31
+ class QubitScopeClient(object):
32
+ def __init__(self, url, api_key):
33
+ self.url = url
34
+ self.api_key = api_key
35
+ self.client = Client(base_url=url)
36
+
37
+ def request(self, file_list:list[str|dict[str,np.ndarray]],task_type:str="s21peak"):
38
+ if len(file_list)>0:
39
+ response = run_task(self.client,file_list,task_type)
40
+ else:
41
+ raise ValueError("file_list must not be empty")
42
+ return response
43
+ def get_result(self,response):
44
+ if response.status_code == 200:
45
+ logging.info("Result: %s", response.parsed)
46
+ result = response.parsed
47
+ return result
48
+ else:
49
+ logging.error("Error: %s %s", response.status_code, response.parsed)
50
+ return []
51
+
@@ -0,0 +1,8 @@
1
+ """A client library for accessing FastAPI"""
2
+
3
+ from .client import AuthenticatedClient, Client
4
+
5
+ __all__ = (
6
+ "AuthenticatedClient",
7
+ "Client",
8
+ )
@@ -0,0 +1 @@
1
+ """Contains methods for accessing the API"""
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""