-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parameter_fix.py
More file actions
76 lines (64 loc) · 2.21 KB
/
test_parameter_fix.py
File metadata and controls
76 lines (64 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
"""
測試腳本:驗證 qcode_example_v5.py 中的參數訪問修復
"""
import sys
import os
sys.path.append('/Users/albert-mac/Code/GitHub/Qcodes/analysis/data_processing_v2')
def test_parameter_access():
"""測試參數訪問是否正確"""
try:
# 模擬 lmfit fit_result 對象
class MockFitResult:
def __init__(self):
self.params = MockParams()
def valuesdict(self):
return {
'B_0_uT': 100.0,
'A_eff_um2': 50.0,
'Ic1': 10.0,
'Ic2': 8.0,
'T1': 0.5,
'phi_21': 0.1
}
class MockParams:
def valuesdict(self):
return {
'B_0_uT': 100.0,
'A_eff_um2': 50.0,
'Ic1': 10.0,
'Ic2': 8.0,
'T1': 0.5,
'phi_21': 0.1
}
# 測試正確的用法
fit_result = MockFitResult()
p = fit_result.valuesdict()
# 測試參數訪問
print("測試參數訪問:")
print(f"B_0_uT: {p['B_0_uT']}")
print(f"A_eff_um2: {p['A_eff_um2']}")
print(f"Ic1: {p['Ic1']}")
print(f"Ic2: {p['Ic2']}")
print(f"T1: {p['T1']}")
print(f"phi_21: {p['phi_21']}")
# 測試模擬的模型調用
def mock_model(x, **params):
import numpy as np
x_array = np.array(x)
return params['Ic1'] * x_array + params['Ic2']
result = mock_model([1, 2, 3], **p)
print(f"模擬模型調用結果: {result}")
print("\n✅ 參數訪問測試通過!")
return True
except Exception as e:
print(f"❌ 測試失敗: {e}")
return False
if __name__ == "__main__":
print("🔍 測試 qcode_example_v5.py 參數訪問修復...")
success = test_parameter_access()
if success:
print("\n🎉 所有修復都已驗證成功!")
print("現在可以安全運行 qcode_example_v5.py 而不會遇到 'B_0' 參數錯誤。")
else:
print("\n⚠️ 測試失敗,請檢查修復。")