|
| 1 | +*************** |
| 2 | +Source code map |
| 3 | +*************** |
| 4 | + |
| 5 | +This document will walk the path of an orion experiment through the |
| 6 | +code. Not every detail is explained, but there are ample links to the |
| 7 | +classes and methods involved if you want to dig further in a certain |
| 8 | +section. |
| 9 | + |
| 10 | +Departure |
| 11 | +--------- |
| 12 | + |
| 13 | +You start an experience by running ``orion hunt <script> <params>``. |
| 14 | + |
| 15 | +The code in :py:func:`orion.core.cli.main` will parse the command line |
| 16 | +arguments and route to :py:func:`orion.core.cli.hunt.main`. |
| 17 | + |
| 18 | +The command line arguments are passed to |
| 19 | +:py:func:`orion.core.io.experiment_builder.build_from_args`. This will |
| 20 | +massage the parsed command line arguments and merge that configuration |
| 21 | +with the config file and the defaults with various helpers from |
| 22 | +:py:mod:`orion.core.io.resolve_config` to build the final |
| 23 | +configuration. The result is eventually handled off to |
| 24 | +:py:func:`orion.core.io.experiment_builder.create_experiment` to |
| 25 | +create an :py:class:`orion.core.worker.experiment.Experiment` and set |
| 26 | +its properties. |
| 27 | + |
| 28 | +The created experiments finds its way back to |
| 29 | +:py:func:`orion.core.cli.hunt.main` and is handed off to |
| 30 | +:py:func:`orion.core.cli.hunt.workon` along with some more |
| 31 | +configuration for the workers. |
| 32 | + |
| 33 | +This method will setup a few more objects to manage the optimization |
| 34 | +process: a :py:class:`orion.core.worker.consumer.Consumer` to act as |
| 35 | +the bridge to the user script and an |
| 36 | +:py:class:`orion.client.experiment.ExperimentClient` to coordinate |
| 37 | +everything and calls |
| 38 | +:py:meth:`orion.client.experiment.ExperimentClient.workon` which |
| 39 | +mostly creates a :py:class:`orion.client.runner.Runner` and calls its |
| 40 | +:py:meth:`orion.client.runner.Runner.run` method. |
| 41 | + |
| 42 | + |
| 43 | +The Run Loop |
| 44 | +------------ |
| 45 | + |
| 46 | +We are finally in the main run loop. It is composed of three main |
| 47 | +phases that repeat. |
| 48 | + |
| 49 | + |
| 50 | +First phase |
| 51 | +~~~~~~~~~~~ |
| 52 | + |
| 53 | +In the first phase we call |
| 54 | +:py:meth:`orion.client.runner.Runner.sample`. This will check if new |
| 55 | +trials are required using |
| 56 | +:py:meth:`orion.client.runner.Runner.should_sample` and request those |
| 57 | +trials using :py:meth:`orion.client.experiment.ExperimentClient.suggest`. |
| 58 | + |
| 59 | +This will first check if any trials are available in the storage using |
| 60 | +:py:meth:`orion.core.worker.experiment.Experiment.reserve_trial`. |
| 61 | + |
| 62 | +If none are available, it will produce new trials using |
| 63 | +:py:meth:`orion.core.worker.producer.Producer.produce()` which loads |
| 64 | +the state of the algorithm from the storage, runs it to suggest new |
| 65 | +:py:class:`orion.core.worker.trial.Trial` and saves both the new |
| 66 | +trials and the new algorithm state to the storage. This is protected |
| 67 | +from concurrent access by other instances of ``orion hunt`` by locking |
| 68 | +the storage for the duration of that operation. |
| 69 | + |
| 70 | + |
| 71 | +The second phase |
| 72 | +~~~~~~~~~~~~~~~~ |
| 73 | + |
| 74 | +In the second phase we call |
| 75 | +:py:meth:`orion.client.runner.Runner.scatter` with the trials |
| 76 | +generated in the first phase, if any. |
| 77 | + |
| 78 | +This schedules each trial to be executed using the configured executor |
| 79 | +and registers the futures that the executor returns. Execution is |
| 80 | +handled asynchronously and the futures enable us to keep track of the |
| 81 | +state of the trials. |
| 82 | + |
| 83 | + |
| 84 | +The third phase |
| 85 | +~~~~~~~~~~~~~~~ |
| 86 | + |
| 87 | +In the third phase we call |
| 88 | +:py:meth:`orion.client.runner.Runner.gather` which will wait on all |
| 89 | +currently registered futures with a timeout to get some results. |
| 90 | + |
| 91 | +Once we get those results we de-register the futures and record the |
| 92 | +results with |
| 93 | +:py:meth:`orion.client.experiment.ExperimentClient.observe` or update |
| 94 | +the count of broken trials if they did not finish successfully. |
| 95 | + |
| 96 | +Finally we monitor the total amount of time spent waiting for trials |
| 97 | +to finish. |
0 commit comments