Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bo klsm #16

Merged
merged 14 commits into from
Mar 4, 2024
18 changes: 11 additions & 7 deletions endure.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,33 +153,37 @@ drop_last = true
[job.BayesianOptimization]
# -----------------------------------------------------------------------------
num_iterations = 15
num_restarts = 20
num_restarts = 2 # TODO set it to 2
# value of raw_samples determines how many initial random samples are taken from the search space before starting the optimization process
raw_samples = 30
raw_samples = 3 # TODO set it to 3
initial_samples = 20
# for a true KLSM calculation - set num_k_values to the same value as max_levels. This is only consequential for the KLSM model
# This works in the following way:
# suppose num_k_values = 4 and max_levels = 20
# Then every layer till the 4th layer will have custom k values but the (num_k_values + 1) layer to the (max_levels) layer will only
# have a k value equal to 1
num_k_values = 4

# This is the q value used in BoTorch Acquisition functions.
# if it is set to a value above 1 sequential processing will stop in acquisition function and batch processing will start
# note that for batch processing tensor shape will change and will require modification of code.
# TODO: Add code to handle batch
batch_size = 1
max_levels = 16

# Acquisition function options
# [ExpectedImprovement, UpperConfidenceBound, qExpectedImprovement]
acquisition_function = "ExpectedImprovement"
beta_value = 0.3
# model_type can take values - "Classic", "QFixed", "YZHybrid", "KHybrid"
model_type = "QFixed"
model_type = "KHybrid"

[job.BayesianOptimization.database]
# This will take value 0 and 1 where 1 means write each cost and run details into the MySqlLite database
# and 0 means run details are not stored in the database
write_to_db = 1
# by default the databases directory will be created inside the data director. To change this, you need to change ["io"]["data_dir"]
db_path = "databases"
db_path = "yz_databases"
# This must be a .db file for code to function. It will create a sqllite database
db_name = "db_cost.db"
db_name = "yz_db_cost.db"

[job.BayesianOptimization.system]
E = 1024
Expand Down
36 changes: 28 additions & 8 deletions endure/util/db_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def initialize_database(db_path='cost_log.db'):
Q INTEGER,
Y INTEGER,
Z INTEGER,
k1 REAL, k2 REAL, k3 REAL, k4 REAL, k5 REAL,
k6 REAL, k7 REAL, k8 REAL, k9 REAL, k10 REAL,
k11 REAL, k12 REAL, k13 REAL, k14 REAL, k15 REAL,
k16 REAL, k17 REAL, k18 REAL, k19 REAL, k20 REAL,
cost REAL,
FOREIGN KEY (run_id) REFERENCES runs(run_id)
);''')
Expand All @@ -56,6 +60,17 @@ def initialize_database(db_path='cost_log.db'):
bayesian_Z INTEGER,
FOREIGN KEY (run_id) REFERENCES runs(run_id)
);''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS run_details_k_values (
idx INTEGER PRIMARY KEY AUTOINCREMENT,
run_id INTEGER,
k1 REAL, k2 REAL, k3 REAL, k4 REAL, k5 REAL,
k6 REAL, k7 REAL, k8 REAL, k9 REAL, k10 REAL,
k11 REAL, k12 REAL, k13 REAL, k14 REAL, k15 REAL,
k16 REAL, k17 REAL, k18 REAL, k19 REAL, k20 REAL,
FOREIGN KEY (run_id) REFERENCES runs(run_id)
);''')

connector.commit()
return connector

Expand All @@ -76,9 +91,12 @@ def log_new_run(connector, system, workload, iterations, sample, acqf):
def log_design_cost(connector, run_id, design, cost):
cursor = connector.cursor()
policy = design.policy
cursor.execute('INSERT INTO design_costs (run_id, bits_per_element, size_ratio, policy, Q, Y, Z, cost) '
'VALUES (?, ?, ?, ?, ?, ?, ?, ?)', (run_id, design.h, design.T, policy.name, design.Q, design.Y,
design.Z, cost))
k_values = design.K + [None] * (20 - len(design.K)) # TODO replace this with the max_levels
sql_command = ('INSERT INTO design_costs (run_id, bits_per_element, size_ratio, policy, Q, Y, Z, cost, ' +
', '.join([f'k{i+1}' for i in range(20)]) + ') ' + 'VALUES (?, ?, ?, ?, ?, ?, ?, ?'', ' +
', '.join(['?']*20) + ')')
cursor.execute(sql_command, (run_id, design.h, design.T, policy.name, design.Q, design.Y, design.Z, cost) +
tuple(k_values))
connector.commit()


Expand All @@ -87,18 +105,20 @@ def log_run_details(connector, run_id, duration, analytical_cost, bayesian_cost,
analytical_policy = analytical_design.policy
print(analytical_policy)
bayesian_policy = bayesian_design.policy
if bayesian_policy == 0.0:
bo_policy = Policy.Leveling
else:
bo_policy = Policy.Tiering
cursor.execute('''
INSERT INTO run_details (run_id, duration_secs, analytical_cost, bayesian_cost, analytical_h, analytical_T,
analytical_policy, analytical_Q, analytical_Y, analytical_Z, bayesian_h, bayesian_T, bayesian_policy, bayesian_Q,
bayesian_Y, bayesian_Z) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
(run_id, duration, analytical_cost, bayesian_cost, analytical_design.h, analytical_design.T,
analytical_policy.name, analytical_design.Q, analytical_design.Y, analytical_design.Z,
bayesian_design.h, bayesian_design.T, bo_policy.name, bayesian_design.Q,
bayesian_design.h, bayesian_design.T, bayesian_policy.name, bayesian_design.Q,
bayesian_design.Y, bayesian_design.Z))
if bayesian_policy == Policy.KHybrid:
k_values = bayesian_design.K + [None] * (20 - len(bayesian_design.K))
cursor.execute('''
INSERT INTO run_details_k_values (run_id, k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, k14, k15,
k16, k17, k18, k19, k20) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''',
(run_id,) + tuple(k_values))
connector.commit()


Expand Down
Loading
Loading