-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathex04_callbacks.py
63 lines (51 loc) · 1.82 KB
/
ex04_callbacks.py
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
# Example 4: Callbacks
#
# How to set a device value at the start of each scan point using the
# `set_scan_point()` callback.
from artiq.experiment import *
from scan_framework import *
class Example4Scan(Scan1D, EnvExperiment):
def build(self):
super().build()
self.scan_arguments()
self.setattr_argument('frequencies', Scannable(
default=RangeScan(
start=0,
stop=7,
npoints=8
),
unit='Hz',
scale=1
))
self.setattr_device('dds0')
def prepare(self):
self.model = Example4Model(self)
self.register_model(self.model, measurement=True, fit=True)
def get_scan_points(self):
return self.frequencies
@kernel
def initialize_devices(self):
self.core.reset()
# 1. Create a `set_scan_point()` method.
# The set_scan_point() callback is called once at the start of each scan point,
# before your measure() method is repeated multiple times.
@kernel
def set_scan_point(self, i_point, frequency):
# `i_point` is set to the index of the current scan point.
# `frequency` is set to the value of the current scan point.
print("callback: set_scan_point")
print(i_point)
print(frequency)
# Note: `set_scan_point()` is typically used to set a device to the value of the current
# scan point.
self.core.break_realtime()
self.dds0.set(frequency)
@kernel
def measure(self, frequency):
# Note: The scan point index is always available at self._i_point when it is not passed in as
# an argument.
print(self._i_point)
return int(frequency ** 2.0)
class Example4Model(ScanModel):
namespace = "example_4"
fit_function = curvefits.Power