1515# and labscript. The device is a PseudoclockDevice, and can be the sole device
1616# in a connection table or experiment.
1717
18- import labscript_utils .h5_lock
19- import h5py
20- from labscript import PseudoclockDevice , Pseudoclock , ClockLine
18+ from labscript import PseudoclockDevice , Pseudoclock , ClockLine , config , LabscriptError
19+ import numpy as np
2120
2221
2322class DummyPseudoclock (PseudoclockDevice ):
2423
2524 description = 'Dummy pseudoclock'
26- clock_limit = 1e6
27- clock_resolution = 1e-6
25+ clock_limit = 10e6
26+ clock_resolution = 25e-9
27+ clock_type = 'fast clock'
28+ trigger_delay = 350e-9
29+ wait_delay = 2.5e-6
30+ allowed_children = None
31+ max_instructions = 1e5
2832
29- def __init__ (self , name = 'dummy_pseudoclock' , BLACS_connection = 'dummy_connection' , ** kwargs ):
33+ def __init__ (
34+ self , name = 'dummy_pseudoclock' , BLACS_connection = 'dummy_connection' , ** kwargs
35+ ):
3036 self .BLACS_connection = BLACS_connection
3137 PseudoclockDevice .__init__ (self , name , None , None , ** kwargs )
32- self .pseudoclock = Pseudoclock (self .name + '_pseudoclock' , self , 'pseudoclock' )
33- self .clockline = ClockLine (name = 'clockline' , pseudoclock = self .pseudoclock , connection = 'dummy' )
38+ self ._pseudoclock = Pseudoclock (
39+ name = f'{ name } _pseudoclock' ,
40+ pseudoclock_device = self ,
41+ connection = 'pseudoclock' ,
42+ )
43+ self ._clock_line = ClockLine (
44+ name = f'{ name } _clock_line' ,
45+ pseudoclock = self .pseudoclock ,
46+ connection = 'internal' ,
47+ )
48+
49+ @property
50+ def pseudoclock (self ):
51+ return self ._pseudoclock
52+
53+ @property
54+ def clockline (self ):
55+ return self ._clock_line
3456
3557 def generate_code (self , hdf5_file ):
3658 PseudoclockDevice .generate_code (self , hdf5_file )
3759 group = self .init_device_group (hdf5_file )
38- self .set_property ('stop_time' , self .stop_time , location = 'device_properties' )
60+
61+ # Compress clock instructions with the same period
62+ # This will halve the number of instructions roughly,
63+ # since the DummyPseudoclock does not have a 'slow clock'
64+ reduced_instructions = []
65+ for instruction in self .pseudoclock .clock :
66+ if instruction == 'WAIT' :
67+ # The following period and reps indicates a wait instruction
68+ reduced_instructions .append ({'period' : 0 , 'reps' : 1 })
69+ continue
70+ reps = instruction ['reps' ]
71+ # period is in quantised units:
72+ period = int (round (instruction ['step' ] / self .clock_resolution ))
73+ if reduced_instructions and reduced_instructions [- 1 ]['period' ] == period :
74+ reduced_instructions [- 1 ]['reps' ] += reps
75+ else :
76+ reduced_instructions .append ({'period' : period , 'reps' : reps })
77+ # The following period and reps indicates a stop instruction:
78+ reduced_instructions .append ({'period' : 0 , 'reps' : 0 })
79+ if len (reduced_instructions ) > self .max_instructions :
80+ raise LabscriptError (
81+ "%s %s has too many instructions. It has %d and can only support %d"
82+ % (
83+ self .description ,
84+ self .name ,
85+ len (reduced_instructions ),
86+ self .max_instructions ,
87+ )
88+ )
89+ # Store these instructions to the h5 file:
90+ dtypes = [('period' , int ), ('reps' , int )]
91+ pulse_program = np .zeros (len (reduced_instructions ), dtype = dtypes )
92+ for i , instruction in enumerate (reduced_instructions ):
93+ pulse_program [i ]['period' ] = instruction ['period' ]
94+ pulse_program [i ]['reps' ] = instruction ['reps' ]
95+ group .create_dataset (
96+ 'PULSE_PROGRAM' , compression = config .compression , data = pulse_program
97+ )
98+ # TODO: is this needed, the PulseBlasters don't save it...
99+ self .set_property (
100+ 'is_master_pseudoclock' ,
101+ self .is_master_pseudoclock ,
102+ location = 'device_properties' ,
103+ )
104+ self .set_property ('stop_time' , self .stop_time , location = 'device_properties' )
0 commit comments