A tool for specifying calculations that depend on other calculations that depend on other calculations...
matlab_makefile uses a target.m file and a context matlab structure.
-
The
targets.mfile specifies which targets depend on which, what functions should be called to build each target, whether the built target should be saved to disk, and how to calculate the paths where results should be saved. Targets are not rebuilt if they can be loaded from disk. -
contextis a matlab structure which contains contextual information: which data set is being used, with which parameters, etc. Information incontextis also used to calculate file and folder names where results will be stored.
See examples/targets.m for an example of a target file. Note that
the target file MUST be called targets.m
Informally, the grammar for a target is:
<target> = [':' <target>] Example: :target1
<target> = { @make_function (list of <target>s) }
<target> = a matlab expression that doesn't match the above 2 rules
-
:target1stands for 'the result of calculating target1' -
{ @make_function (list of <target>s) }stands for the result of callingmake_functionwith the results from evaluating the list of targets as arguments. -
Any matlab expression which is not of these two forms stands for itself.
-
write a
targets.mfile. see next section andexample/targets.m -
context = initialize_context() ; -
add whatever contextual information you like as additional fields in
context -
[result,context] = make_target('my_targets_*', context) ;
this will build all targets in targets.m that match pattern
'my_targets_*', using the additional info in context
-
SAVE_HERE.ROOT_DIRECTORY: root directory where results are saved (string) -
SAVE_HERE.USING_FOLDERS: N-by-2 cell array specifying in which subdirectory ofSAVE_HERE.ROOT_DIRECTORYeach result is saved. Each row corresponds to a pair ( dependency , folder ) where -dependencyis a string, the name of a target -folderis a function of the context which returns a string, the folder name corresponding todependency. An example ofSAVE_HERE.USING_FOLDERSwith a single dependency could be:SAVE_HERE.USING_FOLDERS = {'DataSet' @(context)sprintf('DataSet_%d',context.DataSetNumber)}The result of a calculation which depends on the data set number (42) will be saved inROOT_DIRECTORY/DataSet_42, whereas the result of a calcuation which does not depend on a data set number will be saved inROOT_DIRECTORY/. -
t: a structure containing all targets. Examples: -t.target0.SAVE = { @make_target0 ':target2' 10 ':target4' } ;Here,target0will be saved to disk because it has the field.SAVE. It will be built by calling the functionmake_target0with 3 arguments: the result of buildingtarget2, the number 10, and the result of buildingtarget4. -t.target1 = matlab expression exp1the result target1 is the result of matlab expression exp1. The result is not saved to disk, but it is saved in memory inside context.STORE
Evaluating :target1 starts with the definition t.target1, which can
take two froms:
-
t.target1 = :some_other_targetsome_other_targetis first sought ascontext.some_other_target.Ifsome_other_targetit is not a field ofcontextit is sought ascontext.STORE.some_other_target, where previous builds have been stored. If it is not found there andt.target1has field.SAVEit is sought on disk with filenametarget1.matin the folder calculated usingcontextwithSAVE_HERE.ROOT_DIRECTORYandSAVE_HERE.USING_FOLDERS.Iftarget1.matwas not found at that location, thensome_other_targetis calculated using the rulet.some_other_target. -
t.target1 = { @make_function (list of <target>s) }each target in the list of arguments is retrieved from
context,context.STORE, from disk, or rebuilt (as above), and thenmake_functionis called with these as arguments.