-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhyperparamter_tuning.py
65 lines (59 loc) · 2.36 KB
/
hyperparamter_tuning.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import wandb
wandb.login()
import numpy as np
import random
import subprocess
# 🐝 Step 1: Define training function that takes in hyperparameter
# values from `wandb.config` and uses them to train a model and return metric
# 🐝 Step 2: Define sweep config
sweep_configuration = {
'method': 'bayes',
'name': 'sweep',
'metric': {'goal': 'minimize', 'name': 'distance'},
'parameters':
{
'penaltyDuration': {'distribution': 'log_uniform','min':-2.30258,'max':4.605},# from 0.1 to 100
'penaltyCapacity': {'distribution': 'log_uniform','min':-2.30258,'max':4.605},# from 0.1 to 100
}
}
def main():
# Use the wandb.init() API to generate a background process
# to sync and log data as a Weights and Biases run.
# Optionally provide the name of the project.
run = wandb.init(project='tuneHGS')
# note that we define values from `wandb.config` instead of
# defining hard values
penaltyDuration = wandb.config.penaltyDuration
penaltyCapacity = wandb.config.penaltyCapacity
print('Starting ./Integrate')
result = subprocess.run(f'./Integrate {penaltyCapacity} {penaltyDuration} < input_text.txt', shell=True,stdout=subprocess.PIPE)
print('Exectution Done')
line = result.stdout.decode('utf-8').split('\n')[-2]
distance = float(line.split(' ')[-1])
wandb.log({
'penaltyDuration': float(penaltyDuration),
'penaltyCapacity': float(penaltyCapacity),
'distance': distance
})
def main2():
print('Starting ./Integrate')
# subprocess.run(['ls','-l'])
input =''
# with open('input_text.txt', 'r') as file:
# input = file.read().encode('utf-8')
# p = subprocess.Popen(['./Integrate','1.0','10.0','<', 'input_text.txt'],stdout = subprocess.PIPE, stderr = subprocess.PIPE)
# result,stderr = p.communicate()
result = subprocess.run('./Integrate 1.0 10.0 < input_text.txt', shell=True,stdout=subprocess.PIPE)
print('Exectution Done')
print(result)
line = result.stdout.decode('utf-8').split('\n')[-2]
print(line)
distance = float(line.split(' ')[-1])
print(distance)
if __name__ == '__main__':
# 🐝 Step 3: Initialize sweep by passing in config
sweep_id = wandb.sweep(sweep=sweep_configuration, project='tuneHGS')
print(sweep_id)
# 🐝 Step 4: Call to `wandb.agent` to start a sweep
wandb.agent(sweep_id, function=main, count=20)
# main2()