hiker/fab

Support different optimisation scripts for PSyclone

Closed this issue · 1 comments

ATM only one, hard-coded optimistaion script can be specified, while the whole design idea of PSyclone is that one can have file-specific scripts.

Support for different scripts could be added by replacing the script name with a function. This function would be called from FAB before invoking PSyclone for a file (with the file-path as parameter), and it would return the name of the script to use (or None if there is no script). It would be the responsibility for this called function to return a default (global.py) if no file-specific path is specified.

Note that a method of a class can be used as a callback without a problem, i.e.:

class C:
	def callback(self, x):
		print("class callback", x)

def do_psyclone(func):
        # Do the callback to the user-supplied function - even though it's not called as a method (i.e. no self)
        # if the function is a method, Python will provide the right "self"
	func(1)

c = C()
do_psyclone(c.callback)

A bit convoluted, but it means in the context of the LFRic FAB framework, we can implement the function in our OO framework, and when calling FAB's psyclone function, we can use this method, and the it will be called as expected, including getting the correct self. This will also allow a site-specific script to overwrite this function.

I would suggest that for now we maintain backward compatibility. Two options here:

  1. we test the type of the script name parameter, if it's not a string (or if it's callable, which I believe can be tested), we call it to get the script name to use.
  2. We add another optional parameter (script_callback or so???). And we test that only ever one of script and script_callback is defined, and then use the one that is defined.

I can't see much of a difference in either.