2022-08-17 15:11:57 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ml
|
|
|
|
class Candidate < ApplicationRecord
|
2022-09-12 12:12:09 +00:00
|
|
|
enum status: { running: 0, scheduled: 1, finished: 2, failed: 3, killed: 4 }
|
|
|
|
|
2022-08-17 15:11:57 +00:00
|
|
|
validates :iid, :experiment, presence: true
|
2022-09-12 12:12:09 +00:00
|
|
|
validates :status, inclusion: { in: statuses.keys }
|
2022-08-17 15:11:57 +00:00
|
|
|
|
|
|
|
belongs_to :experiment, class_name: 'Ml::Experiment'
|
|
|
|
belongs_to :user
|
|
|
|
has_many :metrics, class_name: 'Ml::CandidateMetric'
|
|
|
|
has_many :params, class_name: 'Ml::CandidateParam'
|
2022-09-12 12:12:09 +00:00
|
|
|
|
|
|
|
default_value_for(:iid) { SecureRandom.uuid }
|
|
|
|
|
2022-10-20 12:10:43 +00:00
|
|
|
def artifact_root
|
|
|
|
"/ml_candidate_#{iid}/-/"
|
|
|
|
end
|
|
|
|
|
2022-09-12 12:12:09 +00:00
|
|
|
class << self
|
|
|
|
def with_project_id_and_iid(project_id, iid)
|
|
|
|
return unless project_id.present? && iid.present?
|
|
|
|
|
|
|
|
joins(:experiment).find_by(experiment: { project_id: project_id }, iid: iid)
|
|
|
|
end
|
|
|
|
end
|
2022-08-17 15:11:57 +00:00
|
|
|
end
|
|
|
|
end
|