Module: Cnvrg::Helpers
Instance Method Summary collapse
- #checkmark ⇒ Object
- #cnvrgignore_content ⇒ Object
-
#cpu_time ⇒ Object
cpu.
- #decrypt(key, iv, str) ⇒ Object
-
#get_mem(pid) ⇒ Object
memory.
-
#get_s3_props(files) ⇒ Object
will return client and decryptor.
- #hyper_content ⇒ Object
- #internet_connection? ⇒ Boolean
- #is_verify_ssl ⇒ Object
- #linux? ⇒ Boolean
- #look_for_in_path(path, name) ⇒ Object
- #mac? ⇒ Boolean
- #netrc_domain ⇒ Object
- #os ⇒ Object
- #parallel_threads ⇒ Object
- #readme_content ⇒ Object
- #remote_url ⇒ Object
- #ubuntu? ⇒ Boolean
- #wall_time ⇒ Object
- #windows? ⇒ Boolean
Instance Method Details
#checkmark ⇒ Object
9 10 11 12 |
# File 'lib/cnvrg/helpers.rb', line 9 def checkmark checkmark = "\u2713" return checkmark.encode('utf-8') end |
#cnvrgignore_content ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/cnvrg/helpers.rb', line 96 def cnvrgignore_content %{ # cnvrg ignore: Ignore the following directories and files # for example: # some_dir/ # some_file.txt .git* .gitignore }.strip end |
#cpu_time ⇒ Object
cpu
189 190 191 |
# File 'lib/cnvrg/helpers.rb', line 189 def cpu_time Process.clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID, :microsecond) end |
#decrypt(key, iv, str) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/cnvrg/helpers.rb', line 197 def decrypt(key,iv,str) begin cipher = OpenSSL::Cipher.new("aes-256-cbc").decrypt cipher.key = key cipher.iv = Base64.decode64 iv.encode('ascii-8bit') result = Base64.decode64 (str.encode('ascii-8bit')) result = cipher.update(result) result << cipher.final return result rescue => e puts e end end |
#get_mem(pid) ⇒ Object
memory
219 220 |
# File 'lib/cnvrg/helpers.rb', line 219 def get_mem(pid) end |
#get_s3_props(files) ⇒ Object
will return client and decryptor
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/cnvrg/helpers.rb', line 222 def get_s3_props(files) #will return client and decryptor sts_path = files["path_sts"] retries = 0 success= false while !success and retries < 20 begin if !Helpers.is_verify_ssl body = open(sts_path, {ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}).read else body = open(sts_path).read end success = true rescue => e retries +=1 sleep(5) end end if !success return Cnvrg::Result.new(false,"couldn't download some files", "error in sts", "" ) end split = body.split("\n") key = split[0] iv = split[1] access = Cnvrg::Helpers.decrypt(key, iv, files["sts_a"]) secret = Cnvrg::Helpers.decrypt(key,iv, files["sts_s"]) session = Cnvrg::Helpers.decrypt(key,iv, files["sts_st"]) region = Cnvrg::Helpers.decrypt(key,iv, files["region"]) bucket = Cnvrg::Helpers.decrypt(key,iv, files["bucket"]) is_s3 = files["is_s3"] if is_s3 or is_s3.nil? client = Aws::S3::Client.new( :access_key_id =>access, :secret_access_key => secret, :session_token => session, :region => region, :http_open_timeout => 60, :retry_limit => 20) use_accelerate_endpoint = true else endpoint = Cnvrg::Helpers.decrypt(key,iv, files["endpoint_url"]) client = Aws::S3::Client.new( :access_key_id =>access, :secret_access_key => secret, :region => region, :endpoint=> endpoint,:force_path_style=> true,:ssl_verify_peer=>false, :http_open_timeout => 60, :retry_limit => 20) use_accelerate_endpoint = false end = {:use_accelerate_endpoint => use_accelerate_endpoint,:server_side_encryption => 'AES256'} return {client: client, key: key, iv: iv, bucket: bucket, upload_options: } end |
#hyper_content ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cnvrg/helpers.rb', line 107 def hyper_content %{# Hyperparameter Optimization is the process of choosing a set of parameters for a learning algorithm, usually with the goal of optimizing a measure of the algorithm's performance on an independent data set. # Below is the list of parameters that will be used in the optimization process. Each parameter has a param_name that should match the argument that is feeded to the experiment s.t kernel => --kernel='rbf' parameters: # Integer parameter is a range of possible values between a minimum (inclusive) # and maximum (not inclusive) values. Values are floored (0.7 => 0) - param_name: "learning_rate" type: "integer" min: 0 # inclusive max: 10 # not inclusive scale: "linear" steps: 4 # The number of linear steps to produce. # Float parameter is a range of possible values between a minimum (inclusive) # and maximum (not inclusive) values. # - param_name: "learning_rate" type: "float" # precision is 9 after period min: 0.00001 max: 0.1 scale: "log2" # Could be log10 as well steps: 2 # Discrete parameter is an array of numerical values. # - param_name: "c" type: "discrete" values: [0, 0.1 ,0.001] # Categorical parameter is an array of string values # - param_name: "kernel" type: "categorical" values: ["linear", "poly", "rbf"] } end |
#internet_connection? ⇒ Boolean
14 15 16 17 18 19 20 |
# File 'lib/cnvrg/helpers.rb', line 14 def internet_connection? begin true if open("http://www.google.com/") rescue false end end |
#is_verify_ssl ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cnvrg/helpers.rb', line 41 def is_verify_ssl home_dir = File.('~') config = "" begin if File.exist? home_dir+"/.cnvrg/config.yml" config = YAML.load_file(home_dir+"/.cnvrg/config.yml") else return true end rescue return true end if !config or config.empty? or config.to_h[:verify_ssl].nil? return true else return config.to_h[:verify_ssl] end end |
#linux? ⇒ Boolean
87 88 89 |
# File 'lib/cnvrg/helpers.rb', line 87 def linux? not mac? and not windows? end |
#look_for_in_path(path, name) ⇒ Object
177 178 179 180 181 182 183 184 185 |
# File 'lib/cnvrg/helpers.rb', line 177 def look_for_in_path(path, name) url_split = path.split("/") url_split.each_with_index do |u, i| if u == name return i end end return -1 end |
#mac? ⇒ Boolean
83 84 85 |
# File 'lib/cnvrg/helpers.rb', line 83 def mac? !!(RUBY_PLATFORM =~ /-darwin\d/) end |
#netrc_domain ⇒ Object
173 174 175 |
# File 'lib/cnvrg/helpers.rb', line 173 def netrc_domain "cnvrg.io" end |
#os ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cnvrg/helpers.rb', line 62 def os if windows? return "windows" elsif mac? return "mac" elsif ubuntu? return "ubuntu" elsif linux? return "linux" else return "N/A" end end |
#parallel_threads ⇒ Object
6 7 8 |
# File 'lib/cnvrg/helpers.rb', line 6 def parallel_threads() return ParallelThreads end |
#readme_content ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/cnvrg/helpers.rb', line 148 def readme_content %{ # README This README would normally contain some context and description about the project. Things you may want to cover: * Data description * Benchmark and measurement guidelines * Used algorithms * Scores * Configurations * Requirements * How to run the experiments * ...}.strip end |
#remote_url ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cnvrg/helpers.rb', line 22 def remote_url home_dir = File.('~') config = "" begin if File.exist? home_dir+"/.cnvrg/config.yml" config = YAML.load_file(home_dir+"/.cnvrg/config.yml") else return "https://cnvrg.io" end rescue return "https://cnvrg.io" end if !config or config.empty? or config.to_h[:api].nil? return "https://cnvrg.io" else return config.to_h[:api].gsub("/api", "") end end |
#ubuntu? ⇒ Boolean
91 92 93 94 |
# File 'lib/cnvrg/helpers.rb', line 91 def ubuntu? unix = `cat /etc/lsb-release`.downcase! return unix.include? "ubuntu" end |
#wall_time ⇒ Object
193 194 195 |
# File 'lib/cnvrg/helpers.rb', line 193 def wall_time Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond) end |
#windows? ⇒ Boolean
79 80 81 |
# File 'lib/cnvrg/helpers.rb', line 79 def windows? !!(RUBY_PLATFORM =~ /mswin32|mingw32/) end |