coordinate-system 5.2.1__cp313-cp313-win_amd64.whl → 6.0.0__cp313-cp313-win_amd64.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.
@@ -1,376 +1,125 @@
1
- # coordinate_system/fourier_spectral.py
1
+ """
2
+ Quantum Frame Spectral Analysis - 向后兼容模块
3
+ ==============================================
2
4
 
3
- import numpy as np
4
- from typing import List, Tuple, Dict, Optional, Union, Any
5
- from dataclasses import dataclass
6
- from .coordinate_system import coord3, vec3, quat
5
+ 此模块已合并到 qframes.py 中。
6
+ 保留此文件仅用于向后兼容。
7
7
 
8
- # GPU availability check with proper error handling
9
- try:
10
- import cupy as cp
11
- import cupyx.scipy.fft as cufft
12
- GPU_AVAILABLE = True
13
- except ImportError:
14
- GPU_AVAILABLE = False
15
- # Create dummy types for type checking when GPU is not available
16
- class DummyCP:
17
- ndarray = np.ndarray
18
- def asarray(self, *args, **kwargs):
19
- raise RuntimeError("CuPy not available")
20
- def matmul(self, *args, **kwargs):
21
- raise RuntimeError("CuPy not available")
22
- cp = DummyCP()
23
- cufft = None
8
+ 请直接使用 qframes 模块:
9
+ from coordinate_system.qframes import (
10
+ QFrame,
11
+ QFrameSpectrum,
12
+ spectral_transform,
13
+ inverse_spectral_transform,
14
+ )
24
15
 
25
- @dataclass
26
- class FrameFieldSpectrum:
27
- """Fourier spectrum representation of coordinate frame field"""
28
- ux_spectrum: np.ndarray # Fourier coefficients for x-axis basis vectors
29
- uy_spectrum: np.ndarray # Fourier coefficients for y-axis basis vectors
30
- uz_spectrum: np.ndarray # Fourier coefficients for z-axis basis vectors
31
- origin_spectrum: np.ndarray # Fourier coefficients for origin positions
32
- frequencies: Tuple[np.ndarray, np.ndarray] # Frequency grids (kx, ky)
33
-
34
- def __post_init__(self):
35
- """Validate spectrum data dimension consistency"""
36
- shapes = [self.ux_spectrum.shape, self.uy_spectrum.shape,
37
- self.uz_spectrum.shape, self.origin_spectrum.shape]
38
- if not all(shape == shapes[0] for shape in shapes):
39
- raise ValueError("All spectrum components must have the same dimensions")
16
+ Author: Quantum Frame Theory
17
+ Date: 2025-12-03
18
+ """
40
19
 
41
- class FourierTransformer:
42
- """Base Fourier transformer class"""
43
-
44
- def __init__(self, grid_size: Tuple[int, int] = (64, 64)):
45
- self.grid_size = grid_size
46
- self.ny, self.nx = grid_size
47
-
48
- def coord_field_to_tensor(self, coord_field: List[List[coord3]]) -> np.ndarray:
49
- """Convert coordinate field to tensor representation"""
50
- # Validate grid dimensions
51
- actual_ny = len(coord_field)
52
- actual_nx = len(coord_field[0]) if actual_ny > 0 else 0
53
-
54
- if actual_ny != self.ny or actual_nx != self.nx:
55
- raise ValueError(f"Coordinate field dimensions ({actual_ny}x{actual_nx}) "
56
- f"do not match expected grid size ({self.ny}x{self.nx})")
57
-
58
- tensor_field = np.zeros((self.ny, self.nx, 12), dtype=np.float64)
59
-
60
- for i in range(self.ny):
61
- for j in range(self.nx):
62
- coord = coord_field[i][j]
63
- # Position (3), basis vectors (9)
64
- tensor_field[i, j, 0:3] = [coord.o.x, coord.o.y, coord.o.z]
65
- tensor_field[i, j, 3:6] = [coord.ux.x, coord.ux.y, coord.ux.z]
66
- tensor_field[i, j, 6:9] = [coord.uy.x, coord.uy.y, coord.uy.z]
67
- tensor_field[i, j, 9:12] = [coord.uz.x, coord.uz.y, coord.uz.z]
68
-
69
- return tensor_field
70
-
71
- def fft2_coord_field(self, coord_field: List[List[coord3]]) -> FrameFieldSpectrum:
72
- """Perform 2D Fourier transform on coordinate field"""
73
- tensor_field = self.coord_field_to_tensor(coord_field)
74
-
75
- # Separate components
76
- origin_field = tensor_field[..., 0:3] # Position field
77
- ux_field = tensor_field[..., 3:6] # x-axis basis field
78
- uy_field = tensor_field[..., 6:9] # y-axis basis field
79
- uz_field = tensor_field[..., 9:12] # z-axis basis field
80
-
81
- # Fourier transform
82
- origin_spectrum = np.fft.fft2(origin_field, axes=(0, 1))
83
- ux_spectrum = np.fft.fft2(ux_field, axes=(0, 1))
84
- uy_spectrum = np.fft.fft2(uy_field, axes=(0, 1))
85
- uz_spectrum = np.fft.fft2(uz_field, axes=(0, 1))
86
-
87
- # Frequency grids
88
- kx = np.fft.fftfreq(self.nx)
89
- ky = np.fft.fftfreq(self.ny)
90
-
91
- return FrameFieldSpectrum(
92
- ux_spectrum=ux_spectrum,
93
- uy_spectrum=uy_spectrum,
94
- uz_spectrum=uz_spectrum,
95
- origin_spectrum=origin_spectrum,
96
- frequencies=(kx, ky)
97
- )
98
-
99
- def ifft2_spectrum(self, spectrum: FrameFieldSpectrum) -> List[List[coord3]]:
100
- """Inverse Fourier transform to reconstruct coordinate field"""
101
- # Inverse transform each component
102
- origin_field = np.fft.ifft2(spectrum.origin_spectrum, axes=(0, 1)).real
103
- ux_field = np.fft.ifft2(spectrum.ux_spectrum, axes=(0, 1)).real
104
- uy_field = np.fft.ifft2(spectrum.uy_spectrum, axes=(0, 1)).real
105
- uz_field = np.fft.ifft2(spectrum.uz_spectrum, axes=(0, 1)).real
106
-
107
- # Reconstruct coordinate field
108
- coord_field = []
109
- for i in range(self.ny):
110
- row = []
111
- for j in range(self.nx):
112
- o = vec3(origin_field[i, j, 0], origin_field[i, j, 1], origin_field[i, j, 2])
113
- ux = vec3(ux_field[i, j, 0], ux_field[i, j, 1], ux_field[i, j, 2])
114
- uy = vec3(uy_field[i, j, 0], uy_field[i, j, 1], uy_field[i, j, 2])
115
- uz = vec3(uz_field[i, j, 0], uz_field[i, j, 1], uz_field[i, j, 2])
116
-
117
- # Create coordinate system (using unit quaternion, unit scale)
118
- coord = coord3(o, quat(1, 0, 0, 0), vec3(1, 1, 1))
119
- coord.ux, coord.uy, coord.uz = ux, uy, uz
120
- row.append(coord)
121
- coord_field.append(row)
122
-
123
- return coord_field
20
+ import warnings
124
21
 
125
- class GPUFourierTransformer(FourierTransformer):
126
- """GPU-accelerated Fourier transformer"""
127
-
128
- def __init__(self, grid_size: Tuple[int, int] = (64, 64)):
129
- super().__init__(grid_size)
130
- if not GPU_AVAILABLE:
131
- raise RuntimeError("CuPy not available. GPU acceleration requires CuPy installation.")
132
-
133
- def fft2_coord_field(self, coord_field: List[List[coord3]]) -> FrameFieldSpectrum:
134
- """GPU-accelerated Fourier transform of coordinate field"""
135
- tensor_field = self.coord_field_to_tensor(coord_field)
136
-
137
- # Transfer to GPU
138
- tensor_field_gpu = cp.asarray(tensor_field)
139
-
140
- # Separate components
141
- origin_field = tensor_field_gpu[..., 0:3]
142
- ux_field = tensor_field_gpu[..., 3:6]
143
- uy_field = tensor_field_gpu[..., 6:9]
144
- uz_field = tensor_field_gpu[..., 9:12]
145
-
146
- # GPU Fourier transform
147
- origin_spectrum = cufft.fft2(origin_field, axes=(0, 1))
148
- ux_spectrum = cufft.fft2(ux_field, axes=(0, 1))
149
- uy_spectrum = cufft.fft2(uy_field, axes=(0, 1))
150
- uz_spectrum = cufft.fft2(uz_field, axes=(0, 1))
151
-
152
- # Transfer back to CPU
153
- origin_spectrum = cp.asnumpy(origin_spectrum)
154
- ux_spectrum = cp.asnumpy(ux_spectrum)
155
- uy_spectrum = cp.asnumpy(uy_spectrum)
156
- uz_spectrum = cp.asnumpy(uz_spectrum)
157
-
158
- kx = np.fft.fftfreq(self.nx)
159
- ky = np.fft.fftfreq(self.ny)
160
-
161
- return FrameFieldSpectrum(
162
- ux_spectrum=ux_spectrum,
163
- uy_spectrum=uy_spectrum,
164
- uz_spectrum=uz_spectrum,
165
- origin_spectrum=origin_spectrum,
166
- frequencies=(kx, ky)
167
- )
168
-
169
- def ifft2_spectrum(self, spectrum: FrameFieldSpectrum) -> List[List[coord3]]:
170
- """GPU-accelerated inverse Fourier transform"""
171
- # Transfer to GPU
172
- origin_spectrum_gpu = cp.asarray(spectrum.origin_spectrum)
173
- ux_spectrum_gpu = cp.asarray(spectrum.ux_spectrum)
174
- uy_spectrum_gpu = cp.asarray(spectrum.uy_spectrum)
175
- uz_spectrum_gpu = cp.asarray(spectrum.uz_spectrum)
176
-
177
- # GPU inverse transform
178
- origin_field = cufft.ifft2(origin_spectrum_gpu, axes=(0, 1)).real
179
- ux_field = cufft.ifft2(ux_spectrum_gpu, axes=(0, 1)).real
180
- uy_field = cufft.ifft2(uy_spectrum_gpu, axes=(0, 1)).real
181
- uz_field = cufft.ifft2(uz_spectrum_gpu, axes=(0, 1)).real
182
-
183
- # Transfer back to CPU
184
- origin_field = cp.asnumpy(origin_field)
185
- ux_field = cp.asnumpy(ux_field)
186
- uy_field = cp.asnumpy(uy_field)
187
- uz_field = cp.asnumpy(uz_field)
188
-
189
- # Reconstruct coordinate field
190
- coord_field = []
191
- for i in range(self.ny):
192
- row = []
193
- for j in range(self.nx):
194
- o = vec3(origin_field[i, j, 0], origin_field[i, j, 1], origin_field[i, j, 2])
195
- ux = vec3(ux_field[i, j, 0], ux_field[i, j, 1], ux_field[i, j, 2])
196
- uy = vec3(uy_field[i, j, 0], uy_field[i, j, 1], uy_field[i, j, 2])
197
- uz = vec3(uz_field[i, j, 0], uz_field[i, j, 1], uz_field[i, j, 2])
198
-
199
- coord = coord3(o, quat(1, 0, 0, 0), vec3(1, 1, 1))
200
- coord.ux, coord.uy, coord.uz = ux, uy, uz
201
- row.append(coord)
202
- coord_field.append(row)
203
-
204
- return coord_field
22
+ # 发出弃用警告
23
+ warnings.warn(
24
+ "fourier_spectral 模块已合并到 qframes.py 中。"
25
+ "请直接使用: from coordinate_system.qframes import ...",
26
+ DeprecationWarning,
27
+ stacklevel=2
28
+ )
205
29
 
206
- class BatchCoordTransformer:
207
- """Batch coordinate transformer (GPU accelerated)"""
208
-
209
- def __init__(self, batch_size: int = 32):
210
- self.batch_size = batch_size
211
- self.gpu_available = GPU_AVAILABLE
212
-
213
- def batch_coord_transform(self, coords: List[coord3],
214
- transformations: List[coord3]) -> List[coord3]:
215
- """Batch coordinate transformation"""
216
- if len(coords) != len(transformations):
217
- raise ValueError("Number of coordinates and transformations must match")
218
-
219
- if self.gpu_available and len(coords) > 100:
220
- return self._gpu_batch_transform(coords, transformations)
221
- else:
222
- return self._cpu_batch_transform(coords, transformations)
223
-
224
- def _cpu_batch_transform(self, coords: List[coord3],
225
- transformations: List[coord3]) -> List[coord3]:
226
- """CPU batch transformation"""
227
- results = []
228
- for coord, transform in zip(coords, transformations):
229
- results.append(coord * transform)
230
- return results
231
-
232
- def _gpu_batch_transform(self, coords: List[coord3],
233
- transformations: List[coord3]) -> List[coord3]:
234
- """GPU batch transformation"""
235
- if not self.gpu_available:
236
- return self._cpu_batch_transform(coords, transformations)
237
-
238
- # Convert coordinate data to tensors
239
- coord_tensors = self._coords_to_tensor_batch(coords)
240
- transform_tensors = self._coords_to_tensor_batch(transformations)
241
-
242
- # Transfer to GPU and perform batch matrix operations
243
- coord_tensors_gpu = cp.asarray(coord_tensors)
244
- transform_tensors_gpu = cp.asarray(transform_tensors)
245
-
246
- # Execute batch coordinate multiplication
247
- result_tensors_gpu = self._gpu_coord_multiply(coord_tensors_gpu, transform_tensors_gpu)
248
-
249
- # Transfer back to CPU and reconstruct coordinates
250
- result_tensors = cp.asnumpy(result_tensors_gpu)
251
- return self._tensor_batch_to_coords(result_tensors)
252
-
253
- def _coords_to_tensor_batch(self, coords: List[coord3]) -> np.ndarray:
254
- """Convert batch coordinates to tensors"""
255
- batch_size = len(coords)
256
- tensors = np.zeros((batch_size, 4, 4), dtype=np.float64)
257
-
258
- for i, coord in enumerate(coords):
259
- # Build 4x4 homogeneous transformation matrix
260
- tensors[i, 0, 0:3] = [coord.ux.x, coord.uy.x, coord.uz.x]
261
- tensors[i, 1, 0:3] = [coord.ux.y, coord.uy.y, coord.uz.y]
262
- tensors[i, 2, 0:3] = [coord.ux.z, coord.uy.z, coord.uz.z]
263
- tensors[i, 3, 0:3] = [coord.o.x, coord.o.y, coord.o.z]
264
- tensors[i, 3, 3] = 1.0
265
-
266
- return tensors
267
-
268
- def _tensor_batch_to_coords(self, tensors: np.ndarray) -> List[coord3]:
269
- """Convert tensor batch to coordinates"""
270
- coords = []
271
- for i in range(tensors.shape[0]):
272
- matrix = tensors[i]
273
- o = vec3(matrix[3, 0], matrix[3, 1], matrix[3, 2])
274
- ux = vec3(matrix[0, 0], matrix[1, 0], matrix[2, 0])
275
- uy = vec3(matrix[0, 1], matrix[1, 1], matrix[2, 1])
276
- uz = vec3(matrix[0, 2], matrix[1, 2], matrix[2, 2])
277
-
278
- coord = coord3(o, quat(1, 0, 0, 0), vec3(1, 1, 1))
279
- coord.ux, coord.uy, coord.uz = ux, uy, uz
280
- coords.append(coord)
281
-
282
- return coords
283
-
284
- def _gpu_coord_multiply(self, A: Any, B: Any) -> Any:
285
- """Batch coordinate multiplication on GPU"""
286
- if not self.gpu_available:
287
- # Fallback to CPU implementation
288
- A_np = A if isinstance(A, np.ndarray) else cp.asnumpy(A)
289
- B_np = B if isinstance(B, np.ndarray) else cp.asnumpy(B)
290
- return np.matmul(A_np, B_np)
291
-
292
- # GPU matrix multiplication
293
- return cp.matmul(A, B)
30
+ # 从 qframes 重导出所有内容
31
+ from .qframes import (
32
+ # 核心类
33
+ QFrame,
34
+ QuantumState,
35
+ PathIntegral,
36
+ QFrameSpectrum,
294
37
 
295
- class SpectralAnalyzer:
296
- """Spectral geometry analyzer"""
297
-
298
- def __init__(self, transformer: FourierTransformer = None):
299
- self.transformer = transformer or FourierTransformer()
300
-
301
- def compute_spectral_density(self, spectrum: FrameFieldSpectrum) -> np.ndarray:
302
- """Compute spectral energy density"""
303
- energy_density = (np.abs(spectrum.ux_spectrum)**2 +
304
- np.abs(spectrum.uy_spectrum)**2 +
305
- np.abs(spectrum.uz_spectrum)**2)
306
- return np.mean(energy_density, axis=-1) # Average over vector components
307
-
308
- def radial_spectrum_average(self, spectrum: FrameFieldSpectrum) -> Tuple[np.ndarray, np.ndarray]:
309
- """Radial spectrum average (ShapeDNA)"""
310
- kx, ky = spectrum.frequencies
311
- k_mag = np.sqrt(kx[:, None]**2 + ky[None, :]**2)
312
-
313
- spectral_density = self.compute_spectral_density(spectrum)
314
-
315
- # Radial binning
316
- k_max = np.max(k_mag)
317
- k_bins = np.linspace(0, k_max, 50)
318
- radial_avg = np.zeros_like(k_bins)
319
-
320
- for i, k_val in enumerate(k_bins[:-1]):
321
- mask = (k_mag >= k_bins[i]) & (k_mag < k_bins[i+1])
322
- if np.any(mask):
323
- radial_avg[i] = np.mean(spectral_density[mask])
324
-
325
- return k_bins, radial_avg
38
+ # 便利函数
39
+ spectral_transform,
40
+ inverse_spectral_transform,
326
41
 
327
- # Convenience functions
328
- def fft2_coord_field(coord_field: List[List[coord3]],
329
- grid_size: Tuple[int, int] = (64, 64),
330
- use_gpu: bool = False) -> FrameFieldSpectrum:
331
- """2D Fourier transform of coordinate field"""
332
- if use_gpu and GPU_AVAILABLE:
333
- transformer = GPUFourierTransformer(grid_size)
334
- else:
335
- transformer = FourierTransformer(grid_size)
336
- return transformer.fft2_coord_field(coord_field)
42
+ # 常数
43
+ HBAR,
44
+ GPU_AVAILABLE,
45
+ )
337
46
 
338
- def ifft2_spectrum(spectrum: FrameFieldSpectrum,
339
- use_gpu: bool = False) -> List[List[coord3]]:
340
- """Inverse Fourier transform to reconstruct coordinate field"""
341
- if use_gpu and GPU_AVAILABLE:
342
- transformer = GPUFourierTransformer()
343
- else:
344
- transformer = FourierTransformer()
345
- return transformer.ifft2_spectrum(spectrum)
47
+ # 向后兼容别名
48
+ QuantumFrameSpectrum = QFrameSpectrum
49
+ QuantumFrameTransformer = QFrame # QFrame 现在包含变换方法
346
50
 
347
- def compute_spectral_density(spectrum: FrameFieldSpectrum) -> np.ndarray:
348
- """Compute spectral energy density"""
349
- analyzer = SpectralAnalyzer()
350
- return analyzer.compute_spectral_density(spectrum)
351
51
 
352
- def radial_spectrum_average(spectrum: FrameFieldSpectrum) -> Tuple[np.ndarray, np.ndarray]:
353
- """Radial spectrum average"""
354
- analyzer = SpectralAnalyzer()
355
- return analyzer.radial_spectrum_average(spectrum)
52
+ def quantum_frame_transform(coord_field, grid_size=None, use_gpu=False, hbar=HBAR):
53
+ """
54
+ 向后兼容函数 - 已整合到 QFrame.from_coord_field()
55
+ """
56
+ warnings.warn(
57
+ "quantum_frame_transform() 已弃用,请使用 QFrame.from_coord_field()",
58
+ DeprecationWarning,
59
+ stacklevel=2
60
+ )
61
+ return QFrame.from_coord_field(coord_field, hbar)
356
62
 
357
- # Placeholder functions - to be implemented in complete version
358
- def spectral_intrinsic_gradient(spectrum: FrameFieldSpectrum) -> FrameFieldSpectrum:
359
- """Intrinsic gradient calculation in spectral space"""
360
- # Implement intrinsic gradient operator in spectral space
361
- return spectrum
362
63
 
363
- def spectral_curvature_calculator(spectrum: FrameFieldSpectrum) -> Dict:
364
- """Spectral curvature calculation"""
365
- # Implement curvature calculation based on spectrum
366
- return {}
64
+ def inverse_quantum_transform(spectrum, use_gpu=False):
65
+ """
66
+ 向后兼容函数 - 已整合到 QFrameSpectrum.to_coord_field()
67
+ """
68
+ warnings.warn(
69
+ "inverse_quantum_transform() 已弃用,请使用 spectrum.to_coord_field()",
70
+ DeprecationWarning,
71
+ stacklevel=2
72
+ )
73
+ return spectrum.to_coord_field()
367
74
 
368
- def berry_phase_calculator(spectrum: FrameFieldSpectrum) -> float:
369
- """Berry phase calculation"""
370
- # Implement topological invariant calculation
371
- return 0.0
372
75
 
373
- def topological_invariant_analyzer(spectrum: FrameFieldSpectrum) -> Dict:
374
- """Topological invariant analysis"""
375
- # Implement complete topological analysis
376
- return {}
76
+ def compute_quantum_spectral_density(spectrum):
77
+ """
78
+ 向后兼容函数 - 已整合到 QFrameSpectrum.spectral_density()
79
+ """
80
+ warnings.warn(
81
+ "compute_quantum_spectral_density() 已弃用,请使用 spectrum.spectral_density()",
82
+ DeprecationWarning,
83
+ stacklevel=2
84
+ )
85
+ return spectrum.spectral_density()
86
+
87
+
88
+ def compute_radial_spectrum(spectrum):
89
+ """
90
+ 向后兼容函数 - 已整合到 QFrameSpectrum.radial_average()
91
+ """
92
+ warnings.warn(
93
+ "compute_radial_spectrum() 已弃用,请使用 spectrum.radial_average()",
94
+ DeprecationWarning,
95
+ stacklevel=2
96
+ )
97
+ return spectrum.radial_average()
98
+
99
+
100
+ # 导出列表
101
+ __all__ = [
102
+ # 核心类
103
+ 'QFrame',
104
+ 'QuantumState',
105
+ 'PathIntegral',
106
+ 'QFrameSpectrum',
107
+
108
+ # 向后兼容别名
109
+ 'QuantumFrameSpectrum',
110
+ 'QuantumFrameTransformer',
111
+
112
+ # 便利函数
113
+ 'spectral_transform',
114
+ 'inverse_spectral_transform',
115
+
116
+ # 向后兼容函数
117
+ 'quantum_frame_transform',
118
+ 'inverse_quantum_transform',
119
+ 'compute_quantum_spectral_density',
120
+ 'compute_radial_spectrum',
121
+
122
+ # 常数
123
+ 'HBAR',
124
+ 'GPU_AVAILABLE',
125
+ ]