Skip to content

Commit

Permalink
support for yzlsm and qlsm for bo (#11)
Browse files Browse the repository at this point in the history
* added support for yzlsm and qlsm for bo

* qlsm solver update

* remove redundant call
  • Loading branch information
aquaorifice authored Feb 25, 2024
1 parent ba317f3 commit e3c7c94
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 99 deletions.
30 changes: 17 additions & 13 deletions endure.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,29 +153,33 @@ drop_last = true
[job.BayesianOptimization]
# -----------------------------------------------------------------------------
num_iterations = 15
num_restarts = 200
raw_samples = 512
initial_samples = 30
max_levels = 16
# 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"
# This must be a .db file for code to function. It will create a sqllite database
db_name = "db_cost.db"

num_restarts = 20
# value of raw_samples determines how many initial random samples are taken from the search space before starting the optimization process
raw_samples = 30
initial_samples = 20

# 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]
# [ExpectedImprovement, UpperConfidenceBound, qExpectedImprovement]
acquisition_function = "ExpectedImprovement"
beta_value = 0.3
# model_type can take values - "Classic", "QHybrid", "YZHybrid", "KHybrid"
model_type = "YZHybrid"

[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"
# This must be a .db file for code to function. It will create a sqllite database
db_name = "db_cost.db"

[job.BayesianOptimization.system]
E = 1024
Expand Down
5 changes: 3 additions & 2 deletions endure/lsm/solver/qlsm_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def nominal_objective(
q: float,
w: float,
) -> float:
h, t, q = x
design = LSMDesign(h=h, T=t, Q=q, policy=Policy.QFixed)
h, t, q_val = x
design = LSMDesign(h=h, T=t, Q=q_val, policy=Policy.QFixed)
cost = self.cf.calc_cost(design, system, z0, z1, q, w)

return cost
Expand Down Expand Up @@ -80,6 +80,7 @@ def get_nominal_design(
"method": "SLSQP",
"bounds": get_bounds(
config=self.config,
policy=Policy.QFixed,
system=system,
robust=False,
),
Expand Down
23 changes: 16 additions & 7 deletions endure/util/db_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ def initialize_database(db_path='cost_log.db'):
non_empty_reads REAL,
range_queries REAL,
writes REAL,
max_bits_per_element REAL,
physical_entries_per_page INT,
range_selectivity REAL,
entries_per_page INT,
total_elements INT,
read_write_asymmetry REAL
read_write_asymmetry REAL,
iterations INT,
sample_size INT,
acquisition_function TEXT
);''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS design_costs (
Expand All @@ -27,19 +29,25 @@ def initialize_database(db_path='cost_log.db'):
bits_per_element REAL,
size_ratio INTEGER,
policy INTEGER,
Q INTEGER,
Y INTEGER,
Z INTEGER,
cost REAL,
FOREIGN KEY (run_id) REFERENCES runs(run_id)
);''')
connector.commit()
return connector


def log_new_run(connector, system, workload):
def log_new_run(connector, system, workload, iterations, sample, acqf):
cursor = connector.cursor()
cursor.execute('INSERT INTO runs (empty_reads, non_empty_reads, range_queries, writes, '
'max_bits_per_element, physical_entries_per_page, range_selectivity, '
'entries_per_page, total_elements, read_write_asymmetry) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
(workload.z0, workload.z1, workload.q, workload.w, system.H, system.E, system.s, system.B, system.N, system.phi))
'entries_per_page, total_elements, read_write_asymmetry, iterations, sample_size, '
'acquisition_function) '
'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
(workload.z0, workload.z1, workload.q, workload.w, system.H, system.E, system.s, system.B,
system.N, system.phi, iterations, sample, acqf))
connector.commit()
return cursor.lastrowid

Expand All @@ -48,8 +56,9 @@ def log_design_cost(connector, run_id, design, cost):
cursor = connector.cursor()

policy_value = design.policy.value if hasattr(design.policy, 'value') else design.policy
cursor.execute('INSERT INTO design_costs (run_id, bits_per_element, size_ratio, policy, cost) '
'VALUES (?, ?, ?, ?, ?)',(run_id, design.h, design.T, policy_value, cost))
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_value, design.Q, design.Y,
design.Z, cost))
connector.commit()


Expand Down
Loading

0 comments on commit e3c7c94

Please sign in to comment.