-
Notifications
You must be signed in to change notification settings - Fork 135
monkeypatching or overriding PYNQ drivers for testing
Sometimes you want to temporarily modify the behavior of a PYNQ driver class for testing/development, without directly making changes to files in the QICK library.
In this dumb example, I want to modify the configure_connections() method of qick.drivers.readout.MrBufferEt, because I am using that IP in a testing firmware that doesn't wire it in the usual way. For my tests I am going to control the DMA and other IPs directly, not through the MR buffer's driver, so I am happy to just disable configure_connections() so I can load the firmware without the software giving me an error.
Crude and easy way: monkeypatch to replace the method with my own.
def configure_connections(self, soc):
print("configure_connections is overridden")
pass
from qick.drivers.readout import MrBufferEt
MrBufferEt.configure_connections = configure_connections
More complicated way: subclass the driver and register my driver as the one that PYNQ will use when the firmware is loaded. This is more work but might be necessary for more complex changes to the driver's behavior.
from pynq import overlay
def register_driver(driver): # manually register a new driver - copied from pynq.overlay.RegisterIP
for x in driver.bindto:
overlay._ip_drivers[x] = driver
overlay._ip_drivers[x.rpartition(":")[0]] = driver
class MrBufferOverride(MrBufferEt):
def configure_connections(self, soc):
print("configure_connections is overridden")
pass
register_driver(MrBufferOverride)
Either way, when I initialize QickSoc I should see the printout showing that my overriden method is being called.