Skip to content

Commit 1bc9a6c

Browse files
committed
Added clone button functionality
* Also, DAC Adapter Circuit modifications are comitted #34
1 parent a781f99 commit 1bc9a6c

File tree

12 files changed

+3389
-3321
lines changed

12 files changed

+3389
-3321
lines changed

MLC/GUI/ExperimentsManager.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import os
2323
import sys
24+
import shutil
2425
import time
2526

2627
from MLC.api.mlc import DuplicatedExperimentError
@@ -142,6 +143,7 @@ def import_experiment(self, experiment_path):
142143
raise
143144

144145
self._experiment_list.append(experiment_name)
146+
self._experiment_list.sort()
145147
self.load_experiment_info(experiment_name)
146148

147149
def export_experiment(self, export_dir, experiment_name):
@@ -158,6 +160,15 @@ def export_experiment(self, export_dir, experiment_name):
158160
"Error {1}".format(experiment_name, err))
159161
raise
160162

163+
def clone_experiment(self, experiment_name, cloned_experiment):
164+
if not self._mlc_local.clone_experiment(experiment_name, cloned_experiment):
165+
return False
166+
167+
self._experiment_list.append(cloned_experiment)
168+
self._experiment_list.sort()
169+
self.load_experiment_info(cloned_experiment)
170+
return True
171+
161172
def get_experiment_list(self):
162173
return self._experiment_list
163174

MLC/GUI/mlc_gui.py

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,16 @@ def on_new_button_clicked(self):
119119
else:
120120
break
121121

122-
# Create the new experiment and refresh the View
122+
# Create the new experiment and refresh the view
123123
if not self._experiments_manager.add_experiment(experiment_name):
124+
logger.error('[MLC_MANAGER] [NEW_EXPERIMENT] - Experiment {0} could not be created. '
125+
'Check it to be correct in your workspace'.format(experiment_name))
124126
QMessageBox.critical(self, 'New Experiment',
125-
('Experiment {0} already exists but has errors. '
126-
'Check it to be correct in your workspace'
127-
.format(experiment_name)))
127+
'Experiment {0} could not be created. '
128+
'Check the experiment to be correct in your workspace'
129+
.format(experiment_name))
128130
return
131+
129132
self._refresh_experiment_list_view()
130133
self._clean_experiment_selection()
131134

@@ -151,8 +154,68 @@ def on_open_button_clicked(self):
151154
experiment.show()
152155

153156
def on_clone_button_clicked(self):
154-
logger.debug("[MLC_MANAGER] [CLONE_BUTTON] - Open button clicked")
155-
# TODO
157+
logger.debug("[MLC_MANAGER] [CLONE_BUTTON] - Clone button clicked")
158+
cloned_experiment = ""
159+
dialog_ok = False
160+
161+
if self._experiment_selected is None:
162+
logger.info("[MLC MANAGER] [OPEN_BUTTON] - No experiment was selected yet. Don't do anything")
163+
return
164+
experiment_name = self._experiment_selected
165+
166+
while True:
167+
cloned_experiment, dialog_ok = QInputDialog.getText(self, 'Clone Experiment',
168+
'Enter the name of the new cloned experiment:')
169+
170+
if dialog_ok:
171+
if cloned_experiment == "":
172+
logger.info('[MLC_MANAGER] [CLONE_EXPERIMENT] - Cloned experiment name cannot an empty string.')
173+
msg_ok = QMessageBox.information(self, 'Clone Experiment',
174+
'Cloned experiment name experiment cannot be an empty string. '
175+
'Please, insert a valid name',
176+
QMessageBox.Ok | QMessageBox.Cancel,
177+
QMessageBox.Ok)
178+
179+
if msg_ok == QMessageBox.Ok:
180+
continue
181+
else:
182+
break
183+
184+
# Check if the experiment already exists
185+
if cloned_experiment in self._experiments_manager.get_experiment_list():
186+
msg_ok = QMessageBox.question(self, 'Clone Experiment',
187+
('The cloned experiment name has already been taken. '
188+
'Do you want to create the project with a different name?'),
189+
QMessageBox.Yes | QMessageBox.No,
190+
QMessageBox.Yes)
191+
if msg_ok == QMessageBox.Yes:
192+
continue
193+
else:
194+
break
195+
196+
# Create the new experiment and refresh the View
197+
if not self._experiments_manager.clone_experiment(experiment_name, cloned_experiment):
198+
logger.error('[MLC_MANAGER] [CLONE_EXPERIMENT] - Experiment {0} could not be created. '
199+
'Check it to be correct in your workspace'.format(experiment_name))
200+
QMessageBox.critical(self, 'Clone Experiment',
201+
'Experiment {0} could not be cloned. '
202+
'Check the experiment to be correct in your workspace'
203+
.format(experiment_name))
204+
return
205+
206+
self._refresh_experiment_list_view()
207+
self._clean_experiment_selection()
208+
209+
QMessageBox.information(self, 'Clone Experiment',
210+
'Experiment {0} was succesfully cloned. Cloned Experiment: {1}'
211+
.format(experiment_name, cloned_experiment))
212+
logger.debug('[MLC_MANAGER] [CLONE_EXPERIMENT] - Experiment {0} was succesfully cloned. '
213+
'Cloned Experiment {1}'.format(experiment_name, cloned_experiment))
214+
return
215+
else:
216+
break
217+
logger.debug('[MLC_MANAGER] New experiment could not be cloned')
218+
156219

157220
def on_remove_button_clicked(self):
158221
logger.debug("[MLC_MANAGER] [REMOVE_EXPERIMENT] - Remove button clicked")

MLC/GUI/util.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# along with this program. If not, see <http://www.gnu.org/licenses/>
2121

2222
import os
23+
import sys
24+
import traceback
2325

2426
from MLC.Common.LispTreeExpr.LispTreeExpr import LispTreeExpr
2527
from MLC.Common.LispTreeExpr.LispTreeExpr import ExprException
@@ -63,12 +65,14 @@ def test_individual_value(parent, experiment_name, log_prefix, indiv_value, conf
6365
QMessageBox.critical(parent,
6466
"Invalid Evaluation Script",
6567
"Check the evaluation script to be correct. "
66-
"Error Msg: {0}.".format(err))
68+
"Error Msg: {0}. \n Traceback: {1}"
69+
.format(err, traceback.format_exc()))
70+
6771
logger.error("{0} Experiment {1} - "
6872
"Individual inserted is not a valid individual. "
6973
"Check the evaluation script to be correct. "
70-
"Error Msg: {2}."
71-
.format(log_prefix, experiment_name, err))
74+
"Error Msg: {2}. Traceback:\n{3}"
75+
.format(log_prefix, experiment_name, err, traceback.format_exc()))
7276

7377
return None
7478

MLC/api/Experiment.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class Experiment:
4545
__last_simulation = None
4646

4747
def __init__(self, working_dir, experiment_name):
48+
logger.info("[EXPERIMENT {0}] Proceed to load {1} experiment"
49+
.format(experiment_name, os.path.join(working_dir)))
4850
Experiment.check_configuration(working_dir, experiment_name)
4951
cfg, db = Experiment.get_experiment_files(working_dir, experiment_name)
5052
self._name = experiment_name

MLC/api/MLCLocal.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,37 @@ def new_experiment(self, experiment_name,
178178
evaluation_script,
179179
preevaluation_script)
180180

181+
def clone_experiment(self, experiment_name, cloned_experiment):
182+
source_path = os.path.join(self._working_dir, experiment_name)
183+
cloned_path = os.path.join(self._working_dir, cloned_experiment)
184+
185+
# Copy the desired experiment and then change the config and db files names
186+
try:
187+
shutil.copytree(source_path, cloned_path)
188+
shutil.move(os.path.join(cloned_path, experiment_name + ".conf"),
189+
os.path.join(cloned_path, cloned_experiment + ".conf"))
190+
191+
shutil.move(os.path.join(cloned_path, experiment_name + ".db"),
192+
os.path.join(cloned_path, cloned_experiment + ".db"))
193+
194+
# Change the DB name inside the experiment
195+
experiment_config = ConfigParser.ConfigParser()
196+
experiment_config.read(os.path.join(cloned_path, cloned_experiment + ".conf"))
197+
experiment_config.set('BEHAVIOUR', 'savedir', cloned_experiment + ".db")
198+
with open(os.path.join(cloned_path, cloned_experiment + ".conf"), "w") as f:
199+
experiment_config.write(f)
200+
201+
# Add the experiment to the list of experiments
202+
self._experiments[cloned_experiment] = Experiment(cloned_path, cloned_experiment)
203+
204+
except Exception, err:
205+
logger.error("[MLC_LOCAL] [CLONE] - "
206+
"An error ocurred while cloning project {0}. "
207+
"Error {1}".format(experiment_name, err))
208+
return False
209+
210+
return True
211+
181212
def delete_experiment(self, experiment_name):
182213
if experiment_name not in self._experiments:
183214
raise ExperimentNotExistException(experiment_name)
@@ -293,7 +324,6 @@ def save_board_configuration(self, experiment_name, board_configuration, connect
293324
mlc_repo.save_board_configuration(board_configuration, board_id=board_id)
294325
mlc_repo.save_serial_connection(connection, board_id=board_id, connection_id=board_id)
295326

296-
297327
def go(self, experiment_name, to_generation, from_generation=0, callbacks={}, gen_creator=None):
298328
if experiment_name not in self._experiments:
299329
raise ExperimentNotExistException(experiment_name)

MLC/api/mlc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ def delete_experiment(self, experiment_name):
112112
"""
113113
raise NotImplementedError("MLC::delete_experiment not implemented")
114114

115+
def clone_experiment(self, experiment_name, cloned_experiment):
116+
"""
117+
Clone an experiment from the workspace.
118+
:param experiment_name:
119+
:param cloned_experiment
120+
"""
121+
raise NotImplementedError("MLC::cloned_experiment not implemented")
122+
115123
def import_experiment(self, experiment_path):
116124
"""
117125
Import an experiment and add it to the workspace

0 commit comments

Comments
 (0)