qubitclient 0.0.0.1__tar.gz → 0.0.3.0__tar.gz

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 (65) hide show
  1. qubitclient-0.0.3.0/PKG-INFO +112 -0
  2. {qubitclient-0.0.0.1 → qubitclient-0.0.3.0}/README.md +29 -12
  3. qubitclient-0.0.3.0/pyproject.toml +16 -0
  4. qubitclient-0.0.3.0/qubitclient/__init__.py +6 -0
  5. qubitclient-0.0.3.0/qubitclient/nnscope/nnscope.py +51 -0
  6. {qubitclient-0.0.0.1/qubitclient → qubitclient-0.0.3.0/qubitclient/nnscope/nnscope_api}/QubitSeg.py +7 -7
  7. qubitclient-0.0.3.0/qubitclient/nnscope/nnscope_api/curve/__init__.py +0 -0
  8. qubitclient-0.0.3.0/qubitclient/nnscope/nnscope_api/curve/curve_type.py +15 -0
  9. qubitclient-0.0.3.0/qubitclient/nnscope/task.py +130 -0
  10. qubitclient-0.0.3.0/qubitclient/nnscope/utils/data_convert.py +114 -0
  11. qubitclient-0.0.3.0/qubitclient/nnscope/utils/data_parser.py +41 -0
  12. qubitclient-0.0.3.0/qubitclient/nnscope/utils/request_tool.py +41 -0
  13. qubitclient-0.0.3.0/qubitclient/nnscope/utils/result_parser.py +55 -0
  14. qubitclient-0.0.3.0/qubitclient/scope/scope.py +51 -0
  15. qubitclient-0.0.3.0/qubitclient/scope/scope_api/__init__.py +8 -0
  16. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/__init__.py +1 -0
  17. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/__init__.py +1 -0
  18. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/get_task_result_api_v1_tasks_demo_pk_get.py +155 -0
  19. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/get_task_result_api_v1_tasks_scope_pk_get.py +155 -0
  20. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/optpipulse_api_v1_tasks_scope_optpipulse_post.py +218 -0
  21. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/rabi_api_v1_tasks_scope_rabi_post.py +218 -0
  22. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/rabicos_api_v1_tasks_scope_rabicospeak_post.py +218 -0
  23. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/s21peak_api_v1_tasks_scope_s21peak_post.py +218 -0
  24. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/s21vflux_api_v1_tasks_scope_s21vflux_post.py +218 -0
  25. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/singleshot_api_v1_tasks_scope_singleshot_post.py +218 -0
  26. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/spectrum2d_api_v1_tasks_scope_spectrum2d_post.py +218 -0
  27. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/spectrum_api_v1_tasks_scope_spectrum_post.py +218 -0
  28. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/t1fit_api_v1_tasks_scope_t1fit_post.py +218 -0
  29. qubitclient-0.0.3.0/qubitclient/scope/scope_api/api/defined_tasks/t1fit_api_v1_tasks_scope_t2fit_post.py +218 -0
  30. qubitclient-0.0.3.0/qubitclient/scope/scope_api/client.py +268 -0
  31. qubitclient-0.0.3.0/qubitclient/scope/scope_api/errors.py +16 -0
  32. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/__init__.py +29 -0
  33. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/body_optpipulse_api_v1_tasks_scope_optpipulse_post.py +83 -0
  34. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/body_rabi_api_v1_tasks_scope_rabi_post.py +83 -0
  35. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/body_rabicos_api_v1_tasks_scope_rabicospeak_post.py +83 -0
  36. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/body_s21_peak_api_v1_tasks_scope_s21_peak_post.py +83 -0
  37. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/body_s21_vflux_api_v1_tasks_scope_s21_vflux_post.py +83 -0
  38. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/body_singleshot_api_v1_tasks_scope_singleshot_post.py +83 -0
  39. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/body_spectrum_2d_api_v1_tasks_scope_spectrum_2d_post.py +83 -0
  40. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/body_spectrum_api_v1_tasks_scope_spectrum_post.py +83 -0
  41. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/body_t1_fit_api_v1_tasks_scope_t1_fit_post.py +83 -0
  42. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/body_t1_fit_api_v1_tasks_scope_t2_fit_post.py +83 -0
  43. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/http_validation_error.py +75 -0
  44. qubitclient-0.0.3.0/qubitclient/scope/scope_api/models/validation_error.py +88 -0
  45. qubitclient-0.0.3.0/qubitclient/scope/scope_api/types.py +54 -0
  46. qubitclient-0.0.3.0/qubitclient/scope/task.py +147 -0
  47. qubitclient-0.0.3.0/qubitclient/scope/utils/__init__.py +0 -0
  48. qubitclient-0.0.3.0/qubitclient/scope/utils/data_parser.py +20 -0
  49. qubitclient-0.0.3.0/qubitclient.egg-info/PKG-INFO +112 -0
  50. qubitclient-0.0.3.0/qubitclient.egg-info/SOURCES.txt +58 -0
  51. {qubitclient-0.0.0.1 → qubitclient-0.0.3.0}/setup.py +1 -1
  52. qubitclient-0.0.3.0/tests/test_nnscope.py +205 -0
  53. qubitclient-0.0.3.0/tests/test_scope.py +66 -0
  54. qubitclient-0.0.3.0/tests/test_scope_api.py +50 -0
  55. qubitclient-0.0.0.1/PKG-INFO +0 -35
  56. qubitclient-0.0.0.1/qubitclient/__init__.py +0 -1
  57. qubitclient-0.0.0.1/qubitclient.egg-info/PKG-INFO +0 -35
  58. qubitclient-0.0.0.1/qubitclient.egg-info/SOURCES.txt +0 -12
  59. qubitclient-0.0.0.1/qubitclient.egg-info/requires.txt +0 -1
  60. {qubitclient-0.0.0.1 → qubitclient-0.0.3.0}/LICENSE +0 -0
  61. {qubitclient-0.0.0.1 → qubitclient-0.0.3.0}/MANIFEST.in +0 -0
  62. {qubitclient-0.0.0.1 → qubitclient-0.0.3.0}/qubitclient.egg-info/dependency_links.txt +0 -0
  63. {qubitclient-0.0.0.1 → qubitclient-0.0.3.0}/qubitclient.egg-info/top_level.txt +0 -0
  64. {qubitclient-0.0.0.1 → qubitclient-0.0.3.0}/qubitclient.egg-info/zip-safe +0 -0
  65. {qubitclient-0.0.0.1 → qubitclient-0.0.3.0}/setup.cfg +0 -0
@@ -0,0 +1,112 @@
1
+ Metadata-Version: 2.4
2
+ Name: qubitclient
3
+ Version: 0.0.3.0
4
+ Summary: qubit analysis client
5
+ Home-page: https://github.com/yaqiangsun/QubitClient
6
+ Author: Yaqiang Sun
7
+ Author-email: Yaqiang Sun <sunyaking@163.com>
8
+ License: GPL-3.0
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: author
13
+ Dynamic: home-page
14
+ Dynamic: license-file
15
+ Dynamic: requires-python
16
+
17
+ # QubitClient
18
+
19
+ #### 介绍
20
+ **qubit-client**
21
+ QubitClient 是用于使用Qubit服务的示例。
22
+
23
+ # 更新日志
24
+
25
+ 近期更新:
26
+
27
+ - **增加scope功能包**: 增加多种任务功能(20251022).
28
+ - **增加曲线类型**: 增加cosin类型曲线拟合(20250606).
29
+ - **构建基础项目:** 基础功能与结构构建.
30
+
31
+
32
+ # 使用
33
+
34
+ ### scope功能包
35
+
36
+ #### 使用说明
37
+ 1.拷贝config.py.example文件为config.py,并修改配置参数。
38
+ ```
39
+ cp config.py.example config.py
40
+ ```
41
+ 2.运行
42
+ 单次请求多个文件:
43
+ ```python
44
+ python tests/test_nnscope.py
45
+ ```
46
+ 批量多次请求
47
+ ```bash
48
+ Not provided
49
+ ```
50
+ ## 功能集合
51
+ ### 曲线分割功能
52
+
53
+ #### 运行示例代码
54
+ ```python
55
+ python tests/test_nnscope.py
56
+ ```
57
+
58
+ #### 定义实例
59
+ ```
60
+ client = QubitNNScopeClient(url=url,api_key="")
61
+ ```
62
+
63
+ #### 请求输入
64
+
65
+ ```python
66
+ response = client.request(file_list=file_path_list,\
67
+ task_type=NNTaskName.SPECTRUM2D,curve_type=CurveType.COSINE)
68
+ ```
69
+ - dict_list格式为:
70
+ ```json
71
+ [
72
+ {
73
+ "bias":np.ndarray shape(A),
74
+ "frequency":np.ndarray shape(B),
75
+ "iq_avg":np.ndarray shape(B,A),
76
+ },
77
+ ...
78
+ ]
79
+ ```
80
+ - curve_type: `CurveType.COSINE`(cosin拟合) or `CurveType.POLY`(多项式拟合)
81
+
82
+
83
+ #### 返回值
84
+ 返回请求为response
85
+ ```python
86
+ res = response.json()
87
+ ```
88
+ res格式为:
89
+ ```json
90
+ {
91
+ "state":'success',
92
+ "result":result
93
+ }
94
+ ```
95
+ 其中result格式:
96
+ ```json
97
+ [
98
+ {
99
+ "params_list":List[List[float]],//每条线段的多项式参数列表
100
+ "linepoints_list":List[List[[row_index,col_index]]],//每条线段的点坐标列表
101
+ "confidence_list":List[float],//每条线段的置信度
102
+ },//每一个npz文件的结果
103
+ {
104
+ ...
105
+ },
106
+ ...
107
+ ]
108
+ ```
109
+
110
+ ### 其他功能完善中
111
+
112
+
@@ -8,27 +8,49 @@ QubitClient 是用于使用Qubit服务的示例。
8
8
 
9
9
  近期更新:
10
10
 
11
+ - **增加scope功能包**: 增加多种任务功能(20251022).
11
12
  - **增加曲线类型**: 增加cosin类型曲线拟合(20250606).
12
13
  - **构建基础项目:** 基础功能与结构构建.
13
14
 
14
15
 
15
16
  # 使用
17
+
18
+ ### scope功能包
19
+
16
20
  #### 使用说明
17
21
  1.拷贝config.py.example文件为config.py,并修改配置参数。
18
22
  ```
19
23
  cp config.py.example config.py
20
24
  ```
21
25
  2.运行
22
- ```Python
23
- python client_demo.py
26
+ 单次请求多个文件:
27
+ ```python
28
+ python tests/test_nnscope.py
29
+ ```
30
+ 批量多次请求
31
+ ```bash
32
+ Not provided
33
+ ```
34
+ ## 功能集合
35
+ ### 曲线分割功能
36
+
37
+ #### 运行示例代码
38
+ ```python
39
+ python tests/test_nnscope.py
40
+ ```
41
+
42
+ #### 定义实例
43
+ ```
44
+ client = QubitNNScopeClient(url=url,api_key="")
24
45
  ```
25
46
 
26
47
  #### 请求输入
27
48
 
28
49
  ```python
29
- response = client.request(file_list=dict_list)
50
+ response = client.request(file_list=file_path_list,\
51
+ task_type=NNTaskName.SPECTRUM2D,curve_type=CurveType.COSINE)
30
52
  ```
31
- dict_list格式为:
53
+ - dict_list格式为:
32
54
  ```json
33
55
  [
34
56
  {
@@ -39,6 +61,7 @@ dict_list格式为:
39
61
  ...
40
62
  ]
41
63
  ```
64
+ - curve_type: `CurveType.COSINE`(cosin拟合) or `CurveType.POLY`(多项式拟合)
42
65
 
43
66
 
44
67
  #### 返回值
@@ -68,12 +91,6 @@ res格式为:
68
91
  ]
69
92
  ```
70
93
 
71
- ### 坐标映射
72
- ```python
73
- points = result[0]["linepoints_list"][0]
74
- reflection_points = client.convert_axis(points, bias,frequency)
75
- ```
76
- `points`格式:`List[[row_index,col_index],...]`,表示单条线段的点坐标.<br>
77
- `bias`格式:`np.ndarray shape(A)`,与上述bias相同.<br>
78
- `frequency`格式:`np.ndarray shape(B)`,与上述frequency相同.<br>
94
+ ### 其他功能完善中
95
+
79
96
 
@@ -0,0 +1,16 @@
1
+ [project]
2
+ name = "qubitclient"
3
+ version = "0.0.3.0"
4
+ description = "qubit analysis client"
5
+ authors = [
6
+ { name = "Yaqiang Sun", email = "sunyaking@163.com" },
7
+ ]
8
+ license = {text = "GPL-3.0"}
9
+ readme = "README.md"
10
+ requires-python = ">=3.10, <3.13"
11
+ dependencies = []
12
+
13
+ [tool.setuptools.packages.find]
14
+ where = ["."]
15
+ include = ["qubitclient*"] # match qubitscope and qubitscope.*
16
+ exclude = ["tests", "tests.*", "tmp", "tmp.*"]
@@ -0,0 +1,6 @@
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:
@@ -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