Draft: Realtime decorator
Description
This is a proof-of-principle realtime decorator to include multiple realtime devices and allowing for preprocessing kernel code, like precalculating processing heavy arbitrary waveforms (which are fully known before the realtime part), by using the abstract syntax tree as a meta language.
It uses a visitor scheme to split each function which is decorated by realtime into multiple functions for the host and the separate realtime devices.
The following example:
@realtime
def prechunk_host(self, points):
# I use a host function here because it needs to be started from the host.
self.test(points)
@realtime
def test(self, points):
self.core.break_realtime()
delay(1*aq.s)
self.test_ttl.ttl.pulse(10*aq.us)
self.log.info("Current time is {} mu",[self.core.get_rtio_counter_mu(),])
self.log.info("General information",[])
# this does not work yet as function not yet constucted when parsing `test`
# self.log.info("{}",[self.prechunk_host__host.__str__(),])
# This does not work as not know during introspect
# baum = self.test_ttl.ttl.pulse
# baum(10*aq.us)
is parsed into:
@realtime
def prechunk_host(self, points):
self.prechunk_host__host(self, points)
self.prechunk_host__artiq(self, points)
def prechunk_host__host(self, points):
self.test__host(self,points)
@kernel
def prechunk_host__artiq(self, points):
self.test__artiq(self,points)
def test__host(self, points):
self.log.info("General information",[])
@kernel
def test__artiq(self, points):
self.core.break_realtime()
delay(1*aq.s)
self.test_ttl.ttl.pulse(10*aq.us)
self.log.info("Current time is {} mu",[self.core.get_rtio_counter_mu(),])
self.log.info("General information",[])
By using the standard python ast as an intermediate language we are probably limited at some point (at least artiq have run into some limits so they developed their own parser), however the visitor scheme is quite general and we could, if needed, develop our own meta language later on as a replacement.
There are still a lot of open points and this only poses as a proof of principle to discuss the further development of %Implement Other Realtime Hardware. A production implementation will probably require building it again from the ground up once we discussed the goals and implementation details of it.
Type of change
Please delete options that are not relevant.
-
New feature (non-breaking change which adds functionality)
Checklist:
-
I have performed a self-review of my code -
I have commented my code, particularly in hard-to-understand areas -
I have made corresponding changes to the documentation