Skip to content

Commit

Permalink
breeder - correct archive db query templating
Browse files Browse the repository at this point in the history
Let's not use sqlalchemy to generate the archive db interacting sql
queries because that has led to complications. bindparams was not
working as expect for String/Text type.
  • Loading branch information
cherusk committed Nov 19, 2023
1 parent 6385a72 commit e8f07a0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
9 changes: 2 additions & 7 deletions breeder/linux_network_stack/effectuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,9 @@ def run_push_optimization(ti=None):
metric_data = dict(metric=metric_value)
msg = asyncio.run(send_msg_via_nats(subject=f'recon_{identifier}', data_dict=metric_data))

breeder_table_name = config.get("name")

breeder_table_name = f"from_dag_name" # TBD local dag id based name

query = text("INSERT INTO :table_name VALUES (:setting_id, :setting_full, :setting_result )")
query = query.bindparams(bindparam("table_name", breeder_table_name, type_=String),
bindparam("setting_id", setting_id, type_=String),
bindparam("setting_full", settings_full, type_=String),
bindparam("setting_result", metric_data, type_=String))
query = f"INSERT INTO {breeder_table_name} VALUES ({setting_id}, {setting_full}, {setting_result});"

archive_db_engine.execute(query)

Expand Down
11 changes: 4 additions & 7 deletions breeder/linux_network_stack/objective.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


def objective(trial, identifier, archive_db_url):
def objective(trial, identifier, archive_db_url, breeder_name):

###--- definition coroutines ---###
### We have to keep to coroutines in the objective function,
Expand Down Expand Up @@ -31,13 +31,10 @@ def objective(trial, identifier, archive_db_url):
settings = '\n'.join(settings)

is_setting_explored = False
setting_id = hashlib.sha256(str.encode(settings_full)).hexdigest()[0:6]
setting_id = hashlib.sha256(str.encode(settings)).hexdigest()[0:6]

breeder_table_name = f"from_breeder_name" # TBD global knowledge db table nam
query = text("SELECT * FROM :table_name WHERE :table_name.setting_id == :setting_id")

query = query.bindparams(bindparam("table_name", breeder_table_name, type_=String),
bindparam("setting_id", setting_id, type_=String))
breeder_table_name = f"{breeder_name}"
query = f"SELECT * FROM {breeder_table_name} WHERE {breeder_table_name}.setting_id = '{setting_id}';"

archive_db_data = archive_db_engine.execute(query).fetchall()

Expand Down
2 changes: 1 addition & 1 deletion breeder/linux_network_stack/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def run_optimization():
# Create a study using Dask-compatible storage
storage = DaskStorage(InMemoryStorage())
study = optuna.create_study(directions=__directions, storage=storage)
objective_wrapped = lambda trial: objective(trial,identifier, archive_db_url)
objective_wrapped = lambda trial: objective(trial,identifier, archive_db_url, config.get('name'))
# Optimize in parallel on your Dask cluster
futures = [
client.submit(study.optimize, objective_wrapped, n_trials=10, pure=False)
Expand Down

0 comments on commit e8f07a0

Please sign in to comment.