trixi.experiment¶
Experiment¶
-
class
trixi.experiment.experiment.
Experiment
(n_epochs=0)[source]¶ Bases:
object
An abstract Experiment which can be run for a number of epochs.
The basic life cycle of an experiment is:
setup() prepare() while epoch < n_epochs: train() validate() epoch += 1 end()
If you want to use another criterion than number of epochs, e.g. stopping based on validation loss, you can implement that in your validation method and just call .stop() at some point to break the loop. Just set your n_epochs to a high number or np.inf.
The reason there is both
setup()
andprepare()
is that internally there is also a_setup_internal()
method for hidden magic in classes that inherit from this. For example, thetrixi.experiment.pytorchexperiment.PytorchExperiment
uses this to restore checkpoints. Think ofsetup()
as an__init__()
that is only called when the Experiment is actually asked to do anything. Then useprepare()
to modify the fully instantiated Experiment if you need to.To write a new Experiment simply inherit the Experiment class and overwrite the methods. You can then start your Experiment calling
run()
In Addition the Experiment also has a test function. If you call the
run_test()
method it will call thetest()
andend_test()
method internally (and if you give the parameter setup = True in run_test is will again callsetup()
andprepare()
).Each Experiment also has its current state in
_exp_state
, its start time in_time_start
, its end time in_time_end
and the current epoch index in_epoch_idx
Parameters: n_epochs (int) – The number of epochs in the Experiment (how often the train and validate method will be called) -
epoch
¶ Convenience access property for self._epoch_idx
-
process_err
(e)[source]¶ This method is called if an error occurs during the execution of an experiment. Will just raise by default.
Parameters: e (Exception) – The exception which was raised during the experiment life cycle
-
run
(setup=True)[source]¶ This method runs the Experiment. It runs through the basic lifecycle of an Experiment:
setup() prepare() while epoch < n_epochs: train() validate() epoch += 1 end()
-
run_test
(setup=True)[source]¶ This method runs the Experiment.
The test consist of an optional setup and then calls the
test()
andend_test()
.Parameters: setup – If True it will execute the setup()
andprepare()
function similar to the run method before callingtest()
.
-
setup
()[source]¶ Is called at the beginning of each Experiment run to setup the basic components needed for a run.
-