In this tutorial we show how to globally controll the default runner. First we import oommfc
.
import oommfc
oommfc
has a special member oommfc.runner
that provides information and control about the default runner and how it is chosen.
oommfc.runner
OOMMF runner: UNSET runner is cached: True
When we import oommfc
the OOMMF runner
is unset. The runner is chosen automatically when we first ask for oommfc.runner.runner
.
# NBVAL_IGNORE_OUTPUT
oommfc.runner.runner
ExeOOMMFRunner(/opt/miniconda3/envs/ubermag-dev/bin/oommf)
Now we have a default runner. The same does also happen in the background when creating a driver
object and calling its drive
method without explicitly passing a runner.
A subsequent call to oommfc.runner
shows the default runner.
# NBVAL_IGNORE_OUTPUT
oommfc.runner
OOMMF runner: ExeOOMMFRunner(/opt/miniconda3/envs/ubermag-dev/bin/oommf) runner is cached: True
We can also see, that the default runner is cached. This is controlled by:
oommfc.runner.cache_runner
True
The default values for the envvar OOMMFTCL
, the executable oommf
, and the docker
executable can also be controlled via the runner
object. They default to:
oommfc.runner.envvar
'OOMMFTCL'
oommfc.runner.oommf_exe
'oommf'
oommfc.runner.docker_exe
'docker'
Our current runner is:
# NBVAL_IGNORE_OUTPUT
oommfc.runner
OOMMF runner: ExeOOMMFRunner(/opt/miniconda3/envs/ubermag-dev/bin/oommf) runner is cached: True
We can change the default runner by assigning an new OOMMFRunner
object to oommfc.runner.runner
.
# NBVAL_IGNORE_OUTPUT
try:
oommfc.runner.runner = oommfc.oommf.TclOOMMFRunner('/path/to/oommf_tcl')
except ValueError as e:
print('=' * 20)
print('ValueError:', e)
Running OOMMF (TclOOMMFRunner) [2021/08/12 10:53]... (0.0 s) OOMMF error: command: tclsh /path/to/oommf_tcl boxsi +fg macrospin.mif -exitondone 1 stdout: stderr: couldn't read file "/path/to/oommf_tcl": no such file or directory Cannot find OOMMF. ==================== ValueError: new_runner=TclOOMMFRunner(/path/to/oommf_tcl) cannot be used.
In this example we (expectedly) get a ValueError
because the path /path/to/oommf_tcl
is invalid. The default runner has not been changed:
# NBVAL_IGNORE_OUTPUT
oommfc.runner
OOMMF runner: ExeOOMMFRunner(/opt/miniconda3/envs/ubermag-dev/bin/oommf) runner is cached: True
We can change the default runner as demonstrated in the previous paragraph. If we later on decide that we want to go back to the default runner choosen by oommfc
, we can do so by calling:
oommfc.runner.autoselect_runner()
This call searches for the best available runner (it does not rely on caching) and overwrites the default obtained via oommfc.runner.runner
. We still have the same runner, because we actually never sucessfully changed a runner in this tutorial:
# NBVAL_IGNORE_OUTPUT
oommfc.runner
OOMMF runner: ExeOOMMFRunner(/opt/miniconda3/envs/ubermag-dev/bin/oommf) runner is cached: True