Class: Cnvrg::Experiment
- Inherits:
-
Object
- Object
- Cnvrg::Experiment
- Defined in:
- lib/cnvrg/experiment.rb
Instance Attribute Summary collapse
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
Instance Method Summary collapse
- #end(output, exit_status, end_commit, cpu_average, memory_average) ⇒ Object
- #end_notebook_session(notebook_slug, end_commit) ⇒ Object
- #exec_remote(command, commit_to_run, instance_type, image_slug, scheduling_query, local_timestamp, grid, path_to_cmd, data, data_commit) ⇒ Object
- #get_machine_activity(working_dir) ⇒ Object
- #get_notebook_slug(proj_dir) ⇒ Object
-
#initialize(owner, project_slug) ⇒ Experiment
constructor
A new instance of Experiment.
- #start(input, platform, machine_name, start_commit, name, email_notification, machine_activity, script_path) ⇒ Object
- #start_notebook_session(kernel, start_commit, token, port, remote, notebook_path) ⇒ Object
- #update_notebook_slug(proj_dir, slug) ⇒ Object
- #upload_temp_log(temp_log, cpu_average, memory_average) ⇒ Object
Constructor Details
#initialize(owner, project_slug) ⇒ Experiment
Returns a new instance of Experiment.
5 6 7 8 9 10 |
# File 'lib/cnvrg/experiment.rb', line 5 def initialize(owner, project_slug) @project_slug = project_slug @owner = owner @base_resource = "users/#{owner}/projects/#{project_slug}/" @slug = nil end |
Instance Attribute Details
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
3 4 5 |
# File 'lib/cnvrg/experiment.rb', line 3 def slug @slug end |
Instance Method Details
#end(output, exit_status, end_commit, cpu_average, memory_average) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/cnvrg/experiment.rb', line 99 def end(output, exit_status, end_commit, cpu_average, memory_average) #if remote try to remove response = Cnvrg::API.request(@base_resource + "experiment/end", 'POST', {output: output, exp_slug: @slug, exit_status: exit_status, end_commit: end_commit, cpu_average: cpu_average, memory_average: memory_average}) Cnvrg::CLI.is_response_success(response,false) begin FileUtils.rm_rf(["/home/ds/.cnvrg/tmp/exec.log"]) rescue end end |
#end_notebook_session(notebook_slug, end_commit) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/cnvrg/experiment.rb', line 37 def end_notebook_session(notebook_slug, end_commit) res = Cnvrg::API.request(@base_resource + "notebook/end_session", 'POST', {notebook_slug: notebook_slug, end_commit: end_commit}) Cnvrg::CLI.is_response_success(res,false) return res end |
#exec_remote(command, commit_to_run, instance_type, image_slug, scheduling_query, local_timestamp, grid, path_to_cmd, data, data_commit) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/cnvrg/experiment.rb', line 81 def exec_remote(command, commit_to_run, instance_type, image_slug,scheduling_query,, grid,path_to_cmd,data, data_commit) response = Cnvrg::API.request("users/#{@owner}/projects/#{@project_slug}/experiment/remote", 'POST', {command: command, image_slug: image_slug, commit_sha1: commit_to_run, instance_type: instance_type, scheduling_query:scheduling_query, local_timestamp:, grid: grid, path_to_cmd:path_to_cmd,dataset_slug:data, dataset_commit: data_commit}) return response end |
#get_machine_activity(working_dir) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cnvrg/experiment.rb', line 68 def get_machine_activity(working_dir) begin machine_activity = File.open("/home/ds/notebooks/.cnvrg/machine_activity", "rb").read machine_activity = machine_activity.to_s.strip ma_id = machine_activity.to_i return ma_id rescue return nil end end |
#get_notebook_slug(proj_dir) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cnvrg/experiment.rb', line 56 def get_notebook_slug(proj_dir) begin notebook_slug = File.open(proj_dir + "/.cnvrg/notebook_slug", "rb").read notebook_slug = notebook_slug.gsub("/n", "") notebook_slug = notebook_slug.to_s.strip return notebook_slug rescue return nil end end |
#start(input, platform, machine_name, start_commit, name, email_notification, machine_activity, script_path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cnvrg/experiment.rb', line 12 def start(input, platform, machine_name, start_commit, name, email_notification, machine_activity,script_path) res = Cnvrg::API.request(@base_resource + "experiment/start", 'POST', {input: input, platform: platform, machine_name: machine_name, start_commit: start_commit, title: name, email_notification: email_notification, machine_activity: machine_activity,script_path:script_path}) Cnvrg::CLI.is_response_success(res,false) @slug = res.to_h["result"].to_h["slug"] return res end |
#start_notebook_session(kernel, start_commit, token, port, remote, notebook_path) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cnvrg/experiment.rb', line 24 def start_notebook_session(kernel, start_commit, token, port, remote, notebook_path) res = Cnvrg::API.request(@base_resource + "notebook/start_session", 'POST', {kernel: kernel, start_commit: start_commit, token: token, port: port, remote: remote, notebook_path: notebook_path}) Cnvrg::CLI.is_response_success(res) @slug = res["result"]["id"] return @slug end |
#update_notebook_slug(proj_dir, slug) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cnvrg/experiment.rb', line 45 def update_notebook_slug(proj_dir, slug) begin file = proj_dir+"/.cnvrg/notebook_slug" FileUtils.touch file File.open(file, "w+") { |f| f.write slug } rescue end end |
#upload_temp_log(temp_log, cpu_average, memory_average) ⇒ Object
93 94 95 96 97 |
# File 'lib/cnvrg/experiment.rb', line 93 def upload_temp_log(temp_log, cpu_average, memory_average) response = Cnvrg::API.request(@base_resource + "experiment/upload_temp_log", 'POST', {output: temp_log, exp_slug: @slug}) Cnvrg::CLI.is_response_success(response,false) end |