In micromagneticmodel
package, base classes micromagneticmodel.Driver
and micromagneticmodel.Evolver
are defined. Their purpose is to build individual evolvers and drivers in a particular micromagnetic calculator. In this tutorial, we will demonstrate some of their basic properties, on an example of a micromagneticmodel.Driver
class. The behaviour of the micromagneticmodel.Evolver
class is the same.
Let us derive MyDriver
class. In order to define it, _allowed_attributes
list must be defined. It is a list of strings, which lists the kwargs which are allowed to be passed. Additionally, the driver must define a property _x
for the independent variable (e.g. time).
import micromagneticmodel as mm
class MyDriver(mm.Driver):
_allowed_attributes = ["arg1", "arg2"]
@property
def _x(self):
return "t"
def drive(system):
return system
Driver
class does not require any parameters to be passed at initialisation. If a keyword argument is from _allowed_kwargs
list, it will be assigned as a class attribute. Otherwise, AttributeError
will be raised.
driver = MyDriver(arg1=1, arg2="value")
The attributes are
driver.arg1
1
driver.arg2
'value'
If we try to pass a keyword argument at initialisation, which is not in the _allowed_kwargs
list, AttributeError
is rased:
try:
driver = MyDriver(arg3=1)
except AttributeError:
print("Exception raised.")
Exception raised.
The main driver method which must be implemented by a derived class is drive
.
try:
driver.drive()
except NotImplementedError:
print("Exception raised.")
To build a driver for an existing external package class micromagneticmodel.ExternalDriver
should be used. This class provides an additional method schedule
to submit a calculation job to a scheduling system.
Furthermore, it has a generic implementation for drive
and schedule
that consists of the following steps:
system
object with the simulation results (drive
only).Simulation-package specific things such as writing input files and reading results must be implemented in a number of pre-defined abstract methods inside the derived class. Refer to the API reference for more details.