Skip to content

Commit ffdb633

Browse files
committed
Formating and style
1 parent 0a9e6e1 commit ffdb633

File tree

6 files changed

+114
-102
lines changed

6 files changed

+114
-102
lines changed

exopy_pulses/pulses/shapes/gaussian_shape.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# -----------------------------------------------------------------------------
3-
# Copyright 2015-2018 by ExopyPulses Authors, see AUTHORS for more details.
3+
# Copyright 2015-2021 by ExopyPulses Authors, see AUTHORS for more details.
44
#
55
# Distributed under the terms of the BSD license.
66
#
@@ -25,6 +25,8 @@ class GaussianShape(AbstractShape):
2525
"""
2626
#: Amplitude of the pulse this should be a number between -1.0 and 1.0
2727
amplitude = Str('1.0').tag(pref=True, feval=Feval(types=Real))
28+
29+
#: Sigma of gaussian pulse, units are AWG context units
2830
sigma = Str('10.0').tag(pref=True, feval=Feval(types=Real))
2931

3032
def eval_entries(self, root_vars, sequence_locals, missing, errors):

exopy_pulses/pulses/shapes/tanh_shape.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# -----------------------------------------------------------------------------
3-
# Copyright 2015-2018 by ExopyPulses Authors, see AUTHORS for more details.
3+
# Copyright 2015-2021 by ExopyPulses Authors, see AUTHORS for more details.
44
#
55
# Distributed under the terms of the BSD license.
66
#
@@ -20,11 +20,13 @@
2020

2121

2222
class TanhShape(AbstractShape):
23-
""" Atan pulse with a variable amplitude and sigma.
23+
""" Tanh pulse with a variable amplitude and sigma.
2424
2525
"""
2626
#: Amplitude of the pulse this should be a number between -1.0 and 1.0
2727
amplitude = Str('1.0').tag(pref=True, feval=Feval(types=Real))
28+
29+
#: Sigma of tanh pulse, basically raising time, units are AWG context units
2830
sigma = Str('10.0').tag(pref=True, feval=Feval(types=Real))
2931

3032
def eval_entries(self, root_vars, sequence_locals, missing, errors):

exopy_pulses/pulses/shapes/views/gaussian_shape_view.enaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# -----------------------------------------------------------------------------
3-
# Copyright 2015-2018 by ExopyPulses Authors, see AUTHORS for more details.
3+
# Copyright 2015-2021 by ExopyPulses Authors, see AUTHORS for more details.
44
#
55
# Distributed under the terms of the BSD license.
66
#

exopy_pulses/pulses/shapes/views/tanh_shape_view.enaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# -----------------------------------------------------------------------------
3-
# Copyright 2015-2018 by ExopyPulses Authors, see AUTHORS for more details.
3+
# Copyright 2015-2021 by ExopyPulses Authors, see AUTHORS for more details.
44
#
55
# Distributed under the terms of the BSD license.
66
#

exopy_pulses/tasks/tasks/instrs/transfer_pulse_loop_task.py

Lines changed: 97 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# -----------------------------------------------------------------------------
3-
# Copyright 2015-2016 by ExopyHqcLegacy Authors, see AUTHORS for more details.
3+
# Copyright 2015-2021 by ExopyHqcLegacy Authors, see AUTHORS for more details.
44
#
55
# Distributed under the terms of the BSD license.
66
#
@@ -25,7 +25,6 @@ class TransferPulseLoopTask(InstrumentTask):
2525
"""Build and transfer a pulse sequence to an instrument.
2626
2727
"""
28-
2928
#: Sequence path for the case of sequence simply referenced.
3029
sequence_path = Str().tag(pref=True)
3130

@@ -38,9 +37,14 @@ class TransferPulseLoopTask(InstrumentTask):
3837
#: Global variable to use for the sequence.
3938
sequence_vars = Typed(OrderedDict, ()).tag(pref=(ordered_dict_to_pref,
4039
ordered_dict_from_pref))
41-
40+
4241
#: operation mode of the awg
43-
operation = Enum('Clean, Load & Enqueue', 'Clean & Load', 'Load', 'Load & Enqueue all').tag(pref=True)
42+
operation = Enum(
43+
'Clean, Load & Enqueue',
44+
'Clean & Load',
45+
'Load',
46+
'Load & Enqueue all').tag(
47+
pref=True)
4448

4549
#: Loop variables: channels on which the loop will be done, loop parameters
4650
#: names, start value, stop value and number of points per loop
@@ -50,55 +54,55 @@ class TransferPulseLoopTask(InstrumentTask):
5054
loop_stop = Str('0').tag(pref=True)
5155

5256
loop_points = Str('2').tag(pref=True)
53-
57+
5458
#: run mode of the awg
5559
run_mode = Enum('Ext Trig', 'Int Trig', 'Continuous').tag(pref=True)
5660

5761
#: Internal trigger period in mus
5862
trigger_period = Str('20').tag(pref=True)
59-
63+
6064
parameters = Typed(OrderedDict, ()).tag(pref=[ordered_dict_to_pref,
61-
ordered_dict_from_pref])
62-
65+
ordered_dict_from_pref])
66+
6367
database_entries = set_default({'num_loop': 1})
6468

65-
# def check(self, *args, **kwargs):
66-
# """Check that the sequence can be compiled.
67-
#
68-
# """
69-
# test, traceback = super(TransferPulseLoopTask,
70-
# self).check(*args, **kwargs)
71-
# err_path = self.path + '/' + self.name + '-'
72-
#
73-
# msg = 'Failed to evaluate {} ({}): {}'
74-
# seq = self.sequence
75-
# for k, v in self.sequence_vars.items():
76-
# try:
77-
# seq.external_vars[k] = self.format_and_eval_string(v)
78-
# except Exception:
79-
# test = False
80-
# traceback[err_path+k] = msg.format(k, v, format_exc())
81-
#
82-
# if not test:
83-
# return test, traceback
84-
#
85-
# context = seq.context
86-
# res, infos, errors = context.compile_and_transfer_sequence(seq)
87-
#
88-
# if not res:
89-
# traceback[err_path+'compil'] = errors
90-
# return False, traceback
91-
#
92-
# for k, v in infos.items():
93-
# self.write_in_database(k, v)
94-
#
95-
# if self.sequence_path:
96-
# if not (self.sequence_timestamp ==
97-
# os.path.getmtime(self.sequence_path)):
98-
# msg = 'The sequence is outdated, consider refreshing it.'
99-
# traceback[err_path+'outdated'] = msg
100-
#
101-
# return test, traceback
69+
def check(self, *args, **kwargs):
70+
"""Check that the sequence can be compiled.
71+
72+
"""
73+
test, traceback = super(TransferPulseLoopTask,
74+
self).check(*args, **kwargs)
75+
err_path = self.path + '/' + self.name + '-'
76+
77+
msg = 'Failed to evaluate {} ({}): {}'
78+
seq = self.sequence
79+
for k, v in self.sequence_vars.items():
80+
try:
81+
seq.external_vars[k] = self.format_and_eval_string(v)
82+
except Exception:
83+
test = False
84+
traceback[err_path + k] = msg.format(k, v, format_exc())
85+
86+
if not test:
87+
return test, traceback
88+
89+
context = seq.context
90+
res, infos, errors = context.compile_and_transfer_sequence(seq)
91+
92+
if not res:
93+
traceback[err_path + 'compil'] = errors
94+
return False, traceback
95+
96+
for k, v in infos.items():
97+
self.write_in_database(k, v)
98+
99+
if self.sequence_path:
100+
if not (self.sequence_timestamp ==
101+
os.path.getmtime(self.sequence_path)):
102+
msg = 'The sequence is outdated, consider refreshing it.'
103+
traceback[err_path + 'outdated'] = msg
104+
105+
return test, traceback
102106

103107
def perform(self):
104108
"""Compile the sequence.
@@ -107,35 +111,31 @@ def perform(self):
107111
operation = self.operation
108112
seq = self.sequence
109113
context = seq.context
110-
if self.run_mode=='Int Trig':
114+
if self.run_mode == 'Int Trig':
111115
internal_trigger = True
112-
else:
116+
else:
113117
internal_trigger = False
114118

115119
self.driver.internal_trigger = internal_trigger
116120
if internal_trigger:
117-
self.driver.internal_trigger_period = int(float(self.trigger_period) * 1000)
118-
121+
self.driver.internal_trigger_period = int(
122+
float(self.trigger_period) * 1000)
123+
119124
self.driver.clear_all_sequences()
120125
if operation in ['Clean, Load & Enqueue', 'Clean & Load']:
121126
self.driver.delete_all_waveforms()
122127
first_index = 1
123-
# print("First index shoud be %d"%first_index)
124128
else:
125129
n_remaining_wf = self.driver.get_waveform_number()
126-
# print('Remaining of waveforms = '+str(n_remaining_wf))
127-
last_wf = str(self.driver.get_waveform_name(n_remaining_wf-1))
130+
last_wf = str(self.driver.get_waveform_name(n_remaining_wf - 1))
128131
last_wf = last_wf.split('_')
129-
first_index = int(last_wf[1])+1
130-
# print("First index shoud be %d"%first_index)
132+
first_index = int(last_wf[1]) + 1
131133

132134
_used_channels = []
133-
134135
loops = []
135136
name_parameters = []
136137
n_loops = len(self.parameters)
137-
# print(n_loops)
138-
if n_loops>0:
138+
if n_loops > 0:
139139
context.run_after_transfer = False
140140
context.select_after_transfer = False
141141
self.driver.run_mode = 'SEQUENCE'
@@ -145,72 +145,82 @@ def perform(self):
145145
loop_points = int(self.format_and_eval_string(params[1][2]))
146146
loops.append(np.linspace(loop_start, loop_stop, loop_points))
147147
name_parameters.append(params[0])
148-
self.write_in_database(params[0]+'_loop', np.linspace(loop_start, loop_stop, loop_points))
149-
150-
loop_values = np.moveaxis(np.array(np.meshgrid(*loops)),0,-1).reshape((-1,n_loops))
151-
if operation=='Clean, Load & Enqueue':
148+
self.write_in_database(
149+
params[0] + '_loop',
150+
np.linspace(
151+
loop_start,
152+
loop_stop,
153+
loop_points))
154+
155+
loop_values = np.moveaxis(
156+
np.array(np.meshgrid(*loops)), 0, -1).reshape((-1, n_loops))
157+
if operation == 'Clean, Load & Enqueue':
152158
self.write_in_database('num_loop', len(loop_values))
153159
for nn, loop_value in enumerate(loop_values):
154160
for ii, name_parameter in enumerate(name_parameters):
155161
self.write_in_database(name_parameter, loop_value[ii])
156162
for k, v in self.sequence_vars.items():
157163
seq.external_vars[k] = self.format_and_eval_string(v)
158-
context.sequence_name = '{}_{}'.format('', nn+first_index)
164+
context.sequence_name = '{}_{}'.format('', nn + first_index)
159165
res, infos, errors = context.compile_and_transfer_sequence(
160-
seq,
161-
driver=self.driver)
162-
if operation=='Clean, Load & Enqueue':
166+
seq,
167+
driver=self.driver)
168+
if operation == 'Clean, Load & Enqueue':
163169
for cc in range(4):
164-
_seq = 'sequence_ch'+str(cc+1)
170+
_seq = 'sequence_ch' + str(cc + 1)
165171
if infos[_seq]:
166-
self.driver.get_channel(cc+1).set_sequence_pos(infos[_seq],
167-
nn+1)
168-
_used_channels.append(cc+1)
169-
self.driver.set_jump_pos(nn+1, 1)
172+
self.driver.get_channel(
173+
cc +
174+
1).set_sequence_pos(
175+
infos[_seq],
176+
nn +
177+
1)
178+
_used_channels.append(cc + 1)
179+
self.driver.set_jump_pos(nn + 1, 1)
170180
self.driver.set_goto_pos(len(loop_values), 1)
171181
for cc in set(_used_channels):
172182
self.driver.get_channel(cc).output_state = 'on'
173-
183+
174184
if not res:
175185
raise Exception('Failed to compile sequence :\n' +
176186
pformat(errors))
177187
self.write_in_database(name_parameter, loop_value[ii])
178-
188+
179189
else:
180190
for k, v in self.sequence_vars.items():
181191
seq.external_vars[k] = self.format_and_eval_string(v)
182-
if self.run_mode=='Continuous':
192+
if self.run_mode == 'Continuous':
183193
self.driver.run_mode = 'CONT'
184194
else:
185195
self.driver.run_mode = 'TRIG'
186196
context.sequence_name = '{}_{}'.format('', first_index)
187-
res, infos, errors = context.compile_and_transfer_sequence(seq,
188-
self.driver)
197+
res, infos, errors = context.compile_and_transfer_sequence(
198+
seq, self.driver)
189199

190200
if not res:
191201
raise Exception('Failed to compile sequence :\n' +
192202
pformat(errors))
193-
203+
194204
for k, v in infos.items():
195205
self.write_in_database(k, v)
196-
197-
if operation=='Load & Enqueue all':
198-
n_wf = self.driver.get_waveform_number()-25
206+
207+
if operation == 'Load & Enqueue all':
208+
n_wf = self.driver.get_waveform_number() - 25
199209
channels_to_turn_on = set()
200210
for ii in range(n_wf):
201-
index = ii+25
211+
index = ii + 25
202212
current_wf = str(self.driver.get_waveform_name(index))
203213
current_ch = int(current_wf[-1])
204-
current_index = int(current_wf.split('_')[1])
214+
current_index = int(current_wf.split('_')[1])
205215
channels_to_turn_on.add(current_ch)
206-
self.driver.get_channel(current_ch).set_sequence_pos(current_wf,
207-
current_index)
216+
self.driver.get_channel(current_ch).set_sequence_pos(
217+
current_wf, current_index)
208218
self.driver.set_jump_pos(current_index, 1)
209219
self.driver.set_goto_pos(current_index, 1)
210220
self.write_in_database('num_loop', current_index)
211221
for cc in channels_to_turn_on:
212222
self.driver.get_channel(cc).output_state = 'on'
213-
223+
214224
def register_preferences(self):
215225
"""Register the task preferences into the preferences system.
216226
@@ -270,7 +280,7 @@ def _post_setattr_sequence(self, old, new):
270280

271281
if entries != self.database_entries:
272282
self.database_entries = entries
273-
283+
274284
def _post_setattr_parameters(self, old, new):
275285
"""Observer keeping the database entries in sync with the declared
276286
definitions.
@@ -279,10 +289,10 @@ def _post_setattr_parameters(self, old, new):
279289
entries = self.database_entries.copy()
280290
for e in old:
281291
del entries[e]
282-
del entries[e+'_loop']
292+
del entries[e + '_loop']
283293
for e in new:
284294
entries.update({key: 0.0 for key in new})
285-
entries.update({key+'_loop': 0.0 for key in new})
295+
entries.update({key + '_loop': 0.0 for key in new})
286296
self.database_entries = entries
287297

288298
def _update_database_entries(self, change):

0 commit comments

Comments
 (0)