Skip to content

Commit e9764ff

Browse files
authored
Merge pull request #194 from sandialabs/saving-too-fast
Saving too fast issues fixed.
2 parents 30dbdd5 + 232d79c commit e9764ff

File tree

8 files changed

+140
-14
lines changed

8 files changed

+140
-14
lines changed
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:07:38
2-
Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:07:38
3-
Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:07:38
4-
Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:07:38
5-
Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:06:58
6-
Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:06:57
7-
Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:06:57
8-
Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.3.0 at 2024-05-30 10:39:46
1+
Passed with test_instrument_driver version v0.1.0 tested on pyscan version v0.5.3 at 2024-07-05 11:41:28
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
Passed with test_voltage version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:07:38
2-
Passed with test_voltage version v0.1.0 tested on pyscan version v0.4.0 at 2024-06-05 15:06:58
3-
Passed with test_voltage version v0.1.0 tested on pyscan version v0.3.0 at 2024-05-30 10:39:46
1+
Passed with test_voltage version v0.1.0 tested on pyscan version v0.5.3 at 2024-07-05 11:41:28

pyscan/measurement/abstract_experiment.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,16 @@ def check_runinfo(self):
160160
if num_repeat_scans > 1:
161161
assert False, "More than one repeat scan detected. This is not allowed."
162162

163-
self.runinfo.long_name = strftime("%Y%m%dT%H%M%S")
163+
base_name = strftime("%Y%m%dT%H%M%S")
164+
save_path = self.runinfo.data_path / '{}.hdf5'.format(base_name)
165+
count = 0
166+
167+
while save_path.exists():
168+
count += 1
169+
save_path = self.runinfo.data_path / f'{base_name}-{count}.hdf5'
170+
171+
self.runinfo.long_name = save_path.stem
172+
164173
self.runinfo.short_name = self.runinfo.long_name[8:]
165174

166175
self.runinfo.check()

pyscan/measurement/experiment.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def generic_experiment(self):
8282
self.runinfo.t3[indicies] = (datetime.now()).timestamp()
8383

8484
if np.all(np.array(self.runinfo.indicies) == 0):
85+
self.runinfo.measured = []
8586
for key, value in data.items():
8687
self.runinfo.measured.append(key)
8788
self.preallocate(data)
@@ -172,6 +173,7 @@ def average_experiment(self):
172173

173174
# if on the first row of data, log the data names in self.runinfo.measured
174175
if np.all(np.array(self.runinfo.indicies) == 0):
176+
self.runinfo.measured = []
175177
for key, value in data.items():
176178
self.runinfo.measured.append(key)
177179
self.preallocate(data)

test/legacy/measurement/test_legacy_abstract_experiment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from io import StringIO
1313
import sys
1414
import shutil
15+
import re
1516

1617

1718
# for testing default trigger function with empty function
@@ -104,7 +105,8 @@ def test_ms_diff_inputs(data_dir=None, measure_function=measure_point, allocate=
104105

105106
assert hasattr(ms.runinfo, 'long_name'), "Meta Sweep runinfo long name is not initialized by check_runinfo()"
106107
assert isinstance(ms.runinfo.long_name, str), "Meta Sweep runinfo long name is not initialized as a string"
107-
assert len(ms.runinfo.long_name) == 15, "Meta Sweep runinfo long name is not 15 characters"
108+
# check that the long name is formatted with values for YYYYMMDDTHHMMSS, and optionally a - followed by digits.
109+
assert re.match(r'^\d{8}T\d{6}(-\d+)?$', ms.runinfo.long_name), "runinfo long_name is not properly formatted"
108110

109111
assert hasattr(ms.runinfo, 'short_name'), "Meta Sweep runinfo long name is not initialized by check_runinfo()"
110112
assert isinstance(ms.runinfo.short_name, str), "Meta Sweep runinfo short name is not initialized as a string"

test/legacy/measurement/test_legacy_experiment.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import shutil
99
import numpy as np
1010
import pytest
11+
import re
12+
import os
1113

1214

1315
##################### FUNCTIONS USED BY TEST CASES #####################
@@ -1098,3 +1100,61 @@ def check_load_expt(temp):
10981100
check_load_expt(temp)
10991101

11001102
shutil.rmtree('./backup')
1103+
1104+
1105+
def test_fast_experiments():
1106+
devices = ps.ItemAttribute()
1107+
1108+
devices.v1 = ps.TestVoltage() # Device 1
1109+
devices.v2 = ps.TestVoltage() # Device 2
1110+
devices.v3 = ps.TestVoltage() # Device 3
1111+
1112+
def get_voltage_data(ms):
1113+
"""
1114+
Reads the voltage from v1, v2, and v3 devices. Also adds a calculated value vsum.
1115+
"""
1116+
1117+
devices = ms.devices
1118+
1119+
d = ps.ItemAttribute()
1120+
1121+
d.v1_readout = devices.v1.voltage
1122+
d.v2_readout = devices.v2.voltage
1123+
d.v3_readout = devices.v3.voltage
1124+
1125+
d.vsum = d.v1_readout + d.v2_readout + d.v3_readout
1126+
1127+
return d
1128+
1129+
# Create RunInfo instance and set scan0 to PropertyScan
1130+
runinfo = ps.RunInfo()
1131+
runinfo.scan0 = ps.RepeatScan(1, dt=0.0000001)
1132+
1133+
# Set RunInfo measure_function (remember, it takes a Experiment object as a parameter and
1134+
# returns an ItemAttribute containing data).
1135+
runinfo.measure_function = get_voltage_data
1136+
1137+
# Create a Experiment class with the RunInfo and Devices just created
1138+
ms = ps.Sweep(runinfo, devices, time=True)
1139+
1140+
long_names = []
1141+
1142+
while len(long_names) < 3:
1143+
ms.run()
1144+
if len(long_names) == 0:
1145+
long_names.append(ms.runinfo.long_name)
1146+
elif (ms.runinfo.long_name[:15] == long_names[0][:15]):
1147+
long_names.append(ms.runinfo.long_name)
1148+
else:
1149+
long_names = [ms.runinfo.long_name]
1150+
1151+
err_str = f"First long name '{long_names[0]}' does not match expected date/time format."
1152+
assert re.match(r'^\d{8}T\d{6}$', long_names[0]), err_str
1153+
err_str = f"-1 long name '{long_names[1]}' does not match expected increment or format."
1154+
assert long_names[1] == long_names[0] + '-1', err_str
1155+
err_str = f"-2 long name '{long_names[1]}' does not match expected increment or format."
1156+
assert long_names[2] == long_names[0] + '-2', err_str
1157+
1158+
for name in long_names:
1159+
save_path = ms.runinfo.data_path / '{}.hdf5'.format(name)
1160+
assert os.path.exists(save_path), f"Expected file at path'{save_path}' was not found."

test/measurement/test_abstract_experiment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from io import StringIO
1313
import sys
1414
import shutil
15+
import re
1516

1617

1718
# for testing default trigger function with empty function
@@ -104,7 +105,8 @@ def test_ms_diff_inputs(data_dir=None, measure_function=measure_point, allocate=
104105

105106
assert hasattr(ms.runinfo, 'long_name'), "Meta Sweep runinfo long name is not initialized by check_runinfo()"
106107
assert isinstance(ms.runinfo.long_name, str), "Meta Sweep runinfo long name is not initialized as a string"
107-
assert len(ms.runinfo.long_name) == 15, "Meta Sweep runinfo long name is not 15 characters"
108+
# check that the long name is formatted with values for YYYYMMDDTHHMMSS, and optionally a - followed by digits.
109+
assert re.match(r'^\d{8}T\d{6}(-\d+)?$', ms.runinfo.long_name), "runinfo long_name is not properly formatted"
108110

109111
assert hasattr(ms.runinfo, 'short_name'), "Meta Sweep runinfo long name is not initialized by check_runinfo()"
110112
assert isinstance(ms.runinfo.short_name, str), "Meta Sweep runinfo short name is not initialized as a string"

test/measurement/test_experiment.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import shutil
99
import numpy as np
1010
import pytest
11+
import re
12+
import os
1113

1214

1315
##################### FUNCTIONS USED BY TEST CASES #####################
@@ -1093,3 +1095,61 @@ def check_load_expt(temp):
10931095
check_load_expt(temp)
10941096

10951097
shutil.rmtree('./backup')
1098+
1099+
1100+
def test_fast_experiments():
1101+
devices = ps.ItemAttribute()
1102+
1103+
devices.v1 = ps.TestVoltage() # Device 1
1104+
devices.v2 = ps.TestVoltage() # Device 2
1105+
devices.v3 = ps.TestVoltage() # Device 3
1106+
1107+
def get_voltage_data(expt):
1108+
"""
1109+
Reads the voltage from v1, v2, and v3 devices. Also adds a calculated value vsum.
1110+
"""
1111+
1112+
devices = expt.devices
1113+
1114+
d = ps.ItemAttribute()
1115+
1116+
d.v1_readout = devices.v1.voltage
1117+
d.v2_readout = devices.v2.voltage
1118+
d.v3_readout = devices.v3.voltage
1119+
1120+
d.vsum = d.v1_readout + d.v2_readout + d.v3_readout
1121+
1122+
return d
1123+
1124+
# Create RunInfo instance and set scan0 to PropertyScan
1125+
runinfo = ps.RunInfo()
1126+
runinfo.scan0 = ps.RepeatScan(1, dt=0.0000001)
1127+
1128+
# Set RunInfo measure_function (remember, it takes a Experiment object as a parameter and
1129+
# returns an ItemAttribute containing data).
1130+
runinfo.measure_function = get_voltage_data
1131+
1132+
# Create a Experiment class with the RunInfo and Devices just created
1133+
expt = ps.Experiment(runinfo, devices, time=True)
1134+
1135+
long_names = []
1136+
1137+
while len(long_names) < 3:
1138+
expt.run()
1139+
if len(long_names) == 0:
1140+
long_names.append(expt.runinfo.long_name)
1141+
elif (expt.runinfo.long_name[:15] == long_names[0][:15]):
1142+
long_names.append(expt.runinfo.long_name)
1143+
else:
1144+
long_names = [expt.runinfo.long_name]
1145+
1146+
err_str = f"First long name '{long_names[0]}' does not match expected date/time format."
1147+
assert re.match(r'^\d{8}T\d{6}$', long_names[0]), err_str
1148+
err_str = f"-1 long name '{long_names[1]}' does not match expected increment or format."
1149+
assert long_names[1] == long_names[0] + '-1', err_str
1150+
err_str = f"-2 long name '{long_names[1]}' does not match expected increment or format."
1151+
assert long_names[2] == long_names[0] + '-2', err_str
1152+
1153+
for name in long_names:
1154+
save_path = expt.runinfo.data_path / '{}.hdf5'.format(name)
1155+
assert os.path.exists(save_path), f"Expected file at path'{save_path}' was not found."

0 commit comments

Comments
 (0)