def setUp(self): study_configuration_json = { "goal": "MAXIMIZE", "maxTrials": 5, "maxParallelTrials": 1, "params": [{ "parameterName": "hidden1", "type": "INTEGER", "minValue": 40, "maxValue": 400, "scallingType": "LINEAR" }] } study_configuration = json.dumps(study_configuration_json) self.study = Study.create("RandomSearchStudy", study_configuration) trial1 = Trial.create(self.study.id, "RandomSearchTrial1") trial2 = Trial.create(self.study.id, "RandomSearchTrial2") self.trials = [trial1, trial2] TrialMetric.create(trial1.id, 10, 0.5) TrialMetric.create(trial1.id, 20, 0.6) TrialMetric.create(trial2.id, 10, 0.6) TrialMetric.create(trial2.id, 20, 0.5)
def setUp(self): study_configuration_json = { "goal": "MAXIMIZE", "maxTrials": 5, "maxParallelTrials": 1, "params": [{ "parameterName": "hidden1", "type": "INTEGER", "minValue": 40, "maxValue": 400, "scallingType": "LINEAR" }] } study_configuration = json.dumps(study_configuration_json) self.study = Study.create("RandomSearchStudy", study_configuration) trial1 = Trial.create(self.study.id, "RandomSearchTrial1") trial2 = Trial.create(self.study.id, "RandomSearchTrial2") self.trials = [trial1, trial2] TrialMetric.create(trial1.id, 10, 0.5) TrialMetric.create(trial1.id, 20, 0.6) TrialMetric.create(trial2.id, 10, 0.6) TrialMetric.create(trial2.id, 20, 0.5)
def create_trial_metric(self, study_name, trial_id, training_step, objective_value): """ 等价于views.py 中的v1_study_trial_metrics 中的POST方法 :param study_name: :param trial_id: :param training_step: :param objective_value: :return: """ trial_metric = TrialMetric.create(trial_id, training_step, objective_value) return trial_metric
def v1_study_trial_metrics(request, study_id, trial_id): # Create the trial metric if request.method == "POST": data = json.loads(request.body) training_step = data["training_step"] objective_value = data["objective_value"] trial_metric = TrialMetric.create(trial_id, training_step, objective_value) return JsonResponse({"data": trial_metric.to_json()}) # List the trial metrics elif request.method == "GET": trial_metrics = TrialMetric.objects.filter(trial_id=trial_id) response_data = [trial_metric.to_json() for trial_metric in trial_metrics] return JsonResponse({"data": response_data}) else: return JsonResponse({"error": "Unsupported http method"})