Skip to content

Commit 18523a3

Browse files
committed
Python3_PhaseMatrixQuickSyn: Merge with default (incorporates arbitrary_subfolders and remove_workaround PRs)
2 parents 37d7f20 + 1d92bc4 commit 18523a3

26 files changed

+2813
-286
lines changed

AlazarTechBoard.py

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

Camera.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919
check_version('labscript', '2.0.1', '3')
2020

21-
from labscript_devices import labscript_device, BLACS_tab, BLACS_worker
21+
from labscript_devices import BLACS_tab
2222
from labscript import TriggerableDevice, LabscriptError, set_passed_properties
2323
import numpy as np
2424

25-
@labscript_device
25+
2626
class Camera(TriggerableDevice):
2727
description = 'Generic Camera'
2828

@@ -203,7 +203,7 @@ def update_responding_indicator(self, responding):
203203
self.ui.status_icon.setPixmap(pixmap)
204204
self.ui.server_status.setText(status_text)
205205

206-
@BLACS_worker
206+
207207
class CameraWorker(Worker):
208208
def init(self):#, port, host, use_zmq):
209209
# self.port = port

DummyIntermediateDevice.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#####################################################################
2+
# #
3+
# /DummyIntermediateDevice.py #
4+
# #
5+
# Copyright 2013, Monash University #
6+
# #
7+
# This file is part of labscript_devices, in the labscript suite #
8+
# (see http://labscriptsuite.org), and is licensed under the #
9+
# Simplified BSD License. See the license.txt file in the root of #
10+
# the project for the full license. #
11+
# #
12+
#####################################################################
13+
14+
from __future__ import division, unicode_literals, print_function, absolute_import
15+
from labscript_utils import PY2
16+
if PY2:
17+
str = unicode
18+
19+
# This file represents a dummy labscript device for purposes of testing BLACS
20+
# and labscript. The device is a Intermediate Device, and can be attached to
21+
# a pseudoclock in labscript in order to test the pseudoclock behaviour
22+
# without needing a real Intermediate Device.
23+
#
24+
# You can attach an arbitrary number of outputs to this device, however we
25+
# currently only support outputs of type AnalogOut and DigitalOut. I would be
26+
# easy to extend this is anyone needed further functionality.
27+
28+
29+
from labscript_devices import labscript_device, BLACS_tab, BLACS_worker
30+
from labscript import IntermediateDevice, DigitalOut, AnalogOut, config
31+
import numpy as np
32+
33+
@labscript_device
34+
class DummyIntermediateDevice(IntermediateDevice):
35+
36+
description = 'Dummy IntermediateDevice'
37+
clock_limit = 1e6
38+
39+
# If this is updated, then you need to update generate_code to support whatever types you add
40+
allowed_children = [DigitalOut, AnalogOut]
41+
42+
def __init__(self, name, parent, BLACS_connection='dummy_connection', **kwargs):
43+
self.BLACS_connection = BLACS_connection
44+
IntermediateDevice.__init__(self, name, parent, **kwargs)
45+
46+
def generate_code(self, hdf5_file):
47+
group = self.init_device_group(hdf5_file)
48+
49+
clockline = self.parent_device
50+
pseudoclock = clockline.parent_device
51+
times = pseudoclock.times[clockline]
52+
53+
# out_table = np.empty((len(times),len(self.child_devices)), dtype=np.float32)
54+
# determine dtypes
55+
dtypes = []
56+
for device in self.child_devices:
57+
if isinstance(device, DigitalOut):
58+
device_dtype = np.int8
59+
elif isinstance(device, AnalogOut):
60+
device_dtype = np.float64
61+
dtypes.append((device.name, device_dtype))
62+
63+
# create dataset
64+
out_table = np.zeros(len(times), dtype=dtypes)
65+
for device in self.child_devices:
66+
out_table[device.name][:] = device.raw_output
67+
68+
group.create_dataset('OUTPUTS', compression=config.compression, data=out_table)
69+
70+
71+
from blacs.device_base_class import DeviceTab
72+
from blacs.tab_base_classes import Worker
73+
74+
@BLACS_tab
75+
class DummyIntermediateDeviceTab(DeviceTab):
76+
def initialise_GUI(self):
77+
self.create_worker("main_worker",DummyIntermediateDeviceWorker,{})
78+
self.primary_worker = "main_worker"
79+
80+
@BLACS_worker
81+
class DummyIntermediateDeviceWorker(Worker):
82+
def init(self):
83+
pass
84+
85+
def program_manual(self, front_panel_values):
86+
return front_panel_values
87+
88+
def transition_to_buffered(self, device_name, h5file, initial_values, fresh):
89+
return initial_values
90+
91+
def transition_to_manual(self,abort = False):
92+
return True
93+
94+
def abort_transition_to_buffered(self):
95+
return self.transition_to_manual(True)
96+
97+
def abort_buffered(self):
98+
return self.transition_to_manual(True)
99+
100+
def shutdown(self):
101+
pass

DummyPseudoclock/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#####################################################################
2+
# #
3+
# /labscript_devices/DummyPseudoclock/__init__.py #
4+
# #
5+
# Copyright 2017, Christopher Billington #
6+
# #
7+
# This file is part of labscript_devices, in the labscript suite #
8+
# (see http://labscriptsuite.org), and is licensed under the #
9+
# Simplified BSD License. See the license.txt file in the root of #
10+
# the project for the full license. #
11+
# #
12+
#####################################################################
13+
from __future__ import division, unicode_literals, print_function, absolute_import
14+
from labscript_utils import PY2
15+
if PY2:
16+
str = unicode
17+
18+
from labscript_devices import deprecated_import_alias
19+
20+
21+
# For backwards compatibility with old experiment scripts:
22+
DummyPseudoclock = deprecated_import_alias(
23+
"labscript_devices.DummyPseudoclock.labscript_device.DummyPseudoclock"
24+
)

DummyPseudoclock/blacs_tab.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#####################################################################
2+
# #
3+
# /labscript_devices/DummyPseudoclock/blacs_tab.py #
4+
# #
5+
# Copyright 2017, Christopher Billington #
6+
# #
7+
# This file is part of labscript_devices, in the labscript suite #
8+
# (see http://labscriptsuite.org), and is licensed under the #
9+
# Simplified BSD License. See the license.txt file in the root of #
10+
# the project for the full license. #
11+
# #
12+
#####################################################################
13+
from __future__ import division, unicode_literals, print_function, absolute_import
14+
from labscript_utils import PY2
15+
if PY2:
16+
str = unicode
17+
from blacs.device_base_class import DeviceTab, define_state, MODE_BUFFERED
18+
19+
class DummyPseudoclockTab(DeviceTab):
20+
def initialise_workers(self):
21+
worker_initialisation_kwargs = {}
22+
self.create_worker(
23+
"main_worker",
24+
"labscript_devices.DummyPseudoclock.blacs_worker.DummyPseudoclockWorker",
25+
worker_initialisation_kwargs,
26+
)
27+
self.primary_worker = "main_worker"
28+
29+
@define_state(MODE_BUFFERED, True)
30+
def start_run(self, notify_queue):
31+
self.wait_until_done(notify_queue)
32+
33+
@define_state(MODE_BUFFERED, True)
34+
def wait_until_done(self, notify_queue):
35+
"""Call check_if_done repeatedly in the worker until the shot is complete"""
36+
done = yield (self.queue_work(self.primary_worker, 'check_if_done'))
37+
# Experiment is over. Tell the queue manager about it:
38+
if done:
39+
notify_queue.put('done')
40+
else:
41+
# Not actual recursion since this just queues up another call
42+
# after we return:
43+
self.wait_until_done(notify_queue)
44+

DummyPseudoclock/blacs_worker.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#####################################################################
2+
# #
3+
# /labscript_devices/DummyPseudoclock/blacs_worker.py #
4+
# #
5+
# Copyright 2017, Christopher Billington #
6+
# #
7+
# This file is part of labscript_devices, in the labscript suite #
8+
# (see http://labscriptsuite.org), and is licensed under the #
9+
# Simplified BSD License. See the license.txt file in the root of #
10+
# the project for the full license. #
11+
# #
12+
#####################################################################
13+
from __future__ import division, unicode_literals, print_function, absolute_import
14+
from labscript_utils import PY2
15+
if PY2:
16+
str = unicode
17+
import time
18+
import labscript_utils.h5_lock
19+
import h5py
20+
from blacs.tab_base_classes import Worker
21+
import labscript_utils.properties as properties
22+
23+
class DummyPseudoclockWorker(Worker):
24+
def program_manual(self, values):
25+
return {}
26+
27+
def transition_to_buffered(self, device_name, h5file, initial_values, fresh):
28+
# get stop time:
29+
with h5py.File(h5file, 'r') as f:
30+
props = properties.get(f, self.device_name, 'device_properties')
31+
self.stop_time = props.get('stop_time', None) # stop_time may be absent if we are not the master pseudoclock
32+
return {}
33+
34+
def check_if_done(self):
35+
# Wait up to 1 second for the shot to be done, returning True if it is
36+
# or False if not.
37+
if getattr(self, 'start_time', None) is None:
38+
self.start_time = time.time()
39+
timeout = min(self.start_time + self.stop_time - time.time(), 1)
40+
if timeout < 0:
41+
return True
42+
time.sleep(timeout)
43+
return self.start_time + self.stop_time < time.time()
44+
45+
def transition_to_manual(self):
46+
self.start_time = None
47+
self.stop_time = None
48+
return True
49+
50+
def shutdown(self):
51+
return
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
#####################################################################
22
# #
3-
# /labscript_devices/DummyPseudoclock.py #
3+
# /labscript_devices/DummyPseudoclock/DummyPseudoclock.py #
44
# #
5-
# Copyright 2017, Joint Quantum Institute #
5+
# Copyright 2017, Christopher Billington #
66
# #
77
# This file is part of labscript_devices, in the labscript suite #
88
# (see http://labscriptsuite.org), and is licensed under the #
99
# Simplified BSD License. See the license.txt file in the root of #
1010
# the project for the full license. #
1111
# #
1212
#####################################################################
13+
from __future__ import division, unicode_literals, print_function, absolute_import
14+
from labscript_utils import PY2
15+
if PY2:
16+
str = unicode
1317

1418
# This file represents a dummy labscript device for purposes of testing BLACS
1519
# and labscript. The device is a PseudoclockDevice, and can be the sole device
1620
# in a connection table or experiment.
1721

18-
19-
from labscript_devices import labscript_device, BLACS_tab, BLACS_worker
22+
import labscript_utils.h5_lock
23+
import h5py
2024
from labscript import PseudoclockDevice, Pseudoclock, ClockLine
2125

22-
@labscript_device
26+
2327
class DummyPseudoclock(PseudoclockDevice):
2428

2529
description = 'Dummy pseudoclock'
@@ -34,33 +38,4 @@ def __init__(self, name='dummy_pseudoclock', BLACS_connection='dummy_connection'
3438

3539
def generate_code(self, hdf5_file):
3640
group = self.init_device_group(hdf5_file)
37-
38-
39-
from blacs.device_base_class import DeviceTab, define_state, MODE_BUFFERED
40-
from blacs.tab_base_classes import Worker
41-
42-
43-
@BLACS_tab
44-
class DummyPseudoclockTab(DeviceTab):
45-
def initialise_workers(self):
46-
worker_initialisation_kwargs = {}
47-
self.create_worker("main_worker", DummyPseudoclockWorker, worker_initialisation_kwargs)
48-
self.primary_worker = "main_worker"
49-
50-
@define_state(MODE_BUFFERED, True)
51-
def start_run(self, notify_queue):
52-
notify_queue.put('done')
53-
54-
@BLACS_worker
55-
class DummyPseudoclockWorker(Worker):
56-
def program_manual(self, values):
57-
return {}
58-
59-
def transition_to_buffered(self, device_name, h5file, initial_values, fresh):
60-
return {}
61-
62-
def transition_to_manual(self):
63-
return True
64-
65-
def shutdown(self):
66-
return
41+
self.set_property('stop_time', self.stop_time, location='device_properties')
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#####################################################################
2+
# #
3+
# /labscript_devices/DummyPseudoclock/register_classes.py #
4+
# #
5+
# Copyright 2017, Christopher Billington #
6+
# #
7+
# This file is part of labscript_devices, in the labscript suite #
8+
# (see http://labscriptsuite.org), and is licensed under the #
9+
# Simplified BSD License. See the license.txt file in the root of #
10+
# the project for the full license. #
11+
# #
12+
#####################################################################
13+
import labscript_devices
14+
15+
labscript_devices.register_classes(
16+
'DummyPseudoclock',
17+
BLACS_tab='labscript_devices.DummyPseudoclock.blacs_tab.DummyPseudoclockTab',
18+
runviewer_parser=None, #TODO make a runviwer parser for Dummy pseudoclock!
19+
)

NIBoard.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
from __future__ import division, unicode_literals, print_function, absolute_import
2+
from labscript_utils import PY2
3+
if PY2:
4+
str = unicode
5+
16
import numpy as np
27
from labscript_devices import runviewer_parser
38
from labscript import IntermediateDevice, AnalogOut, DigitalOut, AnalogIn, bitfield, config, LabscriptError, set_passed_properties
49
import labscript_utils.h5_lock, h5py
510
import labscript_utils.properties
11+
from labscript_utils.numpy_dtype_workaround import dtype_workaround
612

713
class NIBoard(IntermediateDevice):
814
allowed_children = [AnalogOut, DigitalOut, AnalogIn]
@@ -60,7 +66,7 @@ def generate_code(self, hdf5_file):
6066
times = pseudoclock.times[clockline]
6167

6268
analog_out_table = np.empty((len(times),len(analogs)), dtype=np.float32)
63-
analog_connections = analogs.keys()
69+
analog_connections = list(analogs.keys())
6470
analog_connections.sort()
6571
analog_out_attrs = []
6672
for i, connection in enumerate(analog_connections):
@@ -72,7 +78,7 @@ def generate_code(self, hdf5_file):
7278
'the limit imposed by %s.'%self.name)
7379
analog_out_table[:,i] = output.raw_output
7480
analog_out_attrs.append(self.MAX_name +'/'+connection)
75-
input_connections = inputs.keys()
81+
input_connections = list(inputs.keys())
7682
input_connections.sort()
7783
input_attrs = []
7884
acquisitions = []
@@ -84,14 +90,14 @@ def generate_code(self, hdf5_file):
8490
# characters. Can't imagine this would be an issue, but to not
8591
# specify the string length (using dtype=str) causes the strings
8692
# to all come out empty.
87-
acquisitions_table_dtypes = [('connection','a256'), ('label','a256'), ('start',float),
88-
('stop',float), ('wait label','a256'),('scale factor',float), ('units','a256')]
93+
acquisitions_table_dtypes = dtype_workaround([('connection','a256'), ('label','a256'), ('start',float),
94+
('stop',float), ('wait label','a256'),('scale factor',float), ('units','a256')])
8995
acquisition_table= np.empty(len(acquisitions), dtype=acquisitions_table_dtypes)
9096
for i, acq in enumerate(acquisitions):
9197
acquisition_table[i] = acq
9298
digital_out_table = []
9399
if digitals:
94-
digital_out_table = self.convert_bools_to_bytes(digitals.values())
100+
digital_out_table = self.convert_bools_to_bytes(list(digitals.values()))
95101
grp = self.init_device_group(hdf5_file)
96102
if all(analog_out_table.shape): # Both dimensions must be nonzero
97103
grp.create_dataset('ANALOG_OUTS',compression=config.compression,data=analog_out_table)

0 commit comments

Comments
 (0)