Sha256: 7b03abfa970483d1909547bd436a84ce9ea11dceb16f71970de0fe98b3da2ce2

Contents?: true

Size: 1.42 KB

Versions: 46

Compression:

Stored size: 1.42 KB

Contents

# == Schema Information
#
# Table name: easy_ml_tuner_jobs
#
#  id                :bigint           not null, primary key
#  config            :json             not null
#  best_tuner_run_id :bigint
#  model_id          :bigint           not null
#  status            :string
#  direction         :string           default("minimize")
#  started_at        :datetime
#  completed_at      :datetime
#  metadata          :jsonb
#  wandb_url         :string
#  created_at        :datetime         not null
#  updated_at        :datetime         not null
#
module EasyML
  class TunerJob < ActiveRecord::Base
    self.table_name = "easy_ml_tuner_jobs"

    belongs_to :model
    belongs_to :best_tuner_run, class_name: "EasyML::TunerRun", optional: true
    has_many :tuner_runs, dependent: :destroy

    validates :config, presence: true
    validates :direction, inclusion: { in: %w[minimize maximize] }

    enum status: {
      pending: "pending",
      running: "running",
      success: "success",
      failed: "failed",
    }

    def best_run
      return nil if tuner_runs.empty?

      tuner_runs.order(value: direction_order).first
    end

    def self.constants
      EasyML::Model::MODEL_OPTIONS.inject({}) do |h, (key, class_name)|
        h.tap do
          h[key] = class_name.constantize.hyperparameter_constants
        end
      end
    end

    private

    def direction_order
      direction == "minimize" ? :asc : :desc
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
easy_ml-0.2.0.pre.rc47 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc46 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc45 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc44 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc43 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc41 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc40 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc39 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc38 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc37 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc36 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc35 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc34 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc33 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc32 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc31 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc30 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc29 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc28 app/models/easy_ml/tuner_job.rb
easy_ml-0.2.0.pre.rc27 app/models/easy_ml/tuner_job.rb