Skip to content

Commit b5f88f8

Browse files
committed
Add committment of the first best multi-objective to device as final action of the optimization.
1 parent d5a525b commit b5f88f8

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

‎optimize.py‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
def run_trial(frequency_MHz, coreVoltage_mV, trial_number):
8383
try:
8484
console.rule(
85-
f"[bold green]Trial {trial_number}: freq={frequency_MHz:.0f}MHz, Vcore={coreVoltage_mV:.0f}mV[/bold green]"
85+
f"[bold green]Trial {trial_number}: freq={frequency_MHz:.0f} MHz, Vcore={coreVoltage_mV:.0f} mV[/bold green]"
8686
)
8787

8888
headers = {"Content-Type": "application/json"}
@@ -228,7 +228,7 @@ def entrypoint():
228228
study.set_user_attr("limit_temp_degC", limit_temp_degC)
229229
study.set_user_attr("limit_vrTemp_degC", limit_vrTemp_degC)
230230

231-
study.optimize(run_study, n_trials=n_trials)
231+
# study.optimize(run_study, n_trials=n_trials)
232232

233233
console.rule("[bold green]Optimization Complete[/bold green]")
234234
console.print("Best trials per objective from multi-objective optimization:")
@@ -245,6 +245,51 @@ def entrypoint():
245245
table.add_row("Objectives: hashRate (TH/s), efficiency (J/TH)", f"{trial.values}")
246246
console.print(table)
247247

248+
try:
249+
if study.best_trials:
250+
console.rule("[bold green]Committing the Best Multi-Objective Result 1/2 Parameters to Device[/bold green]")
251+
headers = {"Content-Type": "application/json"}
252+
253+
best_trial_frequency = study.best_trials[0].params.get("frequency", min_frequency_MHz)
254+
best_trial_coreVoltage_mV = study.best_trials[0].params.get("coreVoltage", min_coreVoltage_mV)
255+
payload = {"frequency": int(best_trial_frequency), "coreVoltage": int(best_trial_coreVoltage_mV)}
256+
257+
response = requests.patch(SETTINGS_URL, headers=headers, data=json.dumps(payload), timeout=10)
258+
response.raise_for_status()
259+
time.sleep(1)
260+
261+
console.print(
262+
f"Setting the parameters from best multi-objective result 1/2: freq={best_trial_frequency:.0f} MHz, Vcore={best_trial_coreVoltage_mV:.0f} mV"
263+
)
264+
265+
console.print("[cyan]→ Restarting device...[/cyan]")
266+
restart_response = requests.post(RESET_URL, timeout=10)
267+
restart_response.raise_for_status()
268+
269+
console.print("[yellow]⏳ Waiting 30 seconds for system restart...[/yellow]")
270+
time.sleep(30)
271+
272+
stats_response = requests.get(STATS_URL, timeout=10)
273+
stats = stats_response.json()
274+
275+
actual_frequency_MHz = stats.get("frequency", 0)
276+
actual_coreVoltage_mV = stats.get("coreVoltage", 0)
277+
278+
try:
279+
np.testing.assert_allclose(actual_frequency_MHz, best_trial_frequency, rtol=3 * 1e-3)
280+
np.testing.assert_allclose(actual_coreVoltage_mV, best_trial_coreVoltage_mV, rtol=3 * 1e-3)
281+
except AssertionError:
282+
console.print_exception()
283+
console.print("[bold red]Real parameter not set within tolerance of 1%[/bold red]")
284+
console.print()
285+
raise Exception("Real parameter not set within tolerance of 1%")
286+
287+
console.print("[bold green]Parameters from best multi-objective result 1/2 are now set.[/bold green]")
288+
289+
except Exception as e:
290+
console.print(f"[bold red]Exception:[/bold red] {e}")
291+
return
292+
248293

249294
if __name__ == "__main__":
250295
entrypoint()

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=78.1.0"]
33

44
[project]
55
name = "espminer-optim"
6-
version = "0.0.5"
6+
version = "0.0.6"
77
description = "Add your description here"
88
readme = "README.md"
99
requires-python = ">=3.12"

‎uv.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)