METHOD_OPTIONS¶
This details the methods to be used in the script and is a required section.
Example METHOD_OPTIONS from a Fit Script¶
METHOD_OPTIONS:
# Python module required to process this script file
py_module: fit
# Option to set seed to make run result
# reproducible -e.g. when debugging.
# rand_seed: 12345
rand_seed: auto
# Format string for numerical output
float_format: default
Main METHOD_OPTIONS Fields¶
py_module¶
When calling this script using popy_run, PoPy needs to know which type of script is being called. This is determined by the ‘py_module’ field.
In the example above a ‘fit’ script is specified. Other possible entries are ‘fit’, ‘tut’, ‘gen’, ‘mtut’ etc. See Script File Formats for more information.
rand_seed¶
There are two types of scripts run by PoPy:-
- Deterministic - given the same inputs the same outputs are always returned
- Stochastic - given the same inputs the result are dependent on a random number generator
For example a Gen Script is inherently stochastic. Whereas a Fit Script using the JOE, FOCE or ND fitting method is inherently deterministic.
When running a stochastic method you have two options, this setting:-
rand_seed: auto
Will ensure that the random number generator is seeded with a different random number, every time the script is run. This will generate different output each time. Alternatively you set the seed explicitly:-
rand_seed: 314159
This will initialise the pseudorandom number generator with the value ‘314159’, which will then generate the same output every time, given the same inputs. For more information on seeding and pseudorandom number generators, see Wikipedia page:-
http://en.wikipedia.org/wiki/Random_seed
Note: if your script is deterministic then the ‘rand_seed’ setting will have no effect.
float_format¶
This field allows you to control how numbers output by PoPy are rendered as strings. If you leave this field out it defaults to:-
float_format: default
This has the effect of outputting float values to 4 decimal places. Table 69 shows both named float formats.
Entry | Format String | Example Input | Example Output |
---|---|---|---|
default | .4F | 1.0123456 | ‘1.0123’ |
2 decimal places in exponent format | .2E | 1.0123456 | ‘1.01E+00’ |
You can also specify your own custom format, e.g. ‘.3G’ for 3 significant figures in general format or ‘.6F’ for 6 decimal places in float point format or ‘.4E’ for 4 decimal places in exponent format. Examples of different format strings on the Python command prompt are:-
>>> '{:.4E}'.format(1.0123456)
'1.0123E+00'
>>> '{:.6F}'.format(1.0123456)
'1.012346'
>>> '{:.3G}'.format(1.0123456)
'1.01'
You can experiment with your own formatting. See the rather esoteric instructions here:-
https://docs.python.org/3.4/library/string.html#format-specification-mini-language
Setting the output to six decimal places in PoPy could be achieved by:-
float_format: .6F
Note that PoPy adds the prefix ‘{:’ and the suffix ‘}’ to your ‘float_format’ config file entry.