From 795b721fa235fcd700f4cd7a7db34e7b8a603135 Mon Sep 17 00:00:00 2001 From: Chell Date: Thu, 2 May 2024 22:07:30 +0200 Subject: [PATCH] Refactor Orchestrator class in core.py to randomize treatment order --- README.md | 16 ++++++++++++++-- midori/core.py | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1ed03ff..f0363ed 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Midori is a plugin-based orchestrator that allows researchers to run software en ### Usage -Initialize the orchestrator with the following parameters and run: +Initialize the orchestrator with the following [parameters](#parameters) and run: ```python from midori.core import Orchestrator @@ -48,9 +48,21 @@ orchestrator = Orchestrator( orchestrator.run() ``` +### Remote Node and Experiment Subject Setup + +The `subject_path` is a directory on the remote node. As mentioned in the next section, `variables` represent the variables to be manipulated in the experiment, which should be reflected in the `subject_path`. `subject_path` should be a git repository that contains branches named of the combinations of the `variables`. + +For example, if `variable` is + +```python +variables = {'drink': ['orange', 'apple', 'watermelon'], 'size': [300, 600, 100], 'temperature': [20, 30]} +``` + +The `subject_path` should be a git repository that contains branches named `orange-300-20`, `orange-300-30`, `orange-600-20`, `orange-600-30`, etc. You do not have to include all the combinations, Midori will skip the missing branches. + ### Parameters -- `hostname`, `username`, `password`: Mitori needs these parameters to connect to the remote cluster via SSH. +- `hostname`, `username`, `password`: Mitori needs these parameters to connect to the remote node via SSH. - `repetitions`: The number of repetitions for the experiment. - `before_trial_cooling_time`: The cooling time before each trial, in seconds. - `trial_timespan`: The time span of each trial, in seconds. diff --git a/midori/core.py b/midori/core.py index 39986d1..ca33619 100644 --- a/midori/core.py +++ b/midori/core.py @@ -1,4 +1,5 @@ import paramiko +import random from typing import List, Dict, Type from .plugins.helpers import PluginHelper from .treatments_helper import get_treatments @@ -68,7 +69,8 @@ def run(self) -> None: for i in range(self.__repetitions): print(f"Repetition {i+1}") - for treatment in self.treatments: + randomized_treatments = random.sample(self.treatments, len(self.treatments)) + for treatment in randomized_treatments: if not is_a_branch_exist( branch=treatment, subject_path=self.__subject_path, ssh=self.__ssh ):